Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Amit Sunil Dhamne and committed by
Greg Kroah-Hartman
fc88bb11 4333dbd9

+9
+9
drivers/usb/roles/class.c
··· 11 11 #include <linux/usb/role.h> 12 12 #include <linux/property.h> 13 13 #include <linux/device.h> 14 + #include <linux/lockdep.h> 14 15 #include <linux/module.h> 15 16 #include <linux/mutex.h> 16 17 #include <linux/slab.h> ··· 34 33 usb_role_switch_set_t set; 35 34 usb_role_switch_get_t get; 36 35 bool allow_userspace_control; 36 + 37 + struct lock_class_key key; 37 38 }; 38 39 39 40 #define to_role_switch(d) container_of(d, struct usb_role_switch, dev) ··· 399 396 400 397 sw->registered = true; 401 398 399 + lockdep_register_key(&sw->key); 400 + lockdep_set_class(&sw->lock, &sw->key); 401 + 402 402 /* TODO: Symlinks for the host port and the device controller. */ 403 403 404 404 return sw; ··· 418 412 { 419 413 if (IS_ERR_OR_NULL(sw)) 420 414 return; 415 + 416 + lockdep_unregister_key(&sw->key); 417 + 421 418 sw->registered = false; 422 419 if (dev_fwnode(&sw->dev)) 423 420 component_del(&sw->dev, &connector_ops);