fsl-mc: Use driver_set_override() instead of open-coding
authorKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Tue, 19 Apr 2022 11:34:26 +0000 (13:34 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 22 Apr 2022 15:13:53 +0000 (17:13 +0200)
Use a helper to set driver_override to reduce the amount of duplicated
code.  Make the driver_override field const char, because it is not
modified by the core and it matches other subsystems.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20220419113435.246203-4-krzysztof.kozlowski@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/bus/fsl-mc/fsl-mc-bus.c
include/linux/fsl/mc.h

index 8fd4a356a86ec0b1cff2b830c6c1bf78924682f0..ba01c7f4de925a6f001413c4be52aa5ed2ccc4b3 100644 (file)
@@ -166,31 +166,14 @@ static ssize_t driver_override_store(struct device *dev,
                                     const char *buf, size_t count)
 {
        struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
-       char *driver_override, *old = mc_dev->driver_override;
-       char *cp;
+       int ret;
 
        if (WARN_ON(dev->bus != &fsl_mc_bus_type))
                return -EINVAL;
 
-       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';
-
-       if (strlen(driver_override)) {
-               mc_dev->driver_override = driver_override;
-       } else {
-               kfree(driver_override);
-               mc_dev->driver_override = NULL;
-       }
-
-       kfree(old);
+       ret = driver_set_override(dev, &mc_dev->driver_override, buf, count);
+       if (ret)
+               return ret;
 
        return count;
 }
index 7b6c42bfb660fc200a37586577428917d1fda070..7a87ab9eba99fd76e126a9e18ff1ff3c1ba49bbf 100644 (file)
@@ -170,7 +170,9 @@ struct fsl_mc_obj_desc {
  * @regions: pointer to array of MMIO region entries
  * @irqs: pointer to array of pointers to interrupts allocated to this device
  * @resource: generic resource associated with this MC object device, if any.
- * @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.
  *
  * Generic device object for MC object devices that are "attached" to a
  * MC bus.
@@ -204,7 +206,7 @@ struct fsl_mc_device {
        struct fsl_mc_device_irq **irqs;
        struct fsl_mc_resource *resource;
        struct device_link *consumer_link;
-       char   *driver_override;
+       const char *driver_override;
 };
 
 #define to_fsl_mc_device(_dev) \