Skip to content

Commit fc88bb1

Browse files
amitsd2gregkh
authored andcommitted
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 <[email protected]> Reviewed-by: Badhri Jagan Sridharan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 4333dbd commit fc88bb1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/usb/roles/class.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/usb/role.h>
1212
#include <linux/property.h>
1313
#include <linux/device.h>
14+
#include <linux/lockdep.h>
1415
#include <linux/module.h>
1516
#include <linux/mutex.h>
1617
#include <linux/slab.h>
@@ -33,6 +34,8 @@ struct usb_role_switch {
3334
usb_role_switch_set_t set;
3435
usb_role_switch_get_t get;
3536
bool allow_userspace_control;
37+
38+
struct lock_class_key key;
3639
};
3740

3841
#define to_role_switch(d) container_of(d, struct usb_role_switch, dev)
@@ -396,6 +399,9 @@ usb_role_switch_register(struct device *parent,
396399

397400
sw->registered = true;
398401

402+
lockdep_register_key(&sw->key);
403+
lockdep_set_class(&sw->lock, &sw->key);
404+
399405
/* TODO: Symlinks for the host port and the device controller. */
400406

401407
return sw;
@@ -412,6 +418,9 @@ void usb_role_switch_unregister(struct usb_role_switch *sw)
412418
{
413419
if (IS_ERR_OR_NULL(sw))
414420
return;
421+
422+
lockdep_unregister_key(&sw->key);
423+
415424
sw->registered = false;
416425
if (dev_fwnode(&sw->dev))
417426
component_del(&sw->dev, &connector_ops);

0 commit comments

Comments
 (0)