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

driver core: add helper for deferred probe reason setting

We now have three places within the same file doing the same operation
of freeing this pointer and setting it anew. A helper makes this
arguably easier to read, so add one.

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: Andrzej Hajda <a.hajda@samsung.com>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.kernel.org/r/20210323153714.25120-2-a.fatoum@pengutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Ahmad Fatoum and committed by
Greg Kroah-Hartman
72a91f19 d46f3e3e

+11 -6
+11 -6
drivers/base/dd.c
··· 68 68 */ 69 69 static bool defer_all_probes; 70 70 71 + static void __device_set_deferred_probe_reason(const struct device *dev, char *reason) 72 + { 73 + kfree(dev->p->deferred_probe_reason); 74 + dev->p->deferred_probe_reason = reason; 75 + } 76 + 71 77 /* 72 78 * deferred_probe_work_func() - Retry probing devices in the active list. 73 79 */ ··· 102 96 103 97 get_device(dev); 104 98 105 - kfree(dev->p->deferred_probe_reason); 106 - dev->p->deferred_probe_reason = NULL; 99 + __device_set_deferred_probe_reason(dev, NULL); 107 100 108 101 /* 109 102 * Drop the mutex while probing each device; the probe path may ··· 147 142 if (!list_empty(&dev->p->deferred_probe)) { 148 143 dev_dbg(dev, "Removed from deferred list\n"); 149 144 list_del_init(&dev->p->deferred_probe); 150 - kfree(dev->p->deferred_probe_reason); 151 - dev->p->deferred_probe_reason = NULL; 145 + __device_set_deferred_probe_reason(dev, NULL); 152 146 } 153 147 mutex_unlock(&deferred_probe_mutex); 154 148 } ··· 226 222 void device_set_deferred_probe_reason(const struct device *dev, struct va_format *vaf) 227 223 { 228 224 const char *drv = dev_driver_string(dev); 225 + char *reason; 229 226 230 227 mutex_lock(&deferred_probe_mutex); 231 228 232 - kfree(dev->p->deferred_probe_reason); 233 - dev->p->deferred_probe_reason = kasprintf(GFP_KERNEL, "%s: %pV", drv, vaf); 229 + reason = kasprintf(GFP_KERNEL, "%s: %pV", drv, vaf); 230 + __device_set_deferred_probe_reason(dev, reason); 234 231 235 232 mutex_unlock(&deferred_probe_mutex); 236 233 }