2013-02-06 16:23:54

by Cong Ding

[permalink] [raw]
Subject: [PATCH] net: mac80211/cfg.c: fix error using of sizeof()

Using 'sizeof' on array given as function argument returns size of a pointer
rather than the size of array.

Signed-off-by: Cong Ding <[email protected]>
---
net/mac80211/cfg.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 661b878..af561d5 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -2058,7 +2058,8 @@ static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
{
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);

- memcpy(sdata->vif.bss_conf.mcast_rate, rate, sizeof(rate));
+ memcpy(sdata->vif.bss_conf.mcast_rate, rate,
+ sizeof(int) * IEEE80211_NUM_BANDS);

return 0;
}
--
1.7.9.5



2013-02-06 17:59:55

by Ben Greear

[permalink] [raw]
Subject: Re: [PATCH] net: mac80211/cfg.c: fix error using of sizeof()

On 02/06/2013 09:54 AM, Ben Greear wrote:
> On 02/06/2013 08:27 AM, Johannes Berg wrote:
>> On Wed, 2013-02-06 at 17:23 +0100, Cong Ding wrote:
>>> Using 'sizeof' on array given as function argument returns size of a pointer
>>> rather than the size of array.
>>
>> Oops, yeah, Stephen Hemminger pointed this out a month or so ago and I
>> forgot to change it, thanks.
>
> This needs to be back-ported for 3.7 stable? Perhaps the code below
> corresponds (from copy_mesh_setup)?
>
>
> /* mcast rate setting in Mesh Node */
> memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
> sizeof(setup->mcast_rate));

Nevermind..I think I'm wrong about that..the sizeof probably works fine
here. Sorry for the noise.

Ben

>
> Thanks,
> Ben
>


--
Ben Greear <[email protected]>
Candela Technologies Inc http://www.candelatech.com


2013-02-06 18:33:09

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] net: mac80211/cfg.c: fix error using of sizeof()

From: Cong Ding <[email protected]>
Date: Wed, 6 Feb 2013 17:23:45 +0100

> Using 'sizeof' on array given as function argument returns size of a pointer
> rather than the size of array.
>
> Signed-off-by: Cong Ding <[email protected]>
> ---
> net/mac80211/cfg.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
> index 661b878..af561d5 100644
> --- a/net/mac80211/cfg.c
> +++ b/net/mac80211/cfg.c
> @@ -2058,7 +2058,8 @@ static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
> {
> struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
>
> - memcpy(sdata->vif.bss_conf.mcast_rate, rate, sizeof(rate));
> + memcpy(sdata->vif.bss_conf.mcast_rate, rate,
> + sizeof(int) * IEEE80211_NUM_BANDS);
>

This is not indented properly. The "sizeof(int..." should start at the
first column after the openning parenthesis of the memcpy() call.

2013-02-06 17:58:28

by Ben Greear

[permalink] [raw]
Subject: Re: [PATCH] net: mac80211/cfg.c: fix error using of sizeof()

On 02/06/2013 08:23 AM, Cong Ding wrote:
> Using 'sizeof' on array given as function argument returns size of a pointer
> rather than the size of array.
>
> Signed-off-by: Cong Ding <[email protected]>
> ---
> net/mac80211/cfg.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
> index 661b878..af561d5 100644
> --- a/net/mac80211/cfg.c
> +++ b/net/mac80211/cfg.c
> @@ -2058,7 +2058,8 @@ static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
> {
> struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
>
> - memcpy(sdata->vif.bss_conf.mcast_rate, rate, sizeof(rate));
> + memcpy(sdata->vif.bss_conf.mcast_rate, rate,
> + sizeof(int) * IEEE80211_NUM_BANDS);

Should it perhaps be: sizeof(*rate) * IEEE80211_NUM_BANDS
just in case the type ever changes?

Thanks,
Ben

>
> return 0;
> }
>


--
Ben Greear <[email protected]>
Candela Technologies Inc http://www.candelatech.com


2013-02-06 19:28:17

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH] net: mac80211/cfg.c: fix error using of sizeof()

On Wed, 2013-02-06 at 13:33 -0500, David Miller wrote:
> From: Cong Ding <[email protected]>
> Date: Wed, 6 Feb 2013 17:23:45 +0100
>
> > Using 'sizeof' on array given as function argument returns size of a pointer
> > rather than the size of array.
> >
> > Signed-off-by: Cong Ding <[email protected]>
> > ---
> > net/mac80211/cfg.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
> > index 661b878..af561d5 100644
> > --- a/net/mac80211/cfg.c
> > +++ b/net/mac80211/cfg.c
> > @@ -2058,7 +2058,8 @@ static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
> > {
> > struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
> >
> > - memcpy(sdata->vif.bss_conf.mcast_rate, rate, sizeof(rate));
> > + memcpy(sdata->vif.bss_conf.mcast_rate, rate,
> > + sizeof(int) * IEEE80211_NUM_BANDS);
> >
>
> This is not indented properly. The "sizeof(int..." should start at the
> first column after the openning parenthesis of the memcpy() call.

Yeah I fixed it when I applied it ... oh well.

johannes



2013-02-06 17:55:00

by Ben Greear

[permalink] [raw]
Subject: Re: [PATCH] net: mac80211/cfg.c: fix error using of sizeof()

On 02/06/2013 08:27 AM, Johannes Berg wrote:
> On Wed, 2013-02-06 at 17:23 +0100, Cong Ding wrote:
>> Using 'sizeof' on array given as function argument returns size of a pointer
>> rather than the size of array.
>
> Oops, yeah, Stephen Hemminger pointed this out a month or so ago and I
> forgot to change it, thanks.

This needs to be back-ported for 3.7 stable? Perhaps the code below
corresponds (from copy_mesh_setup)?


/* mcast rate setting in Mesh Node */
memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
sizeof(setup->mcast_rate));

Thanks,
Ben

--
Ben Greear <[email protected]>
Candela Technologies Inc http://www.candelatech.com


2013-02-06 16:26:47

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH] net: mac80211/cfg.c: fix error using of sizeof()

On Wed, 2013-02-06 at 17:23 +0100, Cong Ding wrote:
> Using 'sizeof' on array given as function argument returns size of a pointer
> rather than the size of array.

Oops, yeah, Stephen Hemminger pointed this out a month or so ago and I
forgot to change it, thanks.

johannes