Skip to content

Commit 72a91f1

Browse files
a3fgregkh
authored andcommitted
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>
1 parent d46f3e3 commit 72a91f1

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

‎drivers/base/dd.c‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ static char async_probe_drv_names[ASYNC_DRV_NAMES_MAX_LEN];
6868
*/
6969
static bool defer_all_probes;
7070

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+
7177
/*
7278
* deferred_probe_work_func() - Retry probing devices in the active list.
7379
*/
@@ -96,8 +102,7 @@ static void deferred_probe_work_func(struct work_struct *work)
96102

97103
get_device(dev);
98104

99-
kfree(dev->p->deferred_probe_reason);
100-
dev->p->deferred_probe_reason = NULL;
105+
__device_set_deferred_probe_reason(dev, NULL);
101106

102107
/*
103108
* Drop the mutex while probing each device; the probe path may
@@ -142,8 +147,7 @@ void driver_deferred_probe_del(struct device *dev)
142147
if (!list_empty(&dev->p->deferred_probe)) {
143148
dev_dbg(dev, "Removed from deferred list\n");
144149
list_del_init(&dev->p->deferred_probe);
145-
kfree(dev->p->deferred_probe_reason);
146-
dev->p->deferred_probe_reason = NULL;
150+
__device_set_deferred_probe_reason(dev, NULL);
147151
}
148152
mutex_unlock(&deferred_probe_mutex);
149153
}
@@ -222,11 +226,12 @@ void device_unblock_probing(void)
222226
void device_set_deferred_probe_reason(const struct device *dev, struct va_format *vaf)
223227
{
224228
const char *drv = dev_driver_string(dev);
229+
char *reason;
225230

226231
mutex_lock(&deferred_probe_mutex);
227232

228-
kfree(dev->p->deferred_probe_reason);
229-
dev->p->deferred_probe_reason = kasprintf(GFP_KERNEL, "%s: %pV", drv, vaf);
233+
reason = kasprintf(GFP_KERNEL, "%s: %pV", drv, vaf);
234+
__device_set_deferred_probe_reason(dev, reason);
230235

231236
mutex_unlock(&deferred_probe_mutex);
232237
}

0 commit comments

Comments
 (0)