summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmit Sunil Dhamne <amitsd@google.com>2024-08-22 15:37:15 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-08-25 13:45:56 +0200
commitfc88bb11617978fb3fcfcc697fd5c9d2dae9c4a3 (patch)
tree94341ec9cd6edaa455d0108311ee162f7a20e99c
parent4333dbd9798d470d0c81608bb44bb7c8fd7f7948 (diff)
downloadlwn-fc88bb11617978fb3fcfcc697fd5c9d2dae9c4a3.tar.gz
lwn-fc88bb11617978fb3fcfcc697fd5c9d2dae9c4a3.zip
usb: roles: add lockdep class key to struct usb_role_switch
There can be multiple role switch devices running on a platform. Given that lockdep is not capable of differentiating between locks of different instances, false positive warnings for circular locking are reported. To prevent this, register unique lockdep key for each of the individual instances. Signed-off-by: Amit Sunil Dhamne <amitsd@google.com> Reviewed-by: Badhri Jagan Sridharan <badhri@google.com> Link: https://lore.kernel.org/r/20240822223717.253433-1-amitsd@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/usb/roles/class.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
index d7aa913ceb8a..7aca1ef7f44c 100644
--- a/drivers/usb/roles/class.c
+++ b/drivers/usb/roles/class.c
@@ -11,6 +11,7 @@
#include <linux/usb/role.h>
#include <linux/property.h>
#include <linux/device.h>
+#include <linux/lockdep.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/slab.h>
@@ -33,6 +34,8 @@ struct usb_role_switch {
usb_role_switch_set_t set;
usb_role_switch_get_t get;
bool allow_userspace_control;
+
+ struct lock_class_key key;
};
#define to_role_switch(d) container_of(d, struct usb_role_switch, dev)
@@ -396,6 +399,9 @@ usb_role_switch_register(struct device *parent,
sw->registered = true;
+ lockdep_register_key(&sw->key);
+ lockdep_set_class(&sw->lock, &sw->key);
+
/* TODO: Symlinks for the host port and the device controller. */
return sw;
@@ -412,6 +418,9 @@ void usb_role_switch_unregister(struct usb_role_switch *sw)
{
if (IS_ERR_OR_NULL(sw))
return;
+
+ lockdep_unregister_key(&sw->key);
+
sw->registered = false;
if (dev_fwnode(&sw->dev))
component_del(&sw->dev, &connector_ops);