提交 5688f212 编写于 作者: K Krzysztof Kozlowski 提交者: Greg Kroah-Hartman

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: NKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20220419113435.246203-4-krzysztof.kozlowski@linaro.orgSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 6e679550
...@@ -166,31 +166,14 @@ static ssize_t driver_override_store(struct device *dev, ...@@ -166,31 +166,14 @@ static ssize_t driver_override_store(struct device *dev,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
char *driver_override, *old = mc_dev->driver_override; int ret;
char *cp;
if (WARN_ON(dev->bus != &fsl_mc_bus_type)) if (WARN_ON(dev->bus != &fsl_mc_bus_type))
return -EINVAL; return -EINVAL;
if (count >= (PAGE_SIZE - 1)) ret = driver_set_override(dev, &mc_dev->driver_override, buf, count);
return -EINVAL; if (ret)
return ret;
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);
return count; return count;
} }
......
...@@ -170,7 +170,9 @@ struct fsl_mc_obj_desc { ...@@ -170,7 +170,9 @@ struct fsl_mc_obj_desc {
* @regions: pointer to array of MMIO region entries * @regions: pointer to array of MMIO region entries
* @irqs: pointer to array of pointers to interrupts allocated to this device * @irqs: pointer to array of pointers to interrupts allocated to this device
* @resource: generic resource associated with this MC object device, if any. * @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 * Generic device object for MC object devices that are "attached" to a
* MC bus. * MC bus.
...@@ -204,7 +206,7 @@ struct fsl_mc_device { ...@@ -204,7 +206,7 @@ struct fsl_mc_device {
struct fsl_mc_device_irq **irqs; struct fsl_mc_device_irq **irqs;
struct fsl_mc_resource *resource; struct fsl_mc_resource *resource;
struct device_link *consumer_link; struct device_link *consumer_link;
char *driver_override; const char *driver_override;
}; };
#define to_fsl_mc_device(_dev) \ #define to_fsl_mc_device(_dev) \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册