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 */ 19 20 #include <linux/device.h> 21 #include <linux/module.h> 22 #include <linux/kthread.h> 23 #include <linux/wait.h> 24 25 #include "base.h" 26 #include "power/power.h" ··· 166 atomic_read(&probe_count)); 167 if (atomic_read(&probe_count)) 168 return -EBUSY; 169 return 0; 170 } 171
··· 18 */ 19 20 #include <linux/device.h> 21 + #include <linux/delay.h> 22 #include <linux/module.h> 23 #include <linux/kthread.h> 24 #include <linux/wait.h> 25 + #include <linux/async.h> 26 27 #include "base.h" 28 #include "power/power.h" ··· 164 atomic_read(&probe_count)); 165 if (atomic_read(&probe_count)) 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(); 182 return 0; 183 } 184
+2
include/linux/device.h
··· 147 extern struct device_driver *driver_find(const char *name, 148 struct bus_type *bus); 149 extern int driver_probe_done(void); 150 151 /* sysfs interface for exporting driver attributes */ 152
··· 147 extern struct device_driver *driver_find(const char *name, 148 struct bus_type *bus); 149 extern int driver_probe_done(void); 150 + extern int wait_for_device_probe(void); 151 + 152 153 /* sysfs interface for exporting driver attributes */ 154
+9 -4
init/do_mounts.c
··· 370 ssleep(root_delay); 371 } 372 373 - /* wait for the known devices to complete their probing */ 374 - while (driver_probe_done() != 0) 375 - msleep(100); 376 - async_synchronize_full(); 377 378 md_run_setup(); 379 ··· 403 while (driver_probe_done() != 0 || 404 (ROOT_DEV = name_to_dev_t(saved_root_name)) == 0) 405 msleep(100); 406 } 407 408 is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR;
··· 370 ssleep(root_delay); 371 } 372 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(); 381 382 md_run_setup(); 383 ··· 399 while (driver_probe_done() != 0 || 400 (ROOT_DEV = name_to_dev_t(saved_root_name)) == 0) 401 msleep(100); 402 + async_synchronize_full(); 403 } 404 405 is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR;
+3 -2
init/do_mounts_md.c
··· 281 */ 282 printk(KERN_INFO "md: Waiting for all devices to be available before autodetect\n"); 283 printk(KERN_INFO "md: If you don't use raid, use raid=noautodetect\n"); 284 - while (driver_probe_done() < 0) 285 - msleep(100); 286 fd = sys_open("/dev/md0", 0, 0); 287 if (fd >= 0) { 288 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
··· 281 */ 282 printk(KERN_INFO "md: Waiting for all devices to be available before autodetect\n"); 283 printk(KERN_INFO "md: If you don't use raid, use raid=noautodetect\n"); 284 + 285 + wait_for_device_probe(); 286 + 287 fd = sys_open("/dev/md0", 0, 0); 288 if (fd >= 0) { 289 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);