2017-02-10 15:07:28

by Franck Demathieu

[permalink] [raw]
Subject: [PATCH] staging: wilc1000: remove unnecessary local array

It fixes the following warning reported by sparse:

drivers/staging/wilc1000/linux_wlan.c:67:33: warning: too long initializer-string for array of char(no space for nul char)

Signed-off-by: Franck Demathieu <[email protected]>
---
drivers/staging/wilc1000/linux_wlan.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index 2eebc62..fc61f4e 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -64,7 +64,6 @@ static int dev_state_ev_handler(struct notifier_block *this,
u8 *ip_addr_buf;
struct wilc_vif *vif;
u8 null_ip[4] = {0};
- char wlan_dev_name[5] = "wlan0";

if (!dev_iface || !dev_iface->ifa_dev || !dev_iface->ifa_dev->dev)
return NOTIFY_DONE;
@@ -113,7 +112,7 @@ static int dev_state_ev_handler(struct notifier_block *this,
wilc_optaining_ip = false;
}

- if (memcmp(dev_iface->ifa_label, wlan_dev_name, 5) == 0)
+ if (memcmp(dev_iface->ifa_label, "wlan0", 5) == 0)
wilc_set_power_mgmt(vif, 0, 0);

wilc_resolve_disconnect_aberration(vif);
--
2.10.1


2017-02-10 20:23:19

by Arend Van Spriel

[permalink] [raw]
Subject: Re: [PATCH] staging: wilc1000: remove unnecessary local array

On 10-2-2017 16:06, Franck Demathieu wrote:
> It fixes the following warning reported by sparse:
>
> drivers/staging/wilc1000/linux_wlan.c:67:33: warning: too long initializer-string for array of char(no space for nul char)

As this was already submitted this should probably say [PATCH V2] in the
subject.
> Signed-off-by: Franck Demathieu <[email protected]>
> ---

And put a change log here, ie.:

V2:
- add [email protected]
---
> drivers/staging/wilc1000/linux_wlan.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
> index 2eebc62..fc61f4e 100644
> --- a/drivers/staging/wilc1000/linux_wlan.c
> +++ b/drivers/staging/wilc1000/linux_wlan.c
> @@ -64,7 +64,6 @@ static int dev_state_ev_handler(struct notifier_block *this,
> u8 *ip_addr_buf;
> struct wilc_vif *vif;
> u8 null_ip[4] = {0};
> - char wlan_dev_name[5] = "wlan0";

You could have changed it to 'const char dev_name[] = "wlan0";'.

> if (!dev_iface || !dev_iface->ifa_dev || !dev_iface->ifa_dev->dev)
> return NOTIFY_DONE;
> @@ -113,7 +112,7 @@ static int dev_state_ev_handler(struct notifier_block *this,
> wilc_optaining_ip = false;
> }
>
> - if (memcmp(dev_iface->ifa_label, wlan_dev_name, 5) == 0)
> + if (memcmp(dev_iface->ifa_label, "wlan0", 5) == 0)

First of all. Why using a memcmp here? dev_iface->ifa_label could be
shorter. Also using the value '5' here is tricky. So it would be better
to say:

if (strlen(dev_iface->ifa_label) == strlen(dev_name) &&
memcmp(dev_iface->ifa_label,
dev_name, strlen(dev_name)) == 0)
> wilc_set_power_mgmt(vif, 0, 0);

However, it does not make sense at all to compare with wlan0 in the
first place. The net_device is registered in wilc_netdev_init() with
"wlan%d" as it should so there is no guarantee it is wlan0.

Regards,
Arend