]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
vdpa: Use helper for safer setting of driver_override
authorKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Tue, 19 Apr 2022 11:34:31 +0000 (13:34 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 22 Apr 2022 15:13:54 +0000 (17:13 +0200)
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>
drivers/vdpa/vdpa.c
include/linux/vdpa.h

index 2b75c00b10054d2242b6b7b51c7bc07bc461dd8e..33d1ad60cba70aaaeca75c9bda44ded394e2b204 100644 (file)
@@ -77,32 +77,11 @@ static ssize_t driver_override_store(struct device *dev,
                                     const char *buf, size_t count)
 {
        struct vdpa_device *vdev = dev_to_vdpa(dev);
-       const char *driver_override, *old;
-       char *cp;
+       int ret;
 
-       /* We need to keep extra room for a newline */
-       if (count >= (PAGE_SIZE - 1))
-               return -EINVAL;
-
-       driver_override = kstrndup(buf, count, GFP_KERNEL);
-       if (!driver_override)
-               return -ENOMEM;
-
-       cp = strchr(driver_override, '\n');
-       if (cp)
-               *cp = '\0';
-
-       device_lock(dev);
-       old = vdev->driver_override;
-       if (strlen(driver_override)) {
-               vdev->driver_override = driver_override;
-       } else {
-               kfree(driver_override);
-               vdev->driver_override = NULL;
-       }
-       device_unlock(dev);
-
-       kfree(old);
+       ret = driver_set_override(dev, &vdev->driver_override, buf, count);
+       if (ret)
+               return ret;
 
        return count;
 }
index 8943a209202ea4844de46c5cc96d11a694bf7e40..c0a5083632ab514a39c0d9ff8ad248f137622b80 100644 (file)
@@ -64,7 +64,9 @@ struct vdpa_mgmt_dev;
  * struct vdpa_device - representation of a vDPA device
  * @dev: underlying device
  * @dma_dev: the actual device that is performing DMA
- * @driver_override: driver name to force a match
+ * @driver_override: driver name to force a match; do not set directly,
+ *                   because core frees it; use driver_set_override() to
+ *                   set or clear it.
  * @config: the configuration ops for this device.
  * @cf_mutex: Protects get and set access to configuration layout.
  * @index: device index