diff mbox

[v2] zd1211rw: replace ZD_ASSERT with lockdep_assert_held()

Message ID 1410430179-19944-1-git-send-email-sanjeev_sharma@mentor.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Sharma, Sanjeev Sept. 11, 2014, 10:09 a.m. UTC
on some architecture spin_is_locked() always return false in
uniprocessor configuration and therefore it would be advise
to replace with lockdep_assert_held().

Signed-off-by: Sanjeev Sharma <Sanjeev_Sharma@mentor.com>
---
Changes in v2:
  - corrected the typo

 drivers/net/wireless/zd1211rw/zd_mac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Johannes Berg Sept. 11, 2014, 10:12 a.m. UTC | #1
On Thu, 2014-09-11 at 15:39 +0530, Sanjeev Sharma wrote:
> on some architecture spin_is_locked() always return false in
> uniprocessor configuration and therefore it would be advise
> to replace with lockdep_assert_held().
> 
> Signed-off-by: Sanjeev Sharma <Sanjeev_Sharma@mentor.com>
> ---
> Changes in v2:
>   - corrected the typo

Now it compiles, but you got the logic wrong.

> +++ b/drivers/net/wireless/zd1211rw/zd_mac.c
> @@ -235,7 +235,7 @@ void zd_mac_clear(struct zd_mac *mac)
>  {
>  	flush_workqueue(zd_workqueue);
>  	zd_chip_clear(&mac->chip);
> -	ZD_ASSERT(!spin_is_locked(&mac->lock));
> +	lockdep_assert_held(&mac->lock);
>  	ZD_MEMCLEAR(mac, sizeof(struct zd_mac));
>  }

Look closely at this again.

johannes

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sharma, Sanjeev Sept. 11, 2014, 10:36 a.m. UTC | #2
-----Original Message-----
From: Johannes Berg [mailto:johannes@sipsolutions.net] 

Sent: Thursday, September 11, 2014 3:42 PM
To: Sharma, Sanjeev
Cc: dsd@gentoo.org; kune@deine-taler.de; linux-wireless@vger.kernel.org; linux-kernel@vger.kernel.org; netdev@vger.kernel.org
Subject: Re: [PATCH v2] zd1211rw: replace ZD_ASSERT with lockdep_assert_held()

On Thu, 2014-09-11 at 15:39 +0530, Sanjeev Sharma wrote:
> on some architecture spin_is_locked() always return false in 

> uniprocessor configuration and therefore it would be advise to replace 

> with lockdep_assert_held().

> 

> Signed-off-by: Sanjeev Sharma <Sanjeev_Sharma@mentor.com>

> ---

> Changes in v2:

>   - corrected the typo


> Now it compiles, but you got the logic wrong.


> +++ b/drivers/net/wireless/zd1211rw/zd_mac.c

> @@ -235,7 +235,7 @@ void zd_mac_clear(struct zd_mac *mac)  {

>  	flush_workqueue(zd_workqueue);

>  	zd_chip_clear(&mac->chip);

> -	ZD_ASSERT(!spin_is_locked(&mac->lock));

> +	lockdep_assert_held(&mac->lock);

>  	ZD_MEMCLEAR(mac, sizeof(struct zd_mac));  }


>Look closely at this again.


I didn't understand where I  put wrong logic  ?

Regards
Sanjeev Sharma
Johannes Berg Sept. 11, 2014, 10:42 a.m. UTC | #3
On Thu, 2014-09-11 at 10:36 +0000, Sharma, Sanjeev wrote:

> > -	ZD_ASSERT(!spin_is_locked(&mac->lock));
> > +	lockdep_assert_held(&mac->lock);

> >Look closely at this again.
> 
> I didn't understand where I  put wrong logic  ?

Ok, that's fine. But please send a new patch only when you've understood
the logic.

johannes

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Julian Calaby Sept. 15, 2014, 6:02 a.m. UTC | #4
Hi Sanjeev,

On Thu, Sep 11, 2014 at 8:36 PM, Sharma, Sanjeev
<Sanjeev_Sharma@mentor.com> wrote:
> -----Original Message-----
> From: Johannes Berg [mailto:johannes@sipsolutions.net]
> Sent: Thursday, September 11, 2014 3:42 PM
> To: Sharma, Sanjeev
> Cc: dsd@gentoo.org; kune@deine-taler.de; linux-wireless@vger.kernel.org; linux-kernel@vger.kernel.org; netdev@vger.kernel.org
> Subject: Re: [PATCH v2] zd1211rw: replace ZD_ASSERT with lockdep_assert_held()
>
> On Thu, 2014-09-11 at 15:39 +0530, Sanjeev Sharma wrote:
>> on some architecture spin_is_locked() always return false in
>> uniprocessor configuration and therefore it would be advise to replace
>> with lockdep_assert_held().
>>
>> Signed-off-by: Sanjeev Sharma <Sanjeev_Sharma@mentor.com>
>> ---
>> Changes in v2:
>>   - corrected the typo
>
>> Now it compiles, but you got the logic wrong.
>
>> +++ b/drivers/net/wireless/zd1211rw/zd_mac.c
>> @@ -235,7 +235,7 @@ void zd_mac_clear(struct zd_mac *mac)  {
>>       flush_workqueue(zd_workqueue);
>>       zd_chip_clear(&mac->chip);
>> -     ZD_ASSERT(!spin_is_locked(&mac->lock));
>> +     lockdep_assert_held(&mac->lock);
>>       ZD_MEMCLEAR(mac, sizeof(struct zd_mac));  }
>
>>Look closely at this again.
>
> I didn't understand where I  put wrong logic  ?

I find it helps to spell out what code is doing in words.

E.g. the line you're removing is:
ZD_ASSERT(!spin_is_locked(&mac->lock));

So, we'll assert when spin_is_locked(&mac->lock) is false, i.e. when
mac->lock is not spin locked.

This isn't the same as what you're replacing it with.

Thanks,
Sharma, Sanjeev Sept. 30, 2014, 7:42 a.m. UTC | #5
-----Original Message-----
From: Julian Calaby [mailto:julian.calaby@gmail.com] 

Sent: Monday, September 15, 2014 11:32 AM
To: Sharma, Sanjeev
Cc: Johannes Berg; dsd@gentoo.org; kune@deine-taler.de; linux-wireless@vger.kernel.org; linux-kernel@vger.kernel.org; netdev@vger.kernel.org
Subject: Re: [PATCH v2] zd1211rw: replace ZD_ASSERT with lockdep_assert_held()

Hi Sanjeev,

On Thu, Sep 11, 2014 at 8:36 PM, Sharma, Sanjeev <Sanjeev_Sharma@mentor.com> wrote:
> -----Original Message-----

> From: Johannes Berg [mailto:johannes@sipsolutions.net]

> Sent: Thursday, September 11, 2014 3:42 PM

> To: Sharma, Sanjeev

> Cc: dsd@gentoo.org; kune@deine-taler.de; 

> linux-wireless@vger.kernel.org; linux-kernel@vger.kernel.org; 

> netdev@vger.kernel.org

> Subject: Re: [PATCH v2] zd1211rw: replace ZD_ASSERT with 

> lockdep_assert_held()

>

> On Thu, 2014-09-11 at 15:39 +0530, Sanjeev Sharma wrote:

>> on some architecture spin_is_locked() always return false in 

>> uniprocessor configuration and therefore it would be advise to 

>> replace with lockdep_assert_held().

>>

>> Signed-off-by: Sanjeev Sharma <Sanjeev_Sharma@mentor.com>

>> ---

>> Changes in v2:

>>   - corrected the typo

>

>> Now it compiles, but you got the logic wrong.

>

>> +++ b/drivers/net/wireless/zd1211rw/zd_mac.c

>> @@ -235,7 +235,7 @@ void zd_mac_clear(struct zd_mac *mac)  {

>>       flush_workqueue(zd_workqueue);

>>       zd_chip_clear(&mac->chip);

>> -     ZD_ASSERT(!spin_is_locked(&mac->lock));

>> +     lockdep_assert_held(&mac->lock);

>>       ZD_MEMCLEAR(mac, sizeof(struct zd_mac));  }

>

>>Look closely at this again.

>

> I didn't understand where I  put wrong logic  ?


I find it helps to spell out what code is doing in words.

E.g. the line you're removing is:
ZD_ASSERT(!spin_is_locked(&mac->lock));

So, we'll assert when spin_is_locked(&mac->lock) is false, i.e. when
mac->lock is not spin locked.

This isn't the same as what you're replacing it with.

 I  feel logic is absolutely correct and if you expand it will looks like ..

+#define lockdep_assert_held(l)	do {	\ 
+	WARN_ON(debug_locks && !lockdep_is_held(l));	\ 
+	} while (0)

Please refer http://lkml.iu.edu/hypermail/linux/kernel/1203.2/00369.html and also see include/linux/lockdep.h for more detail.

Thanks
Sanjeev Sharma
diff mbox

Patch

diff --git a/drivers/net/wireless/zd1211rw/zd_mac.c b/drivers/net/wireless/zd1211rw/zd_mac.c
index e7af261..adce2ee 100644
--- a/drivers/net/wireless/zd1211rw/zd_mac.c
+++ b/drivers/net/wireless/zd1211rw/zd_mac.c
@@ -235,7 +235,7 @@  void zd_mac_clear(struct zd_mac *mac)
 {
 	flush_workqueue(zd_workqueue);
 	zd_chip_clear(&mac->chip);
-	ZD_ASSERT(!spin_is_locked(&mac->lock));
+	lockdep_assert_held(&mac->lock);
 	ZD_MEMCLEAR(mac, sizeof(struct zd_mac));
 }