driver core: Allow only unprobed consumers for SYNC_STATE_ONLY device links
authorSaravana Kannan <saravanak@google.com>
Sat, 21 Nov 2020 02:02:24 +0000 (18:02 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 9 Dec 2020 18:10:21 +0000 (19:10 +0100)
SYNC_STATE_ONLY device links only affect the behavior of sync_state()
callbacks. Specifically, they prevent sync_state() only callbacks from
being called on a device if one or more of its consumers haven't probed.

So, creating a SYNC_STATE_ONLY device link from an already probed
consumer is useless. So, don't allow creating such device links.

Signed-off-by: Saravana Kannan <saravanak@google.com>
Link: https://lore.kernel.org/r/20201121020232.908850-10-saravanak@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/core.c

index 972d42dedfc84b0a4feb5e5441c9afd5856e5413..edde79fc3d3381b18054a468dd2a67c33b2eb2e2 100644 (file)
@@ -649,6 +649,17 @@ struct device_link *device_link_add(struct device *consumer,
                goto out;
        }
 
+       /*
+        * SYNC_STATE_ONLY links are useless once a consumer device has probed.
+        * So, only create it if the consumer hasn't probed yet.
+        */
+       if (flags & DL_FLAG_SYNC_STATE_ONLY &&
+           consumer->links.status != DL_DEV_NO_DRIVER &&
+           consumer->links.status != DL_DEV_PROBING) {
+               link = NULL;
+               goto out;
+       }
+
        /*
         * DL_FLAG_AUTOREMOVE_SUPPLIER indicates that the link will be needed
         * longer than for DL_FLAG_AUTOREMOVE_CONSUMER and setting them both