[PATCH 5.14 067/151] driver core: Reject pointless SYNC_STATE_ONLY device links

From
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date
2021-10-18 13:58:47
Also in
lkml
Reply to
Greg Kroah-Hartman, 2021-10-18
From: Saravana Kannan <redacted>

commit f729a592adb6760013c3e48622a5bf256b992452 upstream.

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")
Cc: stable <redacted>
Reported-by: Ulf Hansson <redacted>
Reviewed-by: Rafael J. Wysocki <redacted>
Reviewed-by: Ulf Hansson <redacted>
Signed-off-by: Saravana Kannan <redacted>
Link: https://lore.kernel.org/r/20210929190549.860541-1-saravanak@google.com (local)
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/base/core.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -675,7 +675,8 @@ struct device_link *device_link_add(stru
 {
 	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) ||

Thread (167 messages) 167 messages, 10 authors, last reply 2021-10-19
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help