Skip to contentSkip to conversation

driver core: Reject pointless SYNC_STATE_ONLY device links

PATCH In review Saravana Kannan 3 participants 3 messages Sep 29, 2021 – Sep 30, 2021 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH v2 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")

---
v1 -> v2:
- Moved the check higher up in the function.

 drivers/base/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/base/core.c +2 -1
index 15986cc2fe5e..249da496581a 100644
@@ -687,7 +687,8 @@ struct device_link *device_link_add(struct device *consumer,
 {
 	struct device_link *link;
 
-	if (!consumer || !supplier || flags & ~DL_ADD_VALID_FLAGS ||
+	if (!consumer || !supplier || consumer == supplier ||
+	    flags & ~DL_ADD_VALID_FLAGS ||
 	    (flags & DL_FLAG_STATELESS && flags & DL_MANAGED_LINK_FLAGS) ||
 	    (flags & DL_FLAG_SYNC_STATE_ONLY &&
 	     (flags & ~DL_FLAG_INFERRED) != DL_FLAG_SYNC_STATE_ONLY) ||
Signature · 1 line
2.33.0.685.g46640cef36-goog
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 11 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.

Quoted 3 lines
Fixes 05ef983e0d65 ("driver core: Add device link support for SYNC_STATE_ONLY flag")
Quoted 24 lines

---
v1 -> v2:
- Moved the check higher up in the function.

 drivers/base/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/base/core.c +2 -2
index 15986cc2fe5e..249da496581a 100644
@@ -687,7 +687,8 @@ struct device_link *device_link_add(struct device *consumer,
 {
        struct device_link *link;
 
-       if (!consumer || !supplier || flags & ~DL_ADD_VALID_FLAGS ||
+       if (!consumer || !supplier || consumer == supplier ||
+           flags & ~DL_ADD_VALID_FLAGS ||
            (flags & DL_FLAG_STATELESS && flags & DL_MANAGED_LINK_FLAGS) ||
            (flags & DL_FLAG_SYNC_STATE_ONLY &&
             (flags & ~DL_FLAG_INFERRED) != DL_FLAG_SYNC_STATE_ONLY) ||
--

2.33.0.685.g46640cef36-goog

Reviewed-by on v2 1/1
#2 lore raw
In reply to Saravana Kannan
Quoted 11 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.

Quoted 3 lines
Fixes 05ef983e0d65 ("driver core: Add device link support for SYNC_STATE_ONLY flag")

Kind regards
Uffe

Quoted 24 lines

---
v1 -> v2:
- Moved the check higher up in the function.

 drivers/base/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/base/core.c +2 -2
index 15986cc2fe5e..249da496581a 100644
@@ -687,7 +687,8 @@ struct device_link *device_link_add(struct device *consumer,
 {
        struct device_link *link;
 
-       if (!consumer || !supplier || flags & ~DL_ADD_VALID_FLAGS ||
+       if (!consumer || !supplier || consumer == supplier ||
+           flags & ~DL_ADD_VALID_FLAGS ||
            (flags & DL_FLAG_STATELESS && flags & DL_MANAGED_LINK_FLAGS) ||
            (flags & DL_FLAG_SYNC_STATE_ONLY &&
             (flags & ~DL_FLAG_INFERRED) != DL_FLAG_SYNC_STATE_ONLY) ||
--

2.33.0.685.g46640cef36-goog