driver core: sync state fixups
cover driver core: sync state fixups
Patch 1/3 fixes a bug where sync_state() might not be called when it should be. Patches 2/3 and 3/3 are just minor fix ups that I'm grouping together. Not much to say here.
-Saravana
Saravana Kannan (3):
driver core: Call sync_state() even if supplier has no consumers driver core: Add dev_has_sync_state()
driver core: Skip unnecessary work when device doesn't have
sync_state()
drivers/base/core.c | 27 ++++++++++++++++++++------- include/linux/device.h | 11 +++++++++++ 2 files changed, 31 insertions(+), 7 deletions(-)
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
PATCH 1/3 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.
--- drivers/base/core.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-)
drivers/base/core.c +17 -6
@@ -745,25 +745,31 @@ static void __device_links_queue_sync_state(struct device *dev,/** * device_links_flush_sync_list - Call sync_state() on a list of devices * @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 -* 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;list_for_each_entry_safe (dev, tmp, list, links.defer_sync) {list_del_init (&dev->links.defer_sync); -device_lock (dev); +if (dev != dont_lock_dev) +device_lock (dev);if (dev->bus->sync_state) dev->bus->sync_state (dev);else if (dev->driver && dev->driver->sync_state) dev->driver->sync_state (dev); -device_unlock (dev); +if (dev != dont_lock_dev) +device_unlock (dev);put_device (dev); }
@@ -801,7 +807,7 @@ void device_links_supplier_sync_state_resume(void) out: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 )
@@ -865,6 +871,11 @@ void device_links_driver_bound(struct device *dev)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) {if (!(link->flags &DL_FLAG_MANAGED ))continue ;
@@ -883,7 +894,7 @@ void device_links_driver_bound(struct device *dev)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)
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
PATCH 2/3 driver core: Add dev_has_sync_state()
In reply to Saravana KannanAdd an API to check if a device has sync_state support in its driver or bus.
--- include/linux/device.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
include/linux/device.h +11 -0
@@ -798,6 +798,17 @@ static inline struct device_node *dev_of_node(struct device *dev)return dev->of_node; } +static inline bool dev_has_sync_state (struct device *dev) +{ +if (!dev) +return false; +if (dev->driver && dev->driver->sync_state) +return true; +if (dev->bus && dev->bus->sync_state) +return true; +return false; +} +/* * High level routines for use by the bus drivers */
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
PATCH 3/3 driver core: Skip unnecessary work when device doesn't have sync_state()
In reply to Saravana KannanA bunch of busy work is done for devices that don't have sync_state() support. Stop doing the busy work.
--- drivers/base/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/base/core.c +3 -1
@@ -718,6 +718,8 @@ static void __device_links_queue_sync_state(struct device *dev, {struct device_link *link; +if (!dev_has_sync_state (dev)) +return ;if (dev->state_synced)return ;
@@ -819,7 +821,7 @@ late_initcall(sync_state_resume_initcall);static void __device_links_supplier_defer_sync (struct device *sup) { -if (list_empty (&sup->links.defer_sync)) +if (list_empty (&sup->links.defer_sync) &&dev_has_sync_state (dev))list_add_tail (&sup->links.defer_sync, &deferred_sync); }
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
kbuild test robot
build botRe: [PATCH v1 3/3] driver core: Skip unnecessary work when device doesn't have sync_state()
Thank you for the patch! Yet something to improve:
Hi Saravana,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on driver-core/driver-core-testing]
[also build test ERROR on linus/master v5.6-rc2 next-20200221] [cannot apply to linux/master]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Saravana-Kannan/driver-core-sync-state-fixups/20200222-124626 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git 99c73ce158a44a1a11cb146062bc32df0c1d95db config: i386-tinyconfig (attached as .config) compiler: gcc-7 (Debian 7.5.0-5) 7.5.0 reproduce: # save the attached .config to linux build tree make ARCH=i386
If you fix the issue, kindly add following tag
All errors (new ones prefixed by >>):
drivers/base/core.c: In function '__device_links_supplier_defer_sync':
>> drivers/base/core.c:824:63: error: 'dev' undeclared (first use in this function); did you mean 'cdev'?
if (list_empty(&sup->links.defer_sync) && dev_has_sync_state(dev))
^~~
cdev drivers/base/core.c:824:63: note: each undeclared identifier is reported only once for each function it appears in
vim +824 drivers/base/core.c
821
822 static void __device_links_supplier_defer_sync(struct device *sup)
823 {
> 824 if (list_empty(&sup->links.defer_sync) && dev_has_sync_state(dev))
825 list_add_tail(&sup->links.defer_sync, &deferred_sync);
826 }
827
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org