Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Krzysztof Kozlowski and committed by
Greg Kroah-Hartman
5688f212 6e679550

+8 -23
+4 -21
drivers/bus/fsl-mc/fsl-mc-bus.c
··· 166 166 const char *buf, size_t count) 167 167 { 168 168 struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); 169 - char *driver_override, *old = mc_dev->driver_override; 170 - char *cp; 169 + int ret; 171 170 172 171 if (WARN_ON(dev->bus != &fsl_mc_bus_type)) 173 172 return -EINVAL; 174 173 175 - if (count >= (PAGE_SIZE - 1)) 176 - return -EINVAL; 177 - 178 - driver_override = kstrndup(buf, count, GFP_KERNEL); 179 - if (!driver_override) 180 - return -ENOMEM; 181 - 182 - cp = strchr(driver_override, '\n'); 183 - if (cp) 184 - *cp = '\0'; 185 - 186 - if (strlen(driver_override)) { 187 - mc_dev->driver_override = driver_override; 188 - } else { 189 - kfree(driver_override); 190 - mc_dev->driver_override = NULL; 191 - } 192 - 193 - kfree(old); 174 + ret = driver_set_override(dev, &mc_dev->driver_override, buf, count); 175 + if (ret) 176 + return ret; 194 177 195 178 return count; 196 179 }
+4 -2
include/linux/fsl/mc.h
··· 170 170 * @regions: pointer to array of MMIO region entries 171 171 * @irqs: pointer to array of pointers to interrupts allocated to this device 172 172 * @resource: generic resource associated with this MC object device, if any. 173 - * @driver_override: driver name to force a match 173 + * @driver_override: driver name to force a match; do not set directly, 174 + * because core frees it; use driver_set_override() to 175 + * set or clear it. 174 176 * 175 177 * Generic device object for MC object devices that are "attached" to a 176 178 * MC bus. ··· 206 204 struct fsl_mc_device_irq **irqs; 207 205 struct fsl_mc_resource *resource; 208 206 struct device_link *consumer_link; 209 - char *driver_override; 207 + const char *driver_override; 210 208 }; 211 209 212 210 #define to_fsl_mc_device(_dev) \