Skip to contentSkip to conversation

driver core: Reject pointless SYNC_STATE_ONLY device links

PATCH Superseded Saravana Kannan 2 participants 3 messages Sep 29, 2021 Driver core

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 driver core: Reject pointless SYNC_STATE_ONLY device links

SYNC_STATE_ONLY device links intentionally allow cycles because cyclic sync_state() dependencies are valid and necessary.

However a SYNC_STATE_ONLY device link where the consumer and the supplier are the same device is pointless because the device link would be deleted as soon as the device probes (because it's also the consumer) and won't affect when the sync_state() callback is called. It's a waste of CPU cycles and memory to create this device link. So reject any attempts to create such a device link.

Fixes 05ef983e0d65 ("driver core: Add device link support for SYNC_STATE_ONLY flag")
---
 drivers/base/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/core.c +1 -1
index 15986cc2fe5e..eed27933ac4d 100644
@@ -716,7 +716,7 @@ struct device_link *device_link_add(struct device *consumer,
 	 * SYNC_STATE_ONLY link, we don't check for reverse dependencies
 	 * because it only affects sync_state() callbacks.
 	 */
-	if (!device_pm_initialized(supplier)
+	if (!device_pm_initialized(supplier) || consumer == supplier
 	    || (!(flags & DL_FLAG_SYNC_STATE_ONLY) &&
 		  device_is_dependent(consumer, supplier))) {
 		link = NULL;
Signature · 1 line
2.33.0.685.g46640cef36-goog
#1 lore raw
Quoted 23 lines · Saravana Kannan

SYNC_STATE_ONLY device links intentionally allow cycles because cyclic sync_state() dependencies are valid and necessary.

However a SYNC_STATE_ONLY device link where the consumer and the supplier are the same device is pointless because the device link would be deleted as soon as the device probes (because it's also the consumer) and won't affect when the sync_state() callback is called. It's a waste of CPU cycles and memory to create this device link. So reject any attempts to create such a device link.

Fixes 05ef983e0d65 ("driver core: Add device link support for SYNC_STATE_ONLY flag")
---
 drivers/base/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/core.c +0 -0
index 15986cc2fe5e..eed27933ac4d 100644

drivers/base/core.c struct device_link *device_link_add(struct device *consumer, · line 719

Quoted 5 lines
drivers/base/core.c +1 -1
@@ -716,7 +716,7 @@ struct device_link *device_link_add(struct device *consumer,
         * SYNC_STATE_ONLY link, we don't check for reverse dependencies
         * because it only affects sync_state() callbacks.
         */
-       if (!device_pm_initialized(supplier)
+       if (!device_pm_initialized(supplier) || consumer == supplier

Why do we need to get all the way down to here in order to return NULL in the consumer == supplier case?

IMO this should be checked at the beginning along with !consumer and !supplier.

Quoted 6 lines
drivers/base/core.c +0 -1
            || (!(flags & DL_FLAG_SYNC_STATE_ONLY) &&
                  device_is_dependent(consumer, supplier))) {
                link = NULL;
--

2.33.0.685.g46640cef36-goog

#2 lore raw
Quoted 20 lines · Rafael J. Wysocki
Quoted 18 lines · Saravana Kannan

SYNC_STATE_ONLY device links intentionally allow cycles because cyclic sync_state() dependencies are valid and necessary.

However a SYNC_STATE_ONLY device link where the consumer and the supplier are the same device is pointless because the device link would be deleted as soon as the device probes (because it's also the consumer) and won't affect when the sync_state() callback is called. It's a waste of CPU cycles and memory to create this device link. So reject any attempts to create such a device link.

Fixes 05ef983e0d65 ("driver core: Add device link support for SYNC_STATE_ONLY flag")
---
 drivers/base/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

drivers/base/core.c struct device_link *device_link_add(struct device *consumer, · line 719

Quoted 10 lines
drivers/base/core.c +1 -1
index 15986cc2fe5e..eed27933ac4d 100644
@@ -716,7 +716,7 @@ struct device_link *device_link_add(struct device *consumer,
         * SYNC_STATE_ONLY link, we don't check for reverse dependencies
         * because it only affects sync_state() callbacks.
         */
-       if (!device_pm_initialized(supplier)
+       if (!device_pm_initialized(supplier) || consumer == supplier

Why do we need to get all the way down to here in order to return NULL in the consumer == supplier case?

This is where it used to be checked before the "Fixes commit" so I added it back here. But sure, I can move it up there.

-Saravana

Quoted 9 lines

IMO this should be checked at the beginning along with !consumer and !supplier.

Quoted 6 lines
drivers/base/core.c +0 -1
            || (!(flags & DL_FLAG_SYNC_STATE_ONLY) &&
                  device_is_dependent(consumer, supplier))) {
                link = NULL;
--

2.33.0.685.g46640cef36-goog