Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6ac874f4 authored by Saravana Kannan's avatar Saravana Kannan Committed by Mike Tipton
Browse files

FROMGIT: 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: fc5a251d0fd7ca90 (driver core: Add sync_state driver/bus callback)
Signed-off-by: default avatarSaravana Kannan <saravanak@google.com>
Cc: stable <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20200221080510.197337-2-saravanak@google.com


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 21eb93f432b1a785df193df1a56a59e9eb3a985f
https: //git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git driver-core-linus)
Bug: 150980623
Change-Id: I9bebc164f00d7797501f40080c12a04dbe3095b1
Git-repo: https://android.googlesource.com/kernel/common


Git-commit: a27e0934
Signed-off-by: default avatarMike Tipton <mdtipton@codeaurora.org>
parent 816c0efa
Loading
Loading
Loading
Loading
+17 −6
Original line number Original line Diff line number Diff line
@@ -745,17 +745,22 @@ static void __device_links_queue_sync_state(struct device *dev,
/**
/**
 * device_links_flush_sync_list - Call sync_state() on a list of devices
 * device_links_flush_sync_list - Call sync_state() on a list of devices
 * @list: List of devices to call sync_state() on
 * @list: List of devices to call sync_state() on
 * @dont_lock_dev: Device for which lock is already held by the caller
 *
 *
 * Calls sync_state() on all the devices that have been queued for it. This
 * Calls sync_state() on all the devices that have been queued for it. This
 * function is used in conjunction with __device_links_queue_sync_state().
 * function is used in conjunction with __device_links_queue_sync_state(). The
 * @dont_lock_dev parameter is useful when this function is called from a
 * context where a device lock is already held.
 */
 */
static void device_links_flush_sync_list(struct list_head *list)
static void device_links_flush_sync_list(struct list_head *list,
					 struct device *dont_lock_dev)
{
{
	struct device *dev, *tmp;
	struct device *dev, *tmp;


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


		if (dev != dont_lock_dev)
			device_lock(dev);
			device_lock(dev);


		if (dev->bus->sync_state)
		if (dev->bus->sync_state)
@@ -763,6 +768,7 @@ static void device_links_flush_sync_list(struct list_head *list)
		else if (dev->driver && dev->driver->sync_state)
		else if (dev->driver && dev->driver->sync_state)
			dev->driver->sync_state(dev);
			dev->driver->sync_state(dev);


		if (dev != dont_lock_dev)
			device_unlock(dev);
			device_unlock(dev);


		put_device(dev);
		put_device(dev);
@@ -801,7 +807,7 @@ void device_links_supplier_sync_state_resume(void)
out:
out:
	device_links_write_unlock();
	device_links_write_unlock();


	device_links_flush_sync_list(&sync_list);
	device_links_flush_sync_list(&sync_list, NULL);
}
}


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


	if (defer_sync_state_count)
		__device_links_supplier_defer_sync(dev);
	else
		__device_links_queue_sync_state(dev, &sync_list);

	list_for_each_entry(link, &dev->links.suppliers, c_node) {
	list_for_each_entry(link, &dev->links.suppliers, c_node) {
		if (!(link->flags & DL_FLAG_MANAGED))
		if (!(link->flags & DL_FLAG_MANAGED))
			continue;
			continue;
@@ -883,7 +894,7 @@ void device_links_driver_bound(struct device *dev)


	device_links_write_unlock();
	device_links_write_unlock();


	device_links_flush_sync_list(&sync_list);
	device_links_flush_sync_list(&sync_list, dev);
}
}


static void device_link_drop_managed(struct device_link *link)
static void device_link_drop_managed(struct device_link *link)