linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] b43: Fix sparse warnings
@ 2009-08-13 22:15 Larry Finger
  2009-08-14 20:15 ` Michael Buesch
  0 siblings, 1 reply; 14+ messages in thread
From: Larry Finger @ 2009-08-13 22:15 UTC (permalink / raw)
  To: John W Linville, Michael Buesch; +Cc: bcm43xx-dev, linux-wireless

The b43 driver generates the following sparse warnings:

  CHECK   drivers/net/wireless/b43/phy_g.c
drivers/net/wireless/b43/phy_g.c:974:35: warning: cast truncates bits from constant value (ffff7fff becomes 7fff)
  CHECK   drivers/net/wireless/b43/wa.c
drivers/net/wireless/b43/wa.c:385:53: warning: cast truncates bits from constant value (ffff00ff becomes ff)
drivers/net/wireless/b43/wa.c:403:48: warning: cast truncates bits from constant value (ffff00ff becomes ff)
drivers/net/wireless/b43/wa.c:405:48: warning: cast truncates bits from constant value (ffff00ff becomes ff)
drivers/net/wireless/b43/wa.c:415:50: warning: cast truncates bits from constant value (ffff0fff becomes fff)

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
---

John,

There is no hurry for this material.

Larry
---

Index: wireless-testing/drivers/net/wireless/b43/phy_g.c
===================================================================
--- wireless-testing.orig/drivers/net/wireless/b43/phy_g.c
+++ wireless-testing/drivers/net/wireless/b43/phy_g.c
@@ -971,7 +971,7 @@ b43_radio_interference_mitigation_enable
 		b43_phy_maskset(dev, 0x04A2, 0xFFF0, 0x000B);
 
 		if (phy->rev >= 3) {
-			b43_phy_mask(dev, 0x048A, (u16)~0x8000);
+			b43_phy_mask(dev, 0x048A, (u16)(~0x8000 & 0xFFFF));
 			b43_phy_maskset(dev, 0x0415, 0x8000, 0x36D8);
 			b43_phy_maskset(dev, 0x0416, 0x8000, 0x36D8);
 			b43_phy_maskset(dev, 0x0417, 0xFE00, 0x016D);
Index: wireless-testing/drivers/net/wireless/b43/wa.c
===================================================================
--- wireless-testing.orig/drivers/net/wireless/b43/wa.c
+++ wireless-testing/drivers/net/wireless/b43/wa.c
@@ -382,7 +382,8 @@ static void b43_wa_altagc(struct b43_wld
 		b43_ofdmtab_write16(dev, B43_OFDMTAB_AGC1, 3, 25);
 	}
 
-	b43_phy_maskset(dev, B43_PHY_CCKSHIFTBITS_WA, (u16)~0xFF00, 0x5700);
+	b43_phy_maskset(dev, B43_PHY_CCKSHIFTBITS_WA, (u16)(~0xFF00 & 0xFFFF),
+			0x5700);
 	b43_phy_maskset(dev, B43_PHY_OFDM(0x1A), ~0x007F, 0x000F);
 	b43_phy_maskset(dev, B43_PHY_OFDM(0x1A), ~0x3F80, 0x2B80);
 	b43_phy_maskset(dev, B43_PHY_ANTWRSETT, 0xF0FF, 0x0300);
@@ -400,9 +401,9 @@ static void b43_wa_altagc(struct b43_wld
 	b43_phy_maskset(dev, B43_PHY_OFDM(0x89), ~0x00FF, 0x0020);
 	b43_phy_maskset(dev, B43_PHY_OFDM(0x89), ~0x3F00, 0x0200);
 	b43_phy_maskset(dev, B43_PHY_OFDM(0x82), ~0x00FF, 0x002E);
-	b43_phy_maskset(dev, B43_PHY_OFDM(0x96), (u16)~0xFF00, 0x1A00);
+	b43_phy_maskset(dev, B43_PHY_OFDM(0x96), (u16)(~0xFF00 & 0xFFFF), 0x1A00);
 	b43_phy_maskset(dev, B43_PHY_OFDM(0x81), ~0x00FF, 0x0028);
-	b43_phy_maskset(dev, B43_PHY_OFDM(0x81), (u16)~0xFF00, 0x2C00);
+	b43_phy_maskset(dev, B43_PHY_OFDM(0x81), (u16)(~0xFF00 & 0xFFFF), 0x2C00);
 	if (phy->rev == 1) {
 		b43_phy_write(dev, B43_PHY_PEAK_COUNT, 0x092B);
 		b43_phy_maskset(dev, B43_PHY_OFDM(0x1B), ~0x001E, 0x0002);
@@ -412,7 +413,8 @@ static void b43_wa_altagc(struct b43_wld
 		b43_phy_maskset(dev, B43_PHY_LPFGAINCTL, ~0x000F, 0x0004);
 		if (phy->rev >= 6) {
 			b43_phy_write(dev, B43_PHY_OFDM(0x22), 0x287A);
-			b43_phy_maskset(dev, B43_PHY_LPFGAINCTL, (u16)~0xF000, 0x3000);
+			b43_phy_maskset(dev, B43_PHY_LPFGAINCTL, (u16)(~0xF000 &
+					0xFFFF), 0x3000);
 		}
 	}
 	b43_phy_maskset(dev, B43_PHY_DIVSRCHIDX, 0x8080, 0x7874);

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

* Re: [PATCH] b43: Fix sparse warnings
  2009-08-13 22:15 [PATCH] b43: Fix sparse warnings Larry Finger
@ 2009-08-14 20:15 ` Michael Buesch
  2009-08-14 20:52   ` Pavel Roskin
  2009-08-14 21:33   ` Larry Finger
  0 siblings, 2 replies; 14+ messages in thread
From: Michael Buesch @ 2009-08-14 20:15 UTC (permalink / raw)
  To: Larry Finger; +Cc: John W Linville, bcm43xx-dev, linux-wireless

On Friday 14 August 2009 00:15:07 Larry Finger wrote:
> The b43 driver generates the following sparse warnings:
> 
>   CHECK   drivers/net/wireless/b43/phy_g.c
> drivers/net/wireless/b43/phy_g.c:974:35: warning: cast truncates bits from constant value (ffff7fff becomes 7fff)
>   CHECK   drivers/net/wireless/b43/wa.c
> drivers/net/wireless/b43/wa.c:385:53: warning: cast truncates bits from constant value (ffff00ff becomes ff)
> drivers/net/wireless/b43/wa.c:403:48: warning: cast truncates bits from constant value (ffff00ff becomes ff)
> drivers/net/wireless/b43/wa.c:405:48: warning: cast truncates bits from constant value (ffff00ff becomes ff)
> drivers/net/wireless/b43/wa.c:415:50: warning: cast truncates bits from constant value (ffff0fff becomes fff)
> 
> Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
> ---
> 
> John,
> 
> There is no hurry for this material.
> 
> Larry
> ---
> 
> Index: wireless-testing/drivers/net/wireless/b43/phy_g.c
> ===================================================================
> --- wireless-testing.orig/drivers/net/wireless/b43/phy_g.c
> +++ wireless-testing/drivers/net/wireless/b43/phy_g.c
> @@ -971,7 +971,7 @@ b43_radio_interference_mitigation_enable
>  		b43_phy_maskset(dev, 0x04A2, 0xFFF0, 0x000B);
>  
>  		if (phy->rev >= 3) {
> -			b43_phy_mask(dev, 0x048A, (u16)~0x8000);
> +			b43_phy_mask(dev, 0x048A, (u16)(~0x8000 & 0xFFFF));

Uh come on...
The u16 cast already is stupid as hell, but this is becoming braindead.
The code is perfectly fine. Sparse should instead provide an option to disable
this fragile check.

-- 
Greetings, Michael.

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

* Re: [PATCH] b43: Fix sparse warnings
  2009-08-14 20:15 ` Michael Buesch
@ 2009-08-14 20:52   ` Pavel Roskin
  2009-08-14 21:00     ` Michael Buesch
  2009-08-14 21:33   ` Larry Finger
  1 sibling, 1 reply; 14+ messages in thread
From: Pavel Roskin @ 2009-08-14 20:52 UTC (permalink / raw)
  To: Michael Buesch; +Cc: Larry Finger, John W Linville, bcm43xx-dev, linux-wireless

On Fri, 2009-08-14 at 22:15 +0200, Michael Buesch wrote:

> > -			b43_phy_mask(dev, 0x048A, (u16)~0x8000);
> > +			b43_phy_mask(dev, 0x048A, (u16)(~0x8000 & 0xFFFF));
> 
> Uh come on...
> The u16 cast already is stupid as hell, but this is becoming braindead.
> The code is perfectly fine. Sparse should instead provide an option to disable
> this fragile check.

There are cases where we want to know that a constant was truncated.  In
fact, in most cases it's a useful warning.

In this case, we intuitively expect that it's OK to cast a result of a
bitwise operation to its original type, as if it was never promoted.
But sparse will need to have a special exception for this case.

I would just use 0x7fff here.

-- 
Regards,
Pavel Roskin

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

* Re: [PATCH] b43: Fix sparse warnings
  2009-08-14 20:52   ` Pavel Roskin
@ 2009-08-14 21:00     ` Michael Buesch
  2009-08-14 21:04       ` Gábor Stefanik
  2009-08-14 21:29       ` Pavel Roskin
  0 siblings, 2 replies; 14+ messages in thread
From: Michael Buesch @ 2009-08-14 21:00 UTC (permalink / raw)
  To: Pavel Roskin; +Cc: Larry Finger, John W Linville, bcm43xx-dev, linux-wireless

On Friday 14 August 2009 22:52:13 Pavel Roskin wrote:
> On Fri, 2009-08-14 at 22:15 +0200, Michael Buesch wrote:
> 
> > > -			b43_phy_mask(dev, 0x048A, (u16)~0x8000);
> > > +			b43_phy_mask(dev, 0x048A, (u16)(~0x8000 & 0xFFFF));
> > 

> I would just use 0x7fff here.

That does not work if 0x8000 is a #defined bit.

-- 
Greetings, Michael.

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

* Re: [PATCH] b43: Fix sparse warnings
  2009-08-14 21:00     ` Michael Buesch
@ 2009-08-14 21:04       ` Gábor Stefanik
  2009-08-14 21:35         ` Pavel Roskin
  2009-08-14 21:29       ` Pavel Roskin
  1 sibling, 1 reply; 14+ messages in thread
From: Gábor Stefanik @ 2009-08-14 21:04 UTC (permalink / raw)
  To: Michael Buesch; +Cc: Pavel Roskin, linux-wireless, bcm43xx-dev, Larry Finger

On Fri, Aug 14, 2009 at 11:00 PM, Michael Buesch<mb@bu3sch.de> wrote:
> On Friday 14 August 2009 22:52:13 Pavel Roskin wrote:
>> On Fri, 2009-08-14 at 22:15 +0200, Michael Buesch wrote:
>>
>> > > -                 b43_phy_mask(dev, 0x048A, (u16)~0x8000);
>> > > +                 b43_phy_mask(dev, 0x048A, (u16)(~0x8000 & 0xFFFF));
>> >
>
>> I would just use 0x7fff here.
>
> That does not work if 0x8000 is a #defined bit.

What about ~((u16)0x8000)? (Or maybe ~(u16)0x8000 is enough, without
the extra parentheses.)

>
> --
> Greetings, Michael.
> _______________________________________________
> Bcm43xx-dev mailing list
> Bcm43xx-dev@lists.berlios.de
> https://lists.berlios.de/mailman/listinfo/bcm43xx-dev
>



-- 
Vista: [V]iruses, [I]ntruders, [S]pyware, [T]rojans and [A]dware. :-)

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

* Re: [PATCH] b43: Fix sparse warnings
  2009-08-14 21:00     ` Michael Buesch
  2009-08-14 21:04       ` Gábor Stefanik
@ 2009-08-14 21:29       ` Pavel Roskin
  2009-08-14 21:46         ` Pavel Roskin
  1 sibling, 1 reply; 14+ messages in thread
From: Pavel Roskin @ 2009-08-14 21:29 UTC (permalink / raw)
  To: Michael Buesch; +Cc: Larry Finger, John W Linville, bcm43xx-dev, linux-wireless

On Fri, 2009-08-14 at 23:00 +0200, Michael Buesch wrote:
> On Friday 14 August 2009 22:52:13 Pavel Roskin wrote:
> > On Fri, 2009-08-14 at 22:15 +0200, Michael Buesch wrote:
> > 
> > > > -			b43_phy_mask(dev, 0x048A, (u16)~0x8000);
> > > > +			b43_phy_mask(dev, 0x048A, (u16)(~0x8000 & 0xFFFF));
> > > 
> 
> > I would just use 0x7fff here.
> 
> That does not work if 0x8000 is a #defined bit.

One approach would be to use a macro and tell sparse to ignore it

#define NEGATE(x) (__force typeof(x))(~x)

Another approach would be to have b43_phy_mask() and similar functions
accept int and do the bit cutting in one place.

It should also be possible to have separate functions e.g.
b43_phy_unmask() that would do the negation, so that the caller won't
need to do it.

-- 
Regards,
Pavel Roskin

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

* Re: [PATCH] b43: Fix sparse warnings
  2009-08-14 20:15 ` Michael Buesch
  2009-08-14 20:52   ` Pavel Roskin
@ 2009-08-14 21:33   ` Larry Finger
  1 sibling, 0 replies; 14+ messages in thread
From: Larry Finger @ 2009-08-14 21:33 UTC (permalink / raw)
  To: Michael Buesch, John W Linville; +Cc: bcm43xx-dev, linux-wireless

Michael Buesch wrote:
> On Friday 14 August 2009 00:15:07 Larry Finger wrote:
>> The b43 driver generates the following sparse warnings:
>>
>>   CHECK   drivers/net/wireless/b43/phy_g.c
>> drivers/net/wireless/b43/phy_g.c:974:35: warning: cast truncates bits from constant value (ffff7fff becomes 7fff)
>>   CHECK   drivers/net/wireless/b43/wa.c
>> drivers/net/wireless/b43/wa.c:385:53: warning: cast truncates bits from constant value (ffff00ff becomes ff)
>> drivers/net/wireless/b43/wa.c:403:48: warning: cast truncates bits from constant value (ffff00ff becomes ff)
>> drivers/net/wireless/b43/wa.c:405:48: warning: cast truncates bits from constant value (ffff00ff becomes ff)
>> drivers/net/wireless/b43/wa.c:415:50: warning: cast truncates bits from constant value (ffff0fff becomes fff)
>>
>> Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
>> ---
>>
>> John,
>>
>> There is no hurry for this material.
>>
>> Larry
>> ---
>>
>> Index: wireless-testing/drivers/net/wireless/b43/phy_g.c
>> ===================================================================
>> --- wireless-testing.orig/drivers/net/wireless/b43/phy_g.c
>> +++ wireless-testing/drivers/net/wireless/b43/phy_g.c
>> @@ -971,7 +971,7 @@ b43_radio_interference_mitigation_enable
>>  		b43_phy_maskset(dev, 0x04A2, 0xFFF0, 0x000B);
>>  
>>  		if (phy->rev >= 3) {
>> -			b43_phy_mask(dev, 0x048A, (u16)~0x8000);
>> +			b43_phy_mask(dev, 0x048A, (u16)(~0x8000 & 0xFFFF));
> 
> Uh come on...
> The u16 cast already is stupid as hell, but this is becoming braindead.
> The code is perfectly fine. Sparse should instead provide an option to disable
> this fragile check.

John,

Just drop this patch. The code is OK as is.

Larry

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

* Re: [PATCH] b43: Fix sparse warnings
  2009-08-14 21:04       ` Gábor Stefanik
@ 2009-08-14 21:35         ` Pavel Roskin
  2009-08-15 10:04           ` Michael Buesch
  0 siblings, 1 reply; 14+ messages in thread
From: Pavel Roskin @ 2009-08-14 21:35 UTC (permalink / raw)
  To: Gábor Stefanik
  Cc: Michael Buesch, linux-wireless, bcm43xx-dev, Larry Finger

On Fri, 2009-08-14 at 23:04 +0200, Gábor Stefanik wrote:
> On Fri, Aug 14, 2009 at 11:00 PM, Michael Buesch<mb@bu3sch.de> wrote:
> > On Friday 14 August 2009 22:52:13 Pavel Roskin wrote:
> >> On Fri, 2009-08-14 at 22:15 +0200, Michael Buesch wrote:
> >>
> >> > > -                 b43_phy_mask(dev, 0x048A, (u16)~0x8000);
> >> > > +                 b43_phy_mask(dev, 0x048A, (u16)(~0x8000 & 0xFFFF));
> >> >
> >
> >> I would just use 0x7fff here.
> >
> > That does not work if 0x8000 is a #defined bit.
> 
> What about ~((u16)0x8000)?

phy_g.c:974: warning: large integer implicitly truncated to unsigned
type

>  (Or maybe ~(u16)0x8000 is enough, without
> the extra parentheses.)

Same thing.  Sparse complains whether the cast is explicit or implicit.

-- 
Regards,
Pavel Roskin

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

* Re: [PATCH] b43: Fix sparse warnings
  2009-08-14 21:29       ` Pavel Roskin
@ 2009-08-14 21:46         ` Pavel Roskin
  2009-08-15 10:08           ` Michael Buesch
  0 siblings, 1 reply; 14+ messages in thread
From: Pavel Roskin @ 2009-08-14 21:46 UTC (permalink / raw)
  To: Michael Buesch; +Cc: Larry Finger, John W Linville, bcm43xx-dev, linux-wireless

On Fri, 2009-08-14 at 17:29 -0400, Pavel Roskin wrote:
> On Fri, 2009-08-14 at 23:00 +0200, Michael Buesch wrote:
> > On Friday 14 August 2009 22:52:13 Pavel Roskin wrote:
> > > On Fri, 2009-08-14 at 22:15 +0200, Michael Buesch wrote:
> > > 
> > > > > -			b43_phy_mask(dev, 0x048A, (u16)~0x8000);
> > > > > +			b43_phy_mask(dev, 0x048A, (u16)(~0x8000 & 0xFFFF));
> > > > 
> > 
> > > I would just use 0x7fff here.
> > 
> > That does not work if 0x8000 is a #defined bit.
> 
> One approach would be to use a macro and tell sparse to ignore it
> 
> #define NEGATE(x) (__force typeof(x))(~x)

Scratch that.  It has no change to work for constants unless we hardcode
the size, e.g. by having NEGATE16, NEGATE32 etc.

The best I could do is:

#define NEGATE16(x) (0xFFFF & ~x)
b43_phy_mask(dev, 0x048A, NEGATE16(0x8000));

> Another approach would be to have b43_phy_mask() and similar functions
> accept int and do the bit cutting in one place.

I tend to think that it would be the best approach.

> It should also be possible to have separate functions e.g.
> b43_phy_unmask() that would do the negation, so that the caller won't
> need to do it.

This could make the code hard to read.

-- 
Regards,
Pavel Roskin

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

* Re: [PATCH] b43: Fix sparse warnings
  2009-08-14 21:35         ` Pavel Roskin
@ 2009-08-15 10:04           ` Michael Buesch
  2009-08-17 20:30             ` Pavel Roskin
  0 siblings, 1 reply; 14+ messages in thread
From: Michael Buesch @ 2009-08-15 10:04 UTC (permalink / raw)
  To: Pavel Roskin
  Cc: Gábor Stefanik, linux-wireless, bcm43xx-dev, Larry Finger

On Friday 14 August 2009 23:35:29 Pavel Roskin wrote:
> On Fri, 2009-08-14 at 23:04 +0200, Gábor Stefanik wrote:
> > On Fri, Aug 14, 2009 at 11:00 PM, Michael Buesch<mb@bu3sch.de> wrote:
> > > On Friday 14 August 2009 22:52:13 Pavel Roskin wrote:
> > >> On Fri, 2009-08-14 at 22:15 +0200, Michael Buesch wrote:
> > >>
> > >> > > -                 b43_phy_mask(dev, 0x048A, (u16)~0x8000);
> > >> > > +                 b43_phy_mask(dev, 0x048A, (u16)(~0x8000 & 0xFFFF));
> > >> >
> > >
> > >> I would just use 0x7fff here.
> > >
> > > That does not work if 0x8000 is a #defined bit.
> > 
> > What about ~((u16)0x8000)?
> 
> phy_g.c:974: warning: large integer implicitly truncated to unsigned
> type
> 
> >  (Or maybe ~(u16)0x8000 is enough, without
> > the extra parentheses.)
> 
> Same thing.  Sparse complains whether the cast is explicit or implicit.
> 

I still do not understand why it does complain about an _explicit_ truncation.
That's simply stupid. If I program an explicit truncation I _do_ mean to truncate the value.

-- 
Greetings, Michael.

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

* Re: [PATCH] b43: Fix sparse warnings
  2009-08-14 21:46         ` Pavel Roskin
@ 2009-08-15 10:08           ` Michael Buesch
  0 siblings, 0 replies; 14+ messages in thread
From: Michael Buesch @ 2009-08-15 10:08 UTC (permalink / raw)
  To: Pavel Roskin; +Cc: Larry Finger, John W Linville, bcm43xx-dev, linux-wireless

On Friday 14 August 2009 23:46:54 Pavel Roskin wrote:
> On Fri, 2009-08-14 at 17:29 -0400, Pavel Roskin wrote:
> > On Fri, 2009-08-14 at 23:00 +0200, Michael Buesch wrote:
> > > On Friday 14 August 2009 22:52:13 Pavel Roskin wrote:
> > > > On Fri, 2009-08-14 at 22:15 +0200, Michael Buesch wrote:
> > > > 
> > > > > > -			b43_phy_mask(dev, 0x048A, (u16)~0x8000);
> > > > > > +			b43_phy_mask(dev, 0x048A, (u16)(~0x8000 & 0xFFFF));
> > > > > 
> > > 
> > > > I would just use 0x7fff here.
> > > 
> > > That does not work if 0x8000 is a #defined bit.
> > 
> > One approach would be to use a macro and tell sparse to ignore it
> > 
> > #define NEGATE(x) (__force typeof(x))(~x)
> 
> Scratch that.  It has no change to work for constants unless we hardcode
> the size, e.g. by having NEGATE16, NEGATE32 etc.
> 
> The best I could do is:
> 
> #define NEGATE16(x) (0xFFFF & ~x)
> b43_phy_mask(dev, 0x048A, NEGATE16(0x8000));

I think the real question is whether this does really prevent any bugs or whether
it just introduces new possibilities for bugs.

void my_func(u32 x);

my_func(NEGATE16(0x8000));

-- 
Greetings, Michael.

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

* Re: [PATCH] b43: Fix sparse warnings
  2009-08-15 10:04           ` Michael Buesch
@ 2009-08-17 20:30             ` Pavel Roskin
  2009-08-18 13:12               ` Michael Buesch
  0 siblings, 1 reply; 14+ messages in thread
From: Pavel Roskin @ 2009-08-17 20:30 UTC (permalink / raw)
  To: Michael Buesch
  Cc: Gábor Stefanik, linux-wireless, bcm43xx-dev, Larry Finger

On Sat, 2009-08-15 at 12:04 +0200, Michael Buesch wrote:

> I still do not understand why it does complain about an _explicit_ truncation.
> That's simply stupid. If I program an explicit truncation I _do_ mean to truncate the value.

Actually, it's a bug in sparse.  Sparse acts inconsistently.

This causes a warning:

void mask(unsigned short mask);
static void test(void)
{
        mask((unsigned short)0xffff0000);
}

test.c:4:30: warning: cast truncates bits from constant value (ffff0000
becomes 0)

But this is OK:

void mask(unsigned short mask);
static void test(void)
{
        mask((unsigned short)0xfffff000);
}

Moreover, this is OK, even though the cast changes the value of the
constant:

void mask(unsigned short mask);
static void test(void)
{
        mask((unsigned short)0xfffff000U);
}

I suggest that we take no action until sparse is fixed.  I'm going to
report the issue to the sparse mailing list now.

-- 
Regards,
Pavel Roskin

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

* Re: [PATCH] b43: Fix sparse warnings
  2009-08-17 20:30             ` Pavel Roskin
@ 2009-08-18 13:12               ` Michael Buesch
  0 siblings, 0 replies; 14+ messages in thread
From: Michael Buesch @ 2009-08-18 13:12 UTC (permalink / raw)
  To: Pavel Roskin
  Cc: Gábor Stefanik, linux-wireless, bcm43xx-dev, Larry Finger

On Monday 17 August 2009 22:30:41 Pavel Roskin wrote:
> On Sat, 2009-08-15 at 12:04 +0200, Michael Buesch wrote:
> 
> > I still do not understand why it does complain about an _explicit_ truncation.
> > That's simply stupid. If I program an explicit truncation I _do_ mean to truncate the value.
> 
> Actually, it's a bug in sparse.  Sparse acts inconsistently.
> 
> This causes a warning:
> 
> void mask(unsigned short mask);
> static void test(void)
> {
>         mask((unsigned short)0xffff0000);
> }
> 
> test.c:4:30: warning: cast truncates bits from constant value (ffff0000
> becomes 0)
> 
> But this is OK:
> 
> void mask(unsigned short mask);
> static void test(void)
> {
>         mask((unsigned short)0xfffff000);
> }
> 
> Moreover, this is OK, even though the cast changes the value of the
> constant:
> 
> void mask(unsigned short mask);
> static void test(void)
> {
>         mask((unsigned short)0xfffff000U);
> }
> 
> I suggest that we take no action until sparse is fixed.  I'm going to
> report the issue to the sparse mailing list now.
> 

Cool, thanks a lot for tracking this down. :)

-- 
Greetings, Michael.

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

* [PATCH] b43: Fix sparse warnings.
@ 2007-09-19 16:30 Michael Buesch
  0 siblings, 0 replies; 14+ messages in thread
From: Michael Buesch @ 2007-09-19 16:30 UTC (permalink / raw)
  To: John Linville; +Cc: bcm43xx-dev, linux-wireless

The remaining warning in phy.c will be fixed later.

Signed-off-by: Michael Buesch <mb@bu3sch.de>

Index: wireless-dev/drivers/net/wireless/b43/pio.c
===================================================================
--- wireless-dev.orig/drivers/net/wireless/b43/pio.c	2007-09-19 17:49:20.000000000 +0200
+++ wireless-dev/drivers/net/wireless/b43/pio.c	2007-09-19 17:50:26.000000000 +0200
@@ -60,7 +60,7 @@ static u16 tx_get_next_word(const u8 * t
 		source = packet;
 		i -= txhdr_size;
 	}
-	ret = le16_to_cpu(*((u16 *) (source + i)));
+	ret = le16_to_cpu(*((__le16 *)(source + i)));
 	*pos += 2;
 
 	return ret;
@@ -104,7 +104,7 @@ static u16 generate_cookie(struct b43_pi
 			   struct b43_pio_txpacket *packet)
 {
 	u16 cookie = 0x0000;
-	int packetindex;
+	u16 packetindex;
 
 	/* We use the upper 4 bits for the PIO
 	 * controller ID and the lower 12 bits
@@ -125,7 +125,7 @@ static u16 generate_cookie(struct b43_pi
 	default:
 		B43_WARN_ON(1);
 	}
-	packetindex = pio_txpacket_getindex(packet);
+	packetindex = packet->index;
 	B43_WARN_ON(packetindex & ~0x0FFF);
 	cookie |= (u16) packetindex;
 
@@ -286,6 +286,7 @@ static void setup_txqueues(struct b43_pi
 
 		packet->queue = queue;
 		INIT_LIST_HEAD(&packet->list);
+		packet->index = i;
 
 		list_add(&packet->list, &queue->txfree);
 	}
@@ -518,9 +519,10 @@ static void pio_rx_error(struct b43_pioq
 
 void b43_pio_rx(struct b43_pioqueue *queue)
 {
-	u16 preamble[21] = { 0 };
+	__le16 preamble[21] = { 0 };
 	struct b43_rxhdr_fw4 *rxhdr;
-	u16 tmp, len, macstat;
+	u16 tmp, len;
+	u32 macstat;
 	int i, preamble_readwords;
 	struct sk_buff *skb;
 
@@ -537,7 +539,7 @@ void b43_pio_rx(struct b43_pioqueue *que
 	}
 	b43dbg(queue->dev->wl, "PIO RX timed out\n");
 	return;
-      data_ready:
+data_ready:
 
 	len = b43_pio_read(queue, B43_PIO_RXDATA);
 	if (unlikely(len > 0x700)) {
@@ -558,7 +560,7 @@ void b43_pio_rx(struct b43_pioqueue *que
 		preamble[i + 1] = cpu_to_le16(tmp);
 	}
 	rxhdr = (struct b43_rxhdr_fw4 *)preamble;
-	macstat = le16_to_cpu(rxhdr->mac_status);
+	macstat = le32_to_cpu(rxhdr->mac_status);
 	if (macstat & B43_RX_MAC_FCSERR) {
 		pio_rx_error(queue,
 			     (queue->mmio_base == B43_MMIO_PIO1_BASE),
@@ -583,7 +585,7 @@ void b43_pio_rx(struct b43_pioqueue *que
 	skb_put(skb, len);
 	for (i = 0; i < len - 1; i += 2) {
 		tmp = b43_pio_read(queue, B43_PIO_RXDATA);
-		*((u16 *) (skb->data + i)) = cpu_to_le16(tmp);
+		*((__le16 *)(skb->data + i)) = cpu_to_le16(tmp);
 	}
 	if (len % 2) {
 		tmp = b43_pio_read(queue, B43_PIO_RXDATA);
Index: wireless-dev/drivers/net/wireless/b43/xmit.c
===================================================================
--- wireless-dev.orig/drivers/net/wireless/b43/xmit.c	2007-09-19 17:49:20.000000000 +0200
+++ wireless-dev/drivers/net/wireless/b43/xmit.c	2007-09-19 17:50:26.000000000 +0200
@@ -121,10 +121,12 @@ void b43_generate_plcp_hdr(struct b43_pl
 	__u8 *raw = plcp->raw;
 
 	if (b43_is_ofdm_rate(bitrate)) {
-		*data = b43_plcp_get_ratecode_ofdm(bitrate);
+		u32 d;
+
+		d = b43_plcp_get_ratecode_ofdm(bitrate);
 		B43_WARN_ON(octets & 0xF000);
-		*data |= (octets << 5);
-		*data = cpu_to_le32(*data);
+		d |= (octets << 5);
+		*data = cpu_to_le32(d);
 	} else {
 		u32 plen;
 
Index: wireless-dev/drivers/net/wireless/b43/leds.c
===================================================================
--- wireless-dev.orig/drivers/net/wireless/b43/leds.c	2007-09-19 17:49:20.000000000 +0200
+++ wireless-dev/drivers/net/wireless/b43/leds.c	2007-09-19 17:50:26.000000000 +0200
@@ -32,14 +32,13 @@
 static void b43_led_changestate(struct b43_led *led)
 {
 	struct b43_wldev *dev = led->dev;
-	const int index = b43_led_index(led);
-	const u16 mask = (1 << index);
+	const int index = led->index;
 	u16 ledctl;
 
 	B43_WARN_ON(!(index >= 0 && index < B43_NR_LEDS));
 	B43_WARN_ON(!led->blink_interval);
 	ledctl = b43_read16(dev, B43_MMIO_GPIO_CONTROL);
-	ledctl = (ledctl & mask) ? (ledctl & ~mask) : (ledctl | mask);
+	ledctl ^= (1 << index);
 	b43_write16(dev, B43_MMIO_GPIO_CONTROL, ledctl);
 }
 
@@ -70,7 +69,7 @@ static void b43_led_blink_start(struct b
 static void b43_led_blink_stop(struct b43_led *led, int sync)
 {
 	struct b43_wldev *dev = led->dev;
-	const int index = b43_led_index(led);
+	const int index = led->index;
 	u16 ledctl;
 
 	if (!led->blink_interval)
@@ -139,6 +138,7 @@ int b43_leds_init(struct b43_wldev *dev)
 
 	for (i = 0; i < B43_NR_LEDS; i++) {
 		led = &(dev->leds[i]);
+		led->index = i;
 		led->dev = dev;
 		setup_timer(&led->blink_timer,
 			    b43_led_blink, (unsigned long)led);
Index: wireless-dev/drivers/net/wireless/b43/leds.h
===================================================================
--- wireless-dev.orig/drivers/net/wireless/b43/leds.h	2007-09-19 17:49:20.000000000 +0200
+++ wireless-dev/drivers/net/wireless/b43/leds.h	2007-09-19 17:50:26.000000000 +0200
@@ -5,14 +5,14 @@
 #include <linux/timer.h>
 
 struct b43_led {
-	u8 behaviour:7;
-	u8 activelow:1;
-
+	u8 behaviour;
+	bool activelow;
+	/* Index in the "leds" array in b43_wldev */
+	u8 index;
 	struct b43_wldev *dev;
 	struct timer_list blink_timer;
 	unsigned long blink_interval;
 };
-#define b43_led_index(led)	((int)((led) - (led)->dev->leds))
 
 /* Delay between state changes when blinking in jiffies */
 #define B43_LEDBLINK_SLOW		(HZ / 1)
Index: wireless-dev/drivers/net/wireless/b43/main.c
===================================================================
--- wireless-dev.orig/drivers/net/wireless/b43/main.c	2007-09-19 17:49:20.000000000 +0200
+++ wireless-dev/drivers/net/wireless/b43/main.c	2007-09-19 17:50:26.000000000 +0200
@@ -1062,7 +1062,7 @@ static void handle_irq_noise(struct b43_
 	B43_WARN_ON(!dev->noisecalc.calculation_running);
 	if (dev->noisecalc.channel_at_start != phy->channel)
 		goto drop_calculation;
-	*((u32 *) noise) = cpu_to_le32(b43_jssi_read(dev));
+	*((__le32 *)noise) = cpu_to_le32(b43_jssi_read(dev));
 	if (noise[0] == 0x7F || noise[1] == 0x7F ||
 	    noise[2] == 0x7F || noise[3] == 0x7F)
 		goto generate_new;
@@ -1598,8 +1598,7 @@ static int do_request_fw(struct b43_wlde
 			 const char *name,
 			 const struct firmware **fw)
 {
-	const size_t plen = sizeof(modparam_fwpostfix) + 32;
-	char path[plen];
+	char path[sizeof(modparam_fwpostfix) + 32];
 	struct b43_fw_header *hdr;
 	u32 size;
 	int err;
Index: wireless-dev/drivers/net/wireless/b43/pcmcia.c
===================================================================
--- wireless-dev.orig/drivers/net/wireless/b43/pcmcia.c	2007-09-19 17:49:20.000000000 +0200
+++ wireless-dev/drivers/net/wireless/b43/pcmcia.c	2007-09-19 17:50:26.000000000 +0200
@@ -21,6 +21,8 @@
 
 */
 
+#include "pcmcia.h"
+
 #include <linux/ssb/ssb.h>
 
 #include <pcmcia/cs_types.h>
@@ -30,6 +32,7 @@
 #include <pcmcia/ds.h>
 #include <pcmcia/cisreg.h>
 
+
 static /*const */ struct pcmcia_device_id b43_pcmcia_tbl[] = {
 	PCMCIA_DEVICE_MANF_CARD(0x2D0, 0x448),
 	PCMCIA_DEVICE_NULL,
Index: wireless-dev/drivers/net/wireless/b43/pio.h
===================================================================
--- wireless-dev.orig/drivers/net/wireless/b43/pio.h	2007-09-19 17:49:20.000000000 +0200
+++ wireless-dev/drivers/net/wireless/b43/pio.h	2007-09-19 17:50:26.000000000 +0200
@@ -39,10 +39,9 @@ struct b43_pio_txpacket {
 	struct sk_buff *skb;
 	struct ieee80211_tx_status txstat;
 	struct list_head list;
+	u16 index; /* Index in the tx_packets_cache */
 };
 
-#define pio_txpacket_getindex(packet) ((int)((packet) - (packet)->queue->tx_packets_cache))
-
 struct b43_pioqueue {
 	struct b43_wldev *dev;
 	u16 mmio_base;
Index: wireless-dev/drivers/net/wireless/b43/debugfs.c
===================================================================
--- wireless-dev.orig/drivers/net/wireless/b43/debugfs.c	2007-09-19 17:49:20.000000000 +0200
+++ wireless-dev/drivers/net/wireless/b43/debugfs.c	2007-09-19 18:02:22.000000000 +0200
@@ -39,7 +39,7 @@
 
 
 /* The root directory. */
-struct dentry *rootdir;
+static struct dentry *rootdir;
 
 struct b43_debugfs_fops {
 	ssize_t (*read)(struct b43_wldev *dev, char *buf, size_t bufsize);
@@ -76,7 +76,8 @@ struct b43_dfs_file * fops_to_dfs_file(s
 
 
 /* wl->irq_lock is locked */
-ssize_t tsf_read_file(struct b43_wldev *dev, char *buf, size_t bufsize)
+static ssize_t tsf_read_file(struct b43_wldev *dev,
+			     char *buf, size_t bufsize)
 {
 	ssize_t count = 0;
 	u64 tsf;
@@ -90,7 +91,8 @@ ssize_t tsf_read_file(struct b43_wldev *
 }
 
 /* wl->irq_lock is locked */
-int tsf_write_file(struct b43_wldev *dev, const char *buf, size_t count)
+static int tsf_write_file(struct b43_wldev *dev,
+			  const char *buf, size_t count)
 {
 	u64 tsf;
 
@@ -102,7 +104,8 @@ int tsf_write_file(struct b43_wldev *dev
 }
 
 /* wl->irq_lock is locked */
-ssize_t ucode_regs_read_file(struct b43_wldev *dev, char *buf, size_t bufsize)
+static ssize_t ucode_regs_read_file(struct b43_wldev *dev,
+				    char *buf, size_t bufsize)
 {
 	ssize_t count = 0;
 	int i;
@@ -116,7 +119,8 @@ ssize_t ucode_regs_read_file(struct b43_
 }
 
 /* wl->irq_lock is locked */
-ssize_t shm_read_file(struct b43_wldev *dev, char *buf, size_t bufsize)
+static ssize_t shm_read_file(struct b43_wldev *dev,
+			     char *buf, size_t bufsize)
 {
 	ssize_t count = 0;
 	int i;
@@ -135,7 +139,8 @@ ssize_t shm_read_file(struct b43_wldev *
 	return count;
 }
 
-ssize_t txstat_read_file(struct b43_wldev *dev, char *buf, size_t bufsize)
+static ssize_t txstat_read_file(struct b43_wldev *dev,
+				char *buf, size_t bufsize)
 {
 	struct b43_txstatus_log *log = &dev->dfsentry->txstatlog;
 	ssize_t count = 0;
@@ -182,7 +187,8 @@ out_unlock:
 	return count;
 }
 
-ssize_t txpower_g_read_file(struct b43_wldev *dev, char *buf, size_t bufsize)
+static ssize_t txpower_g_read_file(struct b43_wldev *dev,
+				   char *buf, size_t bufsize)
 {
 	ssize_t count = 0;
 
@@ -214,7 +220,8 @@ out:
 	return count;
 }
 
-int txpower_g_write_file(struct b43_wldev *dev, const char *buf, size_t count)
+static int txpower_g_write_file(struct b43_wldev *dev,
+				const char *buf, size_t count)
 {
 	unsigned long flags;
 	unsigned long phy_flags;
@@ -262,7 +269,8 @@ out_unlock:
 }
 
 /* wl->irq_lock is locked */
-int restart_write_file(struct b43_wldev *dev, const char *buf, size_t count)
+static int restart_write_file(struct b43_wldev *dev,
+			      const char *buf, size_t count)
 {
 	int err = 0;
 
@@ -294,7 +302,8 @@ static ssize_t append_lo_table(ssize_t c
 	return count;
 }
 
-ssize_t loctls_read_file(struct b43_wldev *dev, char *buf, size_t bufsize)
+static ssize_t loctls_read_file(struct b43_wldev *dev,
+				char *buf, size_t bufsize)
 {
 	ssize_t count = 0;
 	struct b43_txpower_lo_control *lo;
@@ -383,6 +392,8 @@ static ssize_t b43_debugfs_read(struct f
 			err = -ENOMEM;
 			goto out_unlock;
 		}
+		/* Sparse warns about the following memset, because it has a big
+		 * size value. That warning is bogus, so I will ignore it. --mb */
 		memset(buf, 0, bufsize);
 		if (dfops->take_irqlock) {
 			spin_lock_irq(&dev->wl->irq_lock);

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

end of thread, other threads:[~2009-08-18 13:12 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-13 22:15 [PATCH] b43: Fix sparse warnings Larry Finger
2009-08-14 20:15 ` Michael Buesch
2009-08-14 20:52   ` Pavel Roskin
2009-08-14 21:00     ` Michael Buesch
2009-08-14 21:04       ` Gábor Stefanik
2009-08-14 21:35         ` Pavel Roskin
2009-08-15 10:04           ` Michael Buesch
2009-08-17 20:30             ` Pavel Roskin
2009-08-18 13:12               ` Michael Buesch
2009-08-14 21:29       ` Pavel Roskin
2009-08-14 21:46         ` Pavel Roskin
2009-08-15 10:08           ` Michael Buesch
2009-08-14 21:33   ` Larry Finger
  -- strict thread matches above, loose matches on Subject: below --
2007-09-19 16:30 Michael Buesch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).