Consolidate driver_probe_done() loops into one place

there's a few places that currently loop over driver_probe_done(), and
I'm about to add another one. This patch abstracts it into a helper
to reduce duplication.

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Len Brown <lenb@kernel.org>
Acked-by: Greg KH <gregkh@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by Arjan van de Ven and committed by Linus Torvalds 216773a7 d2f8d7ee

+31 -6
+17
drivers/base/dd.c
··· 18 18 */ 19 19 20 20 #include <linux/device.h> 21 + #include <linux/delay.h> 21 22 #include <linux/module.h> 22 23 #include <linux/kthread.h> 23 24 #include <linux/wait.h> 25 + #include <linux/async.h> 24 26 25 27 #include "base.h" 26 28 #include "power/power.h" ··· 166 164 atomic_read(&probe_count)); 167 165 if (atomic_read(&probe_count)) 168 166 return -EBUSY; 167 + return 0; 168 + } 169 + 170 + /** 171 + * wait_for_device_probe 172 + * Wait for device probing to be completed. 173 + * 174 + * Note: this function polls at 100 msec intervals. 175 + */ 176 + int wait_for_device_probe(void) 177 + { 178 + /* wait for the known devices to complete their probing */ 179 + while (driver_probe_done() != 0) 180 + msleep(100); 181 + async_synchronize_full(); 169 182 return 0; 170 183 } 171 184
+2
include/linux/device.h
··· 147 147 extern struct device_driver *driver_find(const char *name, 148 148 struct bus_type *bus); 149 149 extern int driver_probe_done(void); 150 + extern int wait_for_device_probe(void); 151 + 150 152 151 153 /* sysfs interface for exporting driver attributes */ 152 154
+9 -4
init/do_mounts.c
··· 370 370 ssleep(root_delay); 371 371 } 372 372 373 - /* wait for the known devices to complete their probing */ 374 - while (driver_probe_done() != 0) 375 - msleep(100); 376 - async_synchronize_full(); 373 + /* 374 + * wait for the known devices to complete their probing 375 + * 376 + * Note: this is a potential source of long boot delays. 377 + * For example, it is not atypical to wait 5 seconds here 378 + * for the touchpad of a laptop to initialize. 379 + */ 380 + wait_for_device_probe(); 377 381 378 382 md_run_setup(); 379 383 ··· 403 399 while (driver_probe_done() != 0 || 404 400 (ROOT_DEV = name_to_dev_t(saved_root_name)) == 0) 405 401 msleep(100); 402 + async_synchronize_full(); 406 403 } 407 404 408 405 is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR;
+3 -2
init/do_mounts_md.c
··· 281 281 */ 282 282 printk(KERN_INFO "md: Waiting for all devices to be available before autodetect\n"); 283 283 printk(KERN_INFO "md: If you don't use raid, use raid=noautodetect\n"); 284 - while (driver_probe_done() < 0) 285 - msleep(100); 284 + 285 + wait_for_device_probe(); 286 + 286 287 fd = sys_open("/dev/md0", 0, 0); 287 288 if (fd >= 0) { 288 289 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);