public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] usb: roles: add lockdep class key to struct usb_role_switch
@ 2024-08-15  4:40 Amit Sunil Dhamne
  2024-08-15  5:06 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Amit Sunil Dhamne @ 2024-08-15  4:40 UTC (permalink / raw)
  To: heikki.krogerus, gregkh
  Cc: badhri, linux-usb, linux-kernel, kyletso, rdbabiera,
	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.

Signed-off-by: Amit Sunil Dhamne <amitsd@google.com>
---
v1->v2
- Avoid usage of ifdefs.
---
 drivers/usb/roles/class.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
index d7aa913ceb8a..9dbe9f6bea83 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,11 @@ usb_role_switch_register(struct device *parent,
 
 	sw->registered = true;
 
+	if (IS_ENABLED(CONFIG_LOCKDEP)) {
+		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 +420,10 @@ void usb_role_switch_unregister(struct usb_role_switch *sw)
 {
 	if (IS_ERR_OR_NULL(sw))
 		return;
+
+	if (IS_ENABLED(CONFIG_LOCKDEP))
+		lockdep_unregister_key(&sw->key);
+
 	sw->registered = false;
 	if (dev_fwnode(&sw->dev))
 		component_del(&sw->dev, &connector_ops);
-- 
2.46.0.76.ge559c4bf1a-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] usb: roles: add lockdep class key to struct usb_role_switch
  2024-08-15  4:40 [PATCH v2] usb: roles: add lockdep class key to struct usb_role_switch Amit Sunil Dhamne
@ 2024-08-15  5:06 ` Greg KH
  2024-08-22 22:32   ` Amit Sunil Dhamne
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2024-08-15  5:06 UTC (permalink / raw)
  To: Amit Sunil Dhamne
  Cc: heikki.krogerus, badhri, linux-usb, linux-kernel, kyletso,
	rdbabiera

On Wed, Aug 14, 2024 at 09:40:55PM -0700, Amit Sunil Dhamne wrote:
> 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>
> ---
> v1->v2
> - Avoid usage of ifdefs.
> ---
>  drivers/usb/roles/class.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
> index d7aa913ceb8a..9dbe9f6bea83 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,11 @@ usb_role_switch_register(struct device *parent,
>  
>  	sw->registered = true;
>  
> +	if (IS_ENABLED(CONFIG_LOCKDEP)) {

Why is this if statement needed at all?

Please get someone internal to your company/group to review the change
before sending it out for others to find the obvious issues with it.
That's what your peers are for.  Please do so and get them to provide a
reviewed-by on it before submitting it again.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] usb: roles: add lockdep class key to struct usb_role_switch
  2024-08-15  5:06 ` Greg KH
@ 2024-08-22 22:32   ` Amit Sunil Dhamne
  0 siblings, 0 replies; 3+ messages in thread
From: Amit Sunil Dhamne @ 2024-08-22 22:32 UTC (permalink / raw)
  To: Greg KH
  Cc: heikki.krogerus, badhri, linux-usb, linux-kernel, kyletso,
	rdbabiera


On 8/14/24 10:06 PM, Greg KH wrote:
> On Wed, Aug 14, 2024 at 09:40:55PM -0700, Amit Sunil Dhamne wrote:
>> 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>
>> ---
>> v1->v2
>> - Avoid usage of ifdefs.
>> ---
>>   drivers/usb/roles/class.c | 12 ++++++++++++
>>   1 file changed, 12 insertions(+)
>>
>> diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
>> index d7aa913ceb8a..9dbe9f6bea83 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,11 @@ usb_role_switch_register(struct device *parent,
>>   
>>   	sw->registered = true;
>>   
>> +	if (IS_ENABLED(CONFIG_LOCKDEP)) {
> Why is this if statement needed at all?

Upon closer look it's redundant. Unfortunately, I missed the different 
definitions for the lockdep API & structs based on CONFIG_LOCKDEP in hdr 
file.

Will be more careful next time.

>
> Please get someone internal to your company/group to review the change
> before sending it out for others to find the obvious issues with it.
> That's what your peers are for.  Please do so and get them to provide a
> reviewed-by on it before submitting it again.

Sounds good. I will send the next revision with reviewed-by signature 
from a peer.


Thanks,

Amit

> thanks,
>
> greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-22 22:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-15  4:40 [PATCH v2] usb: roles: add lockdep class key to struct usb_role_switch Amit Sunil Dhamne
2024-08-15  5:06 ` Greg KH
2024-08-22 22:32   ` Amit Sunil Dhamne

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox