diff mbox

mt7601u: remove a warning in mt7601u_efuse_physical_size_check()

Message ID 2850551da4495924bde846dd237b736e41913d0f.1519827461.git.lorenzo.bianconi@redhat.com (mailing list archive)
State Accepted
Commit 3fb2f6a4db98037890c52f12efa5c351a7bf6c77
Delegated to: Kalle Valo
Headers show

Commit Message

Lorenzo Bianconi Feb. 28, 2018, 2:26 p.m. UTC
Fix the following sparse warning in mt7601u_efuse_physical_size_check:
- drivers/net/wireless/mediatek/mt7601u/eeprom.c:77:27: warning:
  Variable length array is used

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
---
 drivers/net/wireless/mediatek/mt7601u/eeprom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Johannes Berg Feb. 28, 2018, 3:06 p.m. UTC | #1
On Wed, 2018-02-28 at 15:26 +0100, Lorenzo Bianconi wrote:
> 
>  	const int map_reads = DIV_ROUND_UP(MT_EFUSE_USAGE_MAP_SIZE, 16);
> -	u8 data[map_reads * 16];
> +	u8 data[round_up(MT_EFUSE_USAGE_MAP_SIZE, 16)];
> 
You could turn it upside down and make 

const int map_reads = ARRAY_SIZE(data);

johannes
Lorenzo Bianconi Feb. 28, 2018, 4:01 p.m. UTC | #2
> On Wed, 2018-02-28 at 15:26 +0100, Lorenzo Bianconi wrote:
>>
>>       const int map_reads = DIV_ROUND_UP(MT_EFUSE_USAGE_MAP_SIZE, 16);
>> -     u8 data[map_reads * 16];
>> +     u8 data[round_up(MT_EFUSE_USAGE_MAP_SIZE, 16)];
>>
> You could turn it upside down and make
>
> const int map_reads = ARRAY_SIZE(data);

map_reads is actually 2 since MT_EFUSE_USAGE_MAP_SIZE is 29. Using
ARRAY_SIZE(data) map_reads will be set to 32

Regards,
Lorenzo

>
> johannes
Johannes Berg Feb. 28, 2018, 4:01 p.m. UTC | #3
On Wed, 2018-02-28 at 17:01 +0100, Lorenzo Bianconi wrote:
> > On Wed, 2018-02-28 at 15:26 +0100, Lorenzo Bianconi wrote:
> > > 
> > >       const int map_reads = DIV_ROUND_UP(MT_EFUSE_USAGE_MAP_SIZE, 16);
> > > -     u8 data[map_reads * 16];
> > > +     u8 data[round_up(MT_EFUSE_USAGE_MAP_SIZE, 16)];
> > > 
> > 
> > You could turn it upside down and make
> > 
> > const int map_reads = ARRAY_SIZE(data);
> 
> map_reads is actually 2 since MT_EFUSE_USAGE_MAP_SIZE is 29. Using
> ARRAY_SIZE(data) map_reads will be set to 32

Oh yeah, good point, sorry.

johannes
Jakub Kicinski Feb. 28, 2018, 7:46 p.m. UTC | #4
On Wed, 28 Feb 2018 15:26:57 +0100, Lorenzo Bianconi wrote:
> Fix the following sparse warning in mt7601u_efuse_physical_size_check:
> - drivers/net/wireless/mediatek/mt7601u/eeprom.c:77:27: warning:
>   Variable length array is used
> 
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>

Acked-by: Jakub Kicinski <kubakici@wp.pl>

Thanks Lorenzo!
Bas Vermeulen March 1, 2018, 10:22 a.m. UTC | #5
On 28-02-18 15:26, Lorenzo Bianconi wrote:
> Fix the following sparse warning in mt7601u_efuse_physical_size_check:
> - drivers/net/wireless/mediatek/mt7601u/eeprom.c:77:27: warning:
>    Variable length array is used
>
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
> ---
>   drivers/net/wireless/mediatek/mt7601u/eeprom.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/wireless/mediatek/mt7601u/eeprom.c b/drivers/net/wireless/mediatek/mt7601u/eeprom.c
> index da6faea092d6..a462064b5c91 100644
> --- a/drivers/net/wireless/mediatek/mt7601u/eeprom.c
> +++ b/drivers/net/wireless/mediatek/mt7601u/eeprom.c
> @@ -74,7 +74,7 @@ static int
>   mt7601u_efuse_physical_size_check(struct mt7601u_dev *dev)
>   {
>   	const int map_reads = DIV_ROUND_UP(MT_EFUSE_USAGE_MAP_SIZE, 16);
> -	u8 data[map_reads * 16];
> +	u8 data[round_up(MT_EFUSE_USAGE_MAP_SIZE, 16)];
Shouldn't this be u8 data[round_up(MT_EFUSE_USAGE_MAP_SIZE,16)*16]; to 
get the
same array size as before?

Bas Vermeulen
Bas Vermeulen March 1, 2018, 10:25 a.m. UTC | #6
Nevermind. round_up instead of DIV_ROUND_UP.

Bas Vermeulen


On 01-03-18 11:22, Bas Vermeulen wrote:
>
>
> On 28-02-18 15:26, Lorenzo Bianconi wrote:
>> Fix the following sparse warning in mt7601u_efuse_physical_size_check:
>> - drivers/net/wireless/mediatek/mt7601u/eeprom.c:77:27: warning:
>>    Variable length array is used
>>
>> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
>> ---
>>   drivers/net/wireless/mediatek/mt7601u/eeprom.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/wireless/mediatek/mt7601u/eeprom.c 
>> b/drivers/net/wireless/mediatek/mt7601u/eeprom.c
>> index da6faea092d6..a462064b5c91 100644
>> --- a/drivers/net/wireless/mediatek/mt7601u/eeprom.c
>> +++ b/drivers/net/wireless/mediatek/mt7601u/eeprom.c
>> @@ -74,7 +74,7 @@ static int
>>   mt7601u_efuse_physical_size_check(struct mt7601u_dev *dev)
>>   {
>>       const int map_reads = DIV_ROUND_UP(MT_EFUSE_USAGE_MAP_SIZE, 16);
>> -    u8 data[map_reads * 16];
>> +    u8 data[round_up(MT_EFUSE_USAGE_MAP_SIZE, 16)];
> Shouldn't this be u8 data[round_up(MT_EFUSE_USAGE_MAP_SIZE,16)*16]; to 
> get the
> same array size as before?
>
> Bas Vermeulen
>
Lorenzo Bianconi March 1, 2018, 10:51 a.m. UTC | #7
> Nevermind. round_up instead of DIV_ROUND_UP.
>
> Bas Vermeulen
>
>
>
> On 01-03-18 11:22, Bas Vermeulen wrote:
>>
>>
>>
>> On 28-02-18 15:26, Lorenzo Bianconi wrote:
>>>
>>> Fix the following sparse warning in mt7601u_efuse_physical_size_check:
>>> - drivers/net/wireless/mediatek/mt7601u/eeprom.c:77:27: warning:
>>>    Variable length array is used
>>>
>>> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
>>> ---
>>>   drivers/net/wireless/mediatek/mt7601u/eeprom.c | 2 +-
>>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/net/wireless/mediatek/mt7601u/eeprom.c
>>> b/drivers/net/wireless/mediatek/mt7601u/eeprom.c
>>> index da6faea092d6..a462064b5c91 100644
>>> --- a/drivers/net/wireless/mediatek/mt7601u/eeprom.c
>>> +++ b/drivers/net/wireless/mediatek/mt7601u/eeprom.c
>>> @@ -74,7 +74,7 @@ static int
>>>   mt7601u_efuse_physical_size_check(struct mt7601u_dev *dev)
>>>   {
>>>       const int map_reads = DIV_ROUND_UP(MT_EFUSE_USAGE_MAP_SIZE, 16);
>>> -    u8 data[map_reads * 16];
>>> +    u8 data[round_up(MT_EFUSE_USAGE_MAP_SIZE, 16)];
>>
>> Shouldn't this be u8 data[round_up(MT_EFUSE_USAGE_MAP_SIZE,16)*16]; to get
>> the
>> same array size as before?
>>
>> Bas Vermeulen
>>

round_up(MT_EFUSE_USAGE_MAP_SIZE, 16) =
(DIV_ROUND_UP(MT_EFUSE_USAGE_MAP_SIZE, 16) * 16) = 32

Regards,
Lorenzo

>
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>
Kalle Valo March 13, 2018, 4:33 p.m. UTC | #8
Lorenzo Bianconi <lorenzo.bianconi@redhat.com> wrote:

> Fix the following sparse warning in mt7601u_efuse_physical_size_check:
> - drivers/net/wireless/mediatek/mt7601u/eeprom.c:77:27: warning:
>   Variable length array is used
> 
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
> Acked-by: Jakub Kicinski <kubakici@wp.pl>

Patch applied to wireless-drivers-next.git, thanks.

3fb2f6a4db98 mt7601u: remove a warning in mt7601u_efuse_physical_size_check()
diff mbox

Patch

diff --git a/drivers/net/wireless/mediatek/mt7601u/eeprom.c b/drivers/net/wireless/mediatek/mt7601u/eeprom.c
index da6faea092d6..a462064b5c91 100644
--- a/drivers/net/wireless/mediatek/mt7601u/eeprom.c
+++ b/drivers/net/wireless/mediatek/mt7601u/eeprom.c
@@ -74,7 +74,7 @@  static int
 mt7601u_efuse_physical_size_check(struct mt7601u_dev *dev)
 {
 	const int map_reads = DIV_ROUND_UP(MT_EFUSE_USAGE_MAP_SIZE, 16);
-	u8 data[map_reads * 16];
+	u8 data[round_up(MT_EFUSE_USAGE_MAP_SIZE, 16)];
 	int ret, i;
 	u32 start = 0, end = 0, cnt_free;