Skip to content

Commit 240bf4e

Browse files
krzkgregkh
authored andcommitted
vdpa: Use helper for safer setting of driver_override
Use a helper to set driver_override to the reduce amount of duplicated code. Acked-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Link: https://lore.kernel.org/r/20220419113435.246203-9-krzysztof.kozlowski@linaro.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 19368f0 commit 240bf4e

File tree

2 files changed

+7
-26
lines changed

2 files changed

+7
-26
lines changed

drivers/vdpa/vdpa.c

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -77,32 +77,11 @@ static ssize_t driver_override_store(struct device *dev,
7777
const char *buf, size_t count)
7878
{
7979
struct vdpa_device *vdev = dev_to_vdpa(dev);
80-
const char *driver_override, *old;
81-
char *cp;
80+
int ret;
8281

83-
/* We need to keep extra room for a newline */
84-
if (count >= (PAGE_SIZE - 1))
85-
return -EINVAL;
86-
87-
driver_override = kstrndup(buf, count, GFP_KERNEL);
88-
if (!driver_override)
89-
return -ENOMEM;
90-
91-
cp = strchr(driver_override, '\n');
92-
if (cp)
93-
*cp = '\0';
94-
95-
device_lock(dev);
96-
old = vdev->driver_override;
97-
if (strlen(driver_override)) {
98-
vdev->driver_override = driver_override;
99-
} else {
100-
kfree(driver_override);
101-
vdev->driver_override = NULL;
102-
}
103-
device_unlock(dev);
104-
105-
kfree(old);
82+
ret = driver_set_override(dev, &vdev->driver_override, buf, count);
83+
if (ret)
84+
return ret;
10685

10786
return count;
10887
}

include/linux/vdpa.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ struct vdpa_mgmt_dev;
6464
* struct vdpa_device - representation of a vDPA device
6565
* @dev: underlying device
6666
* @dma_dev: the actual device that is performing DMA
67-
* @driver_override: driver name to force a match
67+
* @driver_override: driver name to force a match; do not set directly,
68+
* because core frees it; use driver_set_override() to
69+
* set or clear it.
6870
* @config: the configuration ops for this device.
6971
* @cf_mutex: Protects get and set access to configuration layout.
7072
* @index: device index

0 commit comments

Comments
 (0)