Skip to contentSkip to conversation

usb: roles: add lockdep class key to struct usb_role_switch

PATCH In review Amit Sunil Dhamne 2 participants 2 messages Aug 22, 2024 – Aug 23, 2024 USB

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 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.

---
v1->v2
- Avoid usage of ifdefs.
v2->v3
- Removed redundancies.
- Completed peer review and added reviewer signature.

---
 drivers/usb/roles/class.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/usb/roles/class.c +9 -0
index d7aa913ceb8a..7aca1ef7f44c 100644
@@ -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);

base-commit: ca7df2c7bb5f83fe46aa9ce998b7352c6b28f3a1

Signature · 1 line
2.46.0.184.g6999bdac58-goog
Reviewed-by on v3 1/1
#1 lore raw
Quoted 8 lines · Amit Sunil Dhamne

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.

Quoted 55 lines

---
v1->v2
- Avoid usage of ifdefs.
v2->v3
- Removed redundancies.
- Completed peer review and added reviewer signature.

---
 drivers/usb/roles/class.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/usb/roles/class.c +9 -0
index d7aa913ceb8a..7aca1ef7f44c 100644
@@ -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);

base-commit: ca7df2c7bb5f83fe46aa9ce998b7352c6b28f3a1

Signature · 1 line
2.46.0.184.g6999bdac58-goog
Signature · 1 line
heikki