@@ -94,19 +94,11 @@ int device_bind_driver(struct device *dev)
9494 return ret ;
9595}
9696
97- struct stupid_thread_structure {
98- struct device_driver * drv ;
99- struct device * dev ;
100- };
101-
10297static atomic_t probe_count = ATOMIC_INIT (0 );
10398static DECLARE_WAIT_QUEUE_HEAD (probe_waitqueue );
10499
105- static int really_probe (void * void_data )
100+ static int really_probe (struct device * dev , struct device_driver * drv )
106101{
107- struct stupid_thread_structure * data = void_data ;
108- struct device_driver * drv = data -> drv ;
109- struct device * dev = data -> dev ;
110102 int ret = 0 ;
111103
112104 atomic_inc (& probe_count );
@@ -154,7 +146,6 @@ static int really_probe(void *void_data)
154146 */
155147 ret = 0 ;
156148done :
157- kfree (data );
158149 atomic_dec (& probe_count );
159150 wake_up (& probe_waitqueue );
160151 return ret ;
@@ -186,16 +177,14 @@ int driver_probe_done(void)
186177 * format of the ID structures, nor what is to be considered a match and
187178 * what is not.
188179 *
189- * This function returns 1 if a match is found, an error if one occurs
190- * (that is not -ENODEV or -ENXIO) , and 0 otherwise.
180+ * This function returns 1 if a match is found, -ENODEV if the device is
181+ * not registered , and 0 otherwise.
191182 *
192183 * This function must be called with @dev->sem held. When called for a
193184 * USB interface, @dev->parent->sem must be held as well.
194185 */
195186int driver_probe_device (struct device_driver * drv , struct device * dev )
196187{
197- struct stupid_thread_structure * data ;
198- struct task_struct * probe_task ;
199188 int ret = 0 ;
200189
201190 if (!device_is_registered (dev ))
@@ -206,19 +195,7 @@ int driver_probe_device(struct device_driver * drv, struct device * dev)
206195 pr_debug ("%s: Matched Device %s with Driver %s\n" ,
207196 drv -> bus -> name , dev -> bus_id , drv -> name );
208197
209- data = kmalloc (sizeof (* data ), GFP_KERNEL );
210- if (!data )
211- return - ENOMEM ;
212- data -> drv = drv ;
213- data -> dev = dev ;
214-
215- if (drv -> multithread_probe ) {
216- probe_task = kthread_run (really_probe , data ,
217- "probe-%s" , dev -> bus_id );
218- if (IS_ERR (probe_task ))
219- ret = really_probe (data );
220- } else
221- ret = really_probe (data );
198+ ret = really_probe (dev , drv );
222199
223200done :
224201 return ret ;
@@ -230,30 +207,53 @@ static int __device_attach(struct device_driver * drv, void * data)
230207 return driver_probe_device (drv , dev );
231208}
232209
210+ static int device_probe_drivers (void * data )
211+ {
212+ struct device * dev = data ;
213+ int ret = 0 ;
214+
215+ if (dev -> bus ) {
216+ down (& dev -> sem );
217+ ret = bus_for_each_drv (dev -> bus , NULL , dev , __device_attach );
218+ up (& dev -> sem );
219+ }
220+ return ret ;
221+ }
222+
233223/**
234224 * device_attach - try to attach device to a driver.
235225 * @dev: device.
236226 *
237227 * Walk the list of drivers that the bus has and call
238228 * driver_probe_device() for each pair. If a compatible
239- * pair is found, break out and return.
229+ * pair is found, break out and return. If the bus specifies
230+ * multithreaded probing, walking the list of drivers is done
231+ * on a probing thread.
240232 *
241233 * Returns 1 if the device was bound to a driver;
242- * 0 if no matching device was found; error code otherwise.
234+ * 0 if no matching device was found or multithreaded probing is done;
235+ * error code otherwise.
243236 *
244237 * When called for a USB interface, @dev->parent->sem must be held.
245238 */
246239int device_attach (struct device * dev )
247240{
248241 int ret = 0 ;
242+ struct task_struct * probe_task = ERR_PTR (- ENOMEM );
249243
250244 down (& dev -> sem );
251245 if (dev -> driver ) {
252246 ret = device_bind_driver (dev );
253247 if (ret == 0 )
254248 ret = 1 ;
255- } else
256- ret = bus_for_each_drv (dev -> bus , NULL , dev , __device_attach );
249+ } else {
250+ if (dev -> bus -> multithread_probe )
251+ probe_task = kthread_run (device_probe_drivers , dev ,
252+ "probe-%s" , dev -> bus_id );
253+ if (IS_ERR (probe_task ))
254+ ret = bus_for_each_drv (dev -> bus , NULL , dev ,
255+ __device_attach );
256+ }
257257 up (& dev -> sem );
258258 return ret ;
259259}
0 commit comments