fsl-mc: Use driver_set_override() instead of open-coding

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>
This commit is contained in:
Krzysztof Kozlowski 2022-04-19 13:34:26 +02:00 committed by Greg Kroah-Hartman
parent 6e67955087
commit 5688f212e9
2 changed files with 8 additions and 23 deletions

View 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;
}

View 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) \