GNU Linux-libre 4.4.284-gnu1
[releases.git] / drivers / base / dd.c
1 /*
2  * drivers/base/dd.c - The core device/driver interactions.
3  *
4  * This file contains the (sometimes tricky) code that controls the
5  * interactions between devices and drivers, which primarily includes
6  * driver binding and unbinding.
7  *
8  * All of this code used to exist in drivers/base/bus.c, but was
9  * relocated to here in the name of compartmentalization (since it wasn't
10  * strictly code just for the 'struct bus_type'.
11  *
12  * Copyright (c) 2002-5 Patrick Mochel
13  * Copyright (c) 2002-3 Open Source Development Labs
14  * Copyright (c) 2007-2009 Greg Kroah-Hartman <gregkh@suse.de>
15  * Copyright (c) 2007-2009 Novell Inc.
16  *
17  * This file is released under the GPLv2
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 #include <linux/pm_runtime.h>
27 #include <linux/pinctrl/devinfo.h>
28
29 #include "base.h"
30 #include "power/power.h"
31
32 /*
33  * Deferred Probe infrastructure.
34  *
35  * Sometimes driver probe order matters, but the kernel doesn't always have
36  * dependency information which means some drivers will get probed before a
37  * resource it depends on is available.  For example, an SDHCI driver may
38  * first need a GPIO line from an i2c GPIO controller before it can be
39  * initialized.  If a required resource is not available yet, a driver can
40  * request probing to be deferred by returning -EPROBE_DEFER from its probe hook
41  *
42  * Deferred probe maintains two lists of devices, a pending list and an active
43  * list.  A driver returning -EPROBE_DEFER causes the device to be added to the
44  * pending list.  A successful driver probe will trigger moving all devices
45  * from the pending to the active list so that the workqueue will eventually
46  * retry them.
47  *
48  * The deferred_probe_mutex must be held any time the deferred_probe_*_list
49  * of the (struct device*)->p->deferred_probe pointers are manipulated
50  */
51 static DEFINE_MUTEX(deferred_probe_mutex);
52 static LIST_HEAD(deferred_probe_pending_list);
53 static LIST_HEAD(deferred_probe_active_list);
54 static struct workqueue_struct *deferred_wq;
55 static atomic_t deferred_trigger_count = ATOMIC_INIT(0);
56
57 /*
58  * deferred_probe_work_func() - Retry probing devices in the active list.
59  */
60 static void deferred_probe_work_func(struct work_struct *work)
61 {
62         struct device *dev;
63         struct device_private *private;
64         /*
65          * This block processes every device in the deferred 'active' list.
66          * Each device is removed from the active list and passed to
67          * bus_probe_device() to re-attempt the probe.  The loop continues
68          * until every device in the active list is removed and retried.
69          *
70          * Note: Once the device is removed from the list and the mutex is
71          * released, it is possible for the device get freed by another thread
72          * and cause a illegal pointer dereference.  This code uses
73          * get/put_device() to ensure the device structure cannot disappear
74          * from under our feet.
75          */
76         mutex_lock(&deferred_probe_mutex);
77         while (!list_empty(&deferred_probe_active_list)) {
78                 private = list_first_entry(&deferred_probe_active_list,
79                                         typeof(*dev->p), deferred_probe);
80                 dev = private->device;
81                 list_del_init(&private->deferred_probe);
82
83                 get_device(dev);
84
85                 /*
86                  * Drop the mutex while probing each device; the probe path may
87                  * manipulate the deferred list
88                  */
89                 mutex_unlock(&deferred_probe_mutex);
90
91                 /*
92                  * Force the device to the end of the dpm_list since
93                  * the PM code assumes that the order we add things to
94                  * the list is a good order for suspend but deferred
95                  * probe makes that very unsafe.
96                  */
97                 device_pm_lock();
98                 device_pm_move_last(dev);
99                 device_pm_unlock();
100
101                 dev_dbg(dev, "Retrying from deferred list\n");
102                 bus_probe_device(dev);
103
104                 mutex_lock(&deferred_probe_mutex);
105
106                 put_device(dev);
107         }
108         mutex_unlock(&deferred_probe_mutex);
109 }
110 static DECLARE_WORK(deferred_probe_work, deferred_probe_work_func);
111
112 static void driver_deferred_probe_add(struct device *dev)
113 {
114         mutex_lock(&deferred_probe_mutex);
115         if (list_empty(&dev->p->deferred_probe)) {
116                 dev_dbg(dev, "Added to deferred list\n");
117                 list_add_tail(&dev->p->deferred_probe, &deferred_probe_pending_list);
118         }
119         mutex_unlock(&deferred_probe_mutex);
120 }
121
122 void driver_deferred_probe_del(struct device *dev)
123 {
124         mutex_lock(&deferred_probe_mutex);
125         if (!list_empty(&dev->p->deferred_probe)) {
126                 dev_dbg(dev, "Removed from deferred list\n");
127                 list_del_init(&dev->p->deferred_probe);
128         }
129         mutex_unlock(&deferred_probe_mutex);
130 }
131
132 static bool driver_deferred_probe_enable = false;
133 /**
134  * driver_deferred_probe_trigger() - Kick off re-probing deferred devices
135  *
136  * This functions moves all devices from the pending list to the active
137  * list and schedules the deferred probe workqueue to process them.  It
138  * should be called anytime a driver is successfully bound to a device.
139  *
140  * Note, there is a race condition in multi-threaded probe. In the case where
141  * more than one device is probing at the same time, it is possible for one
142  * probe to complete successfully while another is about to defer. If the second
143  * depends on the first, then it will get put on the pending list after the
144  * trigger event has already occurred and will be stuck there.
145  *
146  * The atomic 'deferred_trigger_count' is used to determine if a successful
147  * trigger has occurred in the midst of probing a driver. If the trigger count
148  * changes in the midst of a probe, then deferred processing should be triggered
149  * again.
150  */
151 static void driver_deferred_probe_trigger(void)
152 {
153         if (!driver_deferred_probe_enable)
154                 return;
155
156         /*
157          * A successful probe means that all the devices in the pending list
158          * should be triggered to be reprobed.  Move all the deferred devices
159          * into the active list so they can be retried by the workqueue
160          */
161         mutex_lock(&deferred_probe_mutex);
162         atomic_inc(&deferred_trigger_count);
163         list_splice_tail_init(&deferred_probe_pending_list,
164                               &deferred_probe_active_list);
165         mutex_unlock(&deferred_probe_mutex);
166
167         /*
168          * Kick the re-probe thread.  It may already be scheduled, but it is
169          * safe to kick it again.
170          */
171         queue_work(deferred_wq, &deferred_probe_work);
172 }
173
174 /**
175  * deferred_probe_initcall() - Enable probing of deferred devices
176  *
177  * We don't want to get in the way when the bulk of drivers are getting probed.
178  * Instead, this initcall makes sure that deferred probing is delayed until
179  * late_initcall time.
180  */
181 static int deferred_probe_initcall(void)
182 {
183         deferred_wq = create_singlethread_workqueue("deferwq");
184         if (WARN_ON(!deferred_wq))
185                 return -ENOMEM;
186
187         driver_deferred_probe_enable = true;
188         driver_deferred_probe_trigger();
189         /* Sort as many dependencies as possible before exiting initcalls */
190         flush_workqueue(deferred_wq);
191         return 0;
192 }
193 late_initcall(deferred_probe_initcall);
194
195 static void driver_bound(struct device *dev)
196 {
197         if (klist_node_attached(&dev->p->knode_driver)) {
198                 printk(KERN_WARNING "%s: device %s already bound\n",
199                         __func__, kobject_name(&dev->kobj));
200                 return;
201         }
202
203         pr_debug("driver: '%s': %s: bound to device '%s'\n", dev->driver->name,
204                  __func__, dev_name(dev));
205
206         klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices);
207
208         /*
209          * Make sure the device is no longer in one of the deferred lists and
210          * kick off retrying all pending devices
211          */
212         driver_deferred_probe_del(dev);
213         driver_deferred_probe_trigger();
214
215         if (dev->bus)
216                 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
217                                              BUS_NOTIFY_BOUND_DRIVER, dev);
218 }
219
220 static int driver_sysfs_add(struct device *dev)
221 {
222         int ret;
223
224         if (dev->bus)
225                 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
226                                              BUS_NOTIFY_BIND_DRIVER, dev);
227
228         ret = sysfs_create_link(&dev->driver->p->kobj, &dev->kobj,
229                           kobject_name(&dev->kobj));
230         if (ret == 0) {
231                 ret = sysfs_create_link(&dev->kobj, &dev->driver->p->kobj,
232                                         "driver");
233                 if (ret)
234                         sysfs_remove_link(&dev->driver->p->kobj,
235                                         kobject_name(&dev->kobj));
236         }
237         return ret;
238 }
239
240 static void driver_sysfs_remove(struct device *dev)
241 {
242         struct device_driver *drv = dev->driver;
243
244         if (drv) {
245                 sysfs_remove_link(&drv->p->kobj, kobject_name(&dev->kobj));
246                 sysfs_remove_link(&dev->kobj, "driver");
247         }
248 }
249
250 /**
251  * device_bind_driver - bind a driver to one device.
252  * @dev: device.
253  *
254  * Allow manual attachment of a driver to a device.
255  * Caller must have already set @dev->driver.
256  *
257  * Note that this does not modify the bus reference count
258  * nor take the bus's rwsem. Please verify those are accounted
259  * for before calling this. (It is ok to call with no other effort
260  * from a driver's probe() method.)
261  *
262  * This function must be called with the device lock held.
263  */
264 int device_bind_driver(struct device *dev)
265 {
266         int ret;
267
268         ret = driver_sysfs_add(dev);
269         if (!ret)
270                 driver_bound(dev);
271         return ret;
272 }
273 EXPORT_SYMBOL_GPL(device_bind_driver);
274
275 static atomic_t probe_count = ATOMIC_INIT(0);
276 static DECLARE_WAIT_QUEUE_HEAD(probe_waitqueue);
277
278 static int really_probe(struct device *dev, struct device_driver *drv)
279 {
280         int ret = 0;
281         int local_trigger_count = atomic_read(&deferred_trigger_count);
282
283         atomic_inc(&probe_count);
284         pr_debug("bus: '%s': %s: probing driver %s with device %s\n",
285                  drv->bus->name, __func__, drv->name, dev_name(dev));
286         if (!list_empty(&dev->devres_head)) {
287                 dev_crit(dev, "Resources present before probing\n");
288                 ret = -EBUSY;
289                 goto done;
290         }
291
292         dev->driver = drv;
293
294         /* If using pinctrl, bind pins now before probing */
295         ret = pinctrl_bind_pins(dev);
296         if (ret)
297                 goto probe_failed;
298
299         if (driver_sysfs_add(dev)) {
300                 printk(KERN_ERR "%s: driver_sysfs_add(%s) failed\n",
301                         __func__, dev_name(dev));
302                 goto probe_failed;
303         }
304
305         if (dev->pm_domain && dev->pm_domain->activate) {
306                 ret = dev->pm_domain->activate(dev);
307                 if (ret)
308                         goto probe_failed;
309         }
310
311         if (dev->bus->probe) {
312                 ret = dev->bus->probe(dev);
313                 if (ret)
314                         goto probe_failed;
315         } else if (drv->probe) {
316                 ret = drv->probe(dev);
317                 if (ret)
318                         goto probe_failed;
319         }
320
321         pinctrl_init_done(dev);
322
323         if (dev->pm_domain && dev->pm_domain->sync)
324                 dev->pm_domain->sync(dev);
325
326         driver_bound(dev);
327         ret = 1;
328         pr_debug("bus: '%s': %s: bound device %s to driver %s\n",
329                  drv->bus->name, __func__, dev_name(dev), drv->name);
330         goto done;
331
332 probe_failed:
333         devres_release_all(dev);
334         driver_sysfs_remove(dev);
335         dev->driver = NULL;
336         dev_set_drvdata(dev, NULL);
337         if (dev->pm_domain && dev->pm_domain->dismiss)
338                 dev->pm_domain->dismiss(dev);
339
340         switch (ret) {
341         case -EPROBE_DEFER:
342                 /* Driver requested deferred probing */
343                 dev_dbg(dev, "Driver %s requests probe deferral\n", drv->name);
344                 driver_deferred_probe_add(dev);
345                 /* Did a trigger occur while probing? Need to re-trigger if yes */
346                 if (local_trigger_count != atomic_read(&deferred_trigger_count))
347                         driver_deferred_probe_trigger();
348                 break;
349         case -ENODEV:
350         case -ENXIO:
351                 pr_debug("%s: probe of %s rejects match %d\n",
352                          drv->name, dev_name(dev), ret);
353                 break;
354         default:
355                 /* driver matched but the probe failed */
356                 printk(KERN_WARNING
357                        "%s: probe of %s failed with error %d\n",
358                        drv->name, dev_name(dev), ret);
359         }
360         /*
361          * Ignore errors returned by ->probe so that the next driver can try
362          * its luck.
363          */
364         ret = 0;
365 done:
366         atomic_dec(&probe_count);
367         wake_up_all(&probe_waitqueue);
368         return ret;
369 }
370
371 /**
372  * driver_probe_done
373  * Determine if the probe sequence is finished or not.
374  *
375  * Should somehow figure out how to use a semaphore, not an atomic variable...
376  */
377 int driver_probe_done(void)
378 {
379         pr_debug("%s: probe_count = %d\n", __func__,
380                  atomic_read(&probe_count));
381         if (atomic_read(&probe_count))
382                 return -EBUSY;
383         return 0;
384 }
385
386 /**
387  * wait_for_device_probe
388  * Wait for device probing to be completed.
389  */
390 void wait_for_device_probe(void)
391 {
392         /* wait for the known devices to complete their probing */
393         wait_event(probe_waitqueue, atomic_read(&probe_count) == 0);
394         async_synchronize_full();
395 }
396 EXPORT_SYMBOL_GPL(wait_for_device_probe);
397
398 /**
399  * driver_probe_device - attempt to bind device & driver together
400  * @drv: driver to bind a device to
401  * @dev: device to try to bind to the driver
402  *
403  * This function returns -ENODEV if the device is not registered,
404  * 1 if the device is bound successfully and 0 otherwise.
405  *
406  * This function must be called with @dev lock held.  When called for a
407  * USB interface, @dev->parent lock must be held as well.
408  *
409  * If the device has a parent, runtime-resume the parent before driver probing.
410  */
411 int driver_probe_device(struct device_driver *drv, struct device *dev)
412 {
413         int ret = 0;
414
415         if (!device_is_registered(dev))
416                 return -ENODEV;
417
418         pr_debug("bus: '%s': %s: matched device %s with driver %s\n",
419                  drv->bus->name, __func__, dev_name(dev), drv->name);
420
421         if (dev->parent)
422                 pm_runtime_get_sync(dev->parent);
423
424         pm_runtime_barrier(dev);
425         ret = really_probe(dev, drv);
426         pm_request_idle(dev);
427
428         if (dev->parent)
429                 pm_runtime_put(dev->parent);
430
431         return ret;
432 }
433
434 bool driver_allows_async_probing(struct device_driver *drv)
435 {
436         switch (drv->probe_type) {
437         case PROBE_PREFER_ASYNCHRONOUS:
438                 return true;
439
440         case PROBE_FORCE_SYNCHRONOUS:
441                 return false;
442
443         default:
444                 if (module_requested_async_probing(drv->owner))
445                         return true;
446
447                 return false;
448         }
449 }
450
451 struct device_attach_data {
452         struct device *dev;
453
454         /*
455          * Indicates whether we are are considering asynchronous probing or
456          * not. Only initial binding after device or driver registration
457          * (including deferral processing) may be done asynchronously, the
458          * rest is always synchronous, as we expect it is being done by
459          * request from userspace.
460          */
461         bool check_async;
462
463         /*
464          * Indicates if we are binding synchronous or asynchronous drivers.
465          * When asynchronous probing is enabled we'll execute 2 passes
466          * over drivers: first pass doing synchronous probing and second
467          * doing asynchronous probing (if synchronous did not succeed -
468          * most likely because there was no driver requiring synchronous
469          * probing - and we found asynchronous driver during first pass).
470          * The 2 passes are done because we can't shoot asynchronous
471          * probe for given device and driver from bus_for_each_drv() since
472          * driver pointer is not guaranteed to stay valid once
473          * bus_for_each_drv() iterates to the next driver on the bus.
474          */
475         bool want_async;
476
477         /*
478          * We'll set have_async to 'true' if, while scanning for matching
479          * driver, we'll encounter one that requests asynchronous probing.
480          */
481         bool have_async;
482 };
483
484 static int __device_attach_driver(struct device_driver *drv, void *_data)
485 {
486         struct device_attach_data *data = _data;
487         struct device *dev = data->dev;
488         bool async_allowed;
489
490         /*
491          * Check if device has already been claimed. This may
492          * happen with driver loading, device discovery/registration,
493          * and deferred probe processing happens all at once with
494          * multiple threads.
495          */
496         if (dev->driver)
497                 return -EBUSY;
498
499         if (!driver_match_device(drv, dev))
500                 return 0;
501
502         async_allowed = driver_allows_async_probing(drv);
503
504         if (async_allowed)
505                 data->have_async = true;
506
507         if (data->check_async && async_allowed != data->want_async)
508                 return 0;
509
510         return driver_probe_device(drv, dev);
511 }
512
513 static void __device_attach_async_helper(void *_dev, async_cookie_t cookie)
514 {
515         struct device *dev = _dev;
516         struct device_attach_data data = {
517                 .dev            = dev,
518                 .check_async    = true,
519                 .want_async     = true,
520         };
521
522         device_lock(dev);
523
524         if (dev->parent)
525                 pm_runtime_get_sync(dev->parent);
526
527         bus_for_each_drv(dev->bus, NULL, &data, __device_attach_driver);
528         dev_dbg(dev, "async probe completed\n");
529
530         pm_request_idle(dev);
531
532         if (dev->parent)
533                 pm_runtime_put(dev->parent);
534
535         device_unlock(dev);
536
537         put_device(dev);
538 }
539
540 static int __device_attach(struct device *dev, bool allow_async)
541 {
542         int ret = 0;
543
544         device_lock(dev);
545         if (dev->driver) {
546                 if (klist_node_attached(&dev->p->knode_driver)) {
547                         ret = 1;
548                         goto out_unlock;
549                 }
550                 ret = device_bind_driver(dev);
551                 if (ret == 0)
552                         ret = 1;
553                 else {
554                         dev->driver = NULL;
555                         ret = 0;
556                 }
557         } else {
558                 struct device_attach_data data = {
559                         .dev = dev,
560                         .check_async = allow_async,
561                         .want_async = false,
562                 };
563
564                 if (dev->parent)
565                         pm_runtime_get_sync(dev->parent);
566
567                 ret = bus_for_each_drv(dev->bus, NULL, &data,
568                                         __device_attach_driver);
569                 if (!ret && allow_async && data.have_async) {
570                         /*
571                          * If we could not find appropriate driver
572                          * synchronously and we are allowed to do
573                          * async probes and there are drivers that
574                          * want to probe asynchronously, we'll
575                          * try them.
576                          */
577                         dev_dbg(dev, "scheduling asynchronous probe\n");
578                         get_device(dev);
579                         async_schedule(__device_attach_async_helper, dev);
580                 } else {
581                         pm_request_idle(dev);
582                 }
583
584                 if (dev->parent)
585                         pm_runtime_put(dev->parent);
586         }
587 out_unlock:
588         device_unlock(dev);
589         return ret;
590 }
591
592 /**
593  * device_attach - try to attach device to a driver.
594  * @dev: device.
595  *
596  * Walk the list of drivers that the bus has and call
597  * driver_probe_device() for each pair. If a compatible
598  * pair is found, break out and return.
599  *
600  * Returns 1 if the device was bound to a driver;
601  * 0 if no matching driver was found;
602  * -ENODEV if the device is not registered.
603  *
604  * When called for a USB interface, @dev->parent lock must be held.
605  */
606 int device_attach(struct device *dev)
607 {
608         return __device_attach(dev, false);
609 }
610 EXPORT_SYMBOL_GPL(device_attach);
611
612 void device_initial_probe(struct device *dev)
613 {
614         __device_attach(dev, true);
615 }
616
617 static int __driver_attach(struct device *dev, void *data)
618 {
619         struct device_driver *drv = data;
620
621         /*
622          * Lock device and try to bind to it. We drop the error
623          * here and always return 0, because we need to keep trying
624          * to bind to devices and some drivers will return an error
625          * simply if it didn't support the device.
626          *
627          * driver_probe_device() will spit a warning if there
628          * is an error.
629          */
630
631         if (!driver_match_device(drv, dev))
632                 return 0;
633
634         if (dev->parent)        /* Needed for USB */
635                 device_lock(dev->parent);
636         device_lock(dev);
637         if (!dev->driver)
638                 driver_probe_device(drv, dev);
639         device_unlock(dev);
640         if (dev->parent)
641                 device_unlock(dev->parent);
642
643         return 0;
644 }
645
646 /**
647  * driver_attach - try to bind driver to devices.
648  * @drv: driver.
649  *
650  * Walk the list of devices that the bus has on it and try to
651  * match the driver with each one.  If driver_probe_device()
652  * returns 0 and the @dev->driver is set, we've found a
653  * compatible pair.
654  */
655 int driver_attach(struct device_driver *drv)
656 {
657         return bus_for_each_dev(drv->bus, NULL, drv, __driver_attach);
658 }
659 EXPORT_SYMBOL_GPL(driver_attach);
660
661 /*
662  * __device_release_driver() must be called with @dev lock held.
663  * When called for a USB interface, @dev->parent lock must be held as well.
664  */
665 static void __device_release_driver(struct device *dev)
666 {
667         struct device_driver *drv;
668
669         drv = dev->driver;
670         if (drv) {
671                 if (driver_allows_async_probing(drv))
672                         async_synchronize_full();
673
674                 pm_runtime_get_sync(dev);
675
676                 driver_sysfs_remove(dev);
677
678                 if (dev->bus)
679                         blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
680                                                      BUS_NOTIFY_UNBIND_DRIVER,
681                                                      dev);
682
683                 pm_runtime_put_sync(dev);
684
685                 if (dev->bus && dev->bus->remove)
686                         dev->bus->remove(dev);
687                 else if (drv->remove)
688                         drv->remove(dev);
689                 devres_release_all(dev);
690                 dev->driver = NULL;
691                 dev_set_drvdata(dev, NULL);
692                 if (dev->pm_domain && dev->pm_domain->dismiss)
693                         dev->pm_domain->dismiss(dev);
694
695                 klist_remove(&dev->p->knode_driver);
696                 if (dev->bus)
697                         blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
698                                                      BUS_NOTIFY_UNBOUND_DRIVER,
699                                                      dev);
700
701         }
702 }
703
704 /**
705  * device_release_driver - manually detach device from driver.
706  * @dev: device.
707  *
708  * Manually detach device from driver.
709  * When called for a USB interface, @dev->parent lock must be held.
710  */
711 void device_release_driver(struct device *dev)
712 {
713         /*
714          * If anyone calls device_release_driver() recursively from
715          * within their ->remove callback for the same device, they
716          * will deadlock right here.
717          */
718         device_lock(dev);
719         __device_release_driver(dev);
720         device_unlock(dev);
721 }
722 EXPORT_SYMBOL_GPL(device_release_driver);
723
724 /**
725  * driver_detach - detach driver from all devices it controls.
726  * @drv: driver.
727  */
728 void driver_detach(struct device_driver *drv)
729 {
730         struct device_private *dev_prv;
731         struct device *dev;
732
733         for (;;) {
734                 spin_lock(&drv->p->klist_devices.k_lock);
735                 if (list_empty(&drv->p->klist_devices.k_list)) {
736                         spin_unlock(&drv->p->klist_devices.k_lock);
737                         break;
738                 }
739                 dev_prv = list_entry(drv->p->klist_devices.k_list.prev,
740                                      struct device_private,
741                                      knode_driver.n_node);
742                 dev = dev_prv->device;
743                 get_device(dev);
744                 spin_unlock(&drv->p->klist_devices.k_lock);
745
746                 if (dev->parent)        /* Needed for USB */
747                         device_lock(dev->parent);
748                 device_lock(dev);
749                 if (dev->driver == drv)
750                         __device_release_driver(dev);
751                 device_unlock(dev);
752                 if (dev->parent)
753                         device_unlock(dev->parent);
754                 put_device(dev);
755         }
756 }