Skip to content

Commit 21eb93f

Browse files
Saravana Kannangregkh
authored andcommitted
driver core: Call sync_state() even if supplier has no consumers
The initial patch that added sync_state() support didn't handle the case where a supplier has no consumers. This was because when a device is successfully bound with a driver, only its suppliers were checked to see if they are eligible to get a sync_state(). This is not sufficient for devices that have no consumers but still need to do device state clean up. So fix this. Fixes: fc5a251 (driver core: Add sync_state driver/bus callback) Signed-off-by: Saravana Kannan <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ae91c92 commit 21eb93f

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

drivers/base/core.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -745,25 +745,31 @@ static void __device_links_queue_sync_state(struct device *dev,
745745
/**
746746
* device_links_flush_sync_list - Call sync_state() on a list of devices
747747
* @list: List of devices to call sync_state() on
748+
* @dont_lock_dev: Device for which lock is already held by the caller
748749
*
749750
* Calls sync_state() on all the devices that have been queued for it. This
750-
* function is used in conjunction with __device_links_queue_sync_state().
751+
* function is used in conjunction with __device_links_queue_sync_state(). The
752+
* @dont_lock_dev parameter is useful when this function is called from a
753+
* context where a device lock is already held.
751754
*/
752-
static void device_links_flush_sync_list(struct list_head *list)
755+
static void device_links_flush_sync_list(struct list_head *list,
756+
struct device *dont_lock_dev)
753757
{
754758
struct device *dev, *tmp;
755759

756760
list_for_each_entry_safe(dev, tmp, list, links.defer_sync) {
757761
list_del_init(&dev->links.defer_sync);
758762

759-
device_lock(dev);
763+
if (dev != dont_lock_dev)
764+
device_lock(dev);
760765

761766
if (dev->bus->sync_state)
762767
dev->bus->sync_state(dev);
763768
else if (dev->driver && dev->driver->sync_state)
764769
dev->driver->sync_state(dev);
765770

766-
device_unlock(dev);
771+
if (dev != dont_lock_dev)
772+
device_unlock(dev);
767773

768774
put_device(dev);
769775
}
@@ -801,7 +807,7 @@ void device_links_supplier_sync_state_resume(void)
801807
out:
802808
device_links_write_unlock();
803809

804-
device_links_flush_sync_list(&sync_list);
810+
device_links_flush_sync_list(&sync_list, NULL);
805811
}
806812

807813
static int sync_state_resume_initcall(void)
@@ -865,6 +871,11 @@ void device_links_driver_bound(struct device *dev)
865871
driver_deferred_probe_add(link->consumer);
866872
}
867873

874+
if (defer_sync_state_count)
875+
__device_links_supplier_defer_sync(dev);
876+
else
877+
__device_links_queue_sync_state(dev, &sync_list);
878+
868879
list_for_each_entry(link, &dev->links.suppliers, c_node) {
869880
if (!(link->flags & DL_FLAG_MANAGED))
870881
continue;
@@ -883,7 +894,7 @@ void device_links_driver_bound(struct device *dev)
883894

884895
device_links_write_unlock();
885896

886-
device_links_flush_sync_list(&sync_list);
897+
device_links_flush_sync_list(&sync_list, dev);
887898
}
888899

889900
static void device_link_drop_managed(struct device_link *link)

0 commit comments

Comments
 (0)