* [PATCH] mac80211: correct size the argument to kzalloc in minstrel_ht
@ 2012-06-28 23:28 Thomas Huehn
2012-06-29 1:04 ` Julian Calaby
0 siblings, 1 reply; 5+ messages in thread
From: Thomas Huehn @ 2012-06-28 23:28 UTC (permalink / raw)
To: linux-wireless; +Cc: johannes, thomas, nbd
msp has type struct minstrel_ht_sta_priv not struct minstrel_ht_sta.
Signed-off-by: Thomas Huehn <thomas@net.t-labs.tu-berlin.de>
---
net/mac80211/rc80211_minstrel_ht.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/mac80211/rc80211_minstrel_ht.c b/net/mac80211/rc80211_minstrel_ht.c
index 2d1acc6..dc2b801 100644
--- a/net/mac80211/rc80211_minstrel_ht.c
+++ b/net/mac80211/rc80211_minstrel_ht.c
@@ -809,7 +809,7 @@ minstrel_ht_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
max_rates = sband->n_bitrates;
}
- msp = kzalloc(sizeof(struct minstrel_ht_sta), gfp);
+ msp = kzalloc(sizeof(struct minstrel_ht_sta_priv), gfp);
if (!msp)
return NULL;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] mac80211: correct size the argument to kzalloc in minstrel_ht
2012-06-28 23:28 [PATCH] mac80211: correct size the argument to kzalloc in minstrel_ht Thomas Huehn
@ 2012-06-29 1:04 ` Julian Calaby
2012-06-29 5:00 ` thomas
0 siblings, 1 reply; 5+ messages in thread
From: Julian Calaby @ 2012-06-29 1:04 UTC (permalink / raw)
To: Thomas Huehn; +Cc: linux-wireless, johannes, nbd
Hi Thomas,
On Fri, Jun 29, 2012 at 9:28 AM, Thomas Huehn
<thomas@net.t-labs.tu-berlin.de> wrote:
> msp has type struct minstrel_ht_sta_priv not struct minstrel_ht_sta.
>
> Signed-off-by: Thomas Huehn <thomas@net.t-labs.tu-berlin.de>
> ---
> net/mac80211/rc80211_minstrel_ht.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/mac80211/rc80211_minstrel_ht.c b/net/mac80211/rc80211_minstrel_ht.c
> index 2d1acc6..dc2b801 100644
> --- a/net/mac80211/rc80211_minstrel_ht.c
> +++ b/net/mac80211/rc80211_minstrel_ht.c
> @@ -809,7 +809,7 @@ minstrel_ht_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
> max_rates = sband->n_bitrates;
> }
>
> - msp = kzalloc(sizeof(struct minstrel_ht_sta), gfp);
> + msp = kzalloc(sizeof(struct minstrel_ht_sta_priv), gfp);
Why not use sizeof(*msp)?
Thanks,
--
Julian Calaby
Email: julian.calaby@gmail.com
Profile: http://www.google.com/profiles/julian.calaby/
.Plan: http://sites.google.com/site/juliancalaby/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mac80211: correct size the argument to kzalloc in minstrel_ht
2012-06-29 1:04 ` Julian Calaby
@ 2012-06-29 5:00 ` thomas
2012-06-29 7:50 ` Schrober
0 siblings, 1 reply; 5+ messages in thread
From: thomas @ 2012-06-29 5:00 UTC (permalink / raw)
To: Julian Calaby; +Cc: linux-wireless, johannes, nbd
Hi Julian,
Compiler wise both of our suggestions will lead to the same machine code.
So beside the matter of taste, I just followed the other overall usage
pattern of kzalloc in minstrel_ht.
And it seems to be explicitly using the struct type.
Bye Thomas
Julian Calaby schrieb:
> Hi Thomas,
>
> On Fri, Jun 29, 2012 at 9:28 AM, Thomas Huehn
> <thomas@net.t-labs.tu-berlin.de> wrote:
>> msp has type struct minstrel_ht_sta_priv not struct minstrel_ht_sta.
>>
>> Signed-off-by: Thomas Huehn <thomas@net.t-labs.tu-berlin.de>
>> ---
>> net/mac80211/rc80211_minstrel_ht.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/net/mac80211/rc80211_minstrel_ht.c b/net/mac80211/rc80211_minstrel_ht.c
>> index 2d1acc6..dc2b801 100644
>> --- a/net/mac80211/rc80211_minstrel_ht.c
>> +++ b/net/mac80211/rc80211_minstrel_ht.c
>> @@ -809,7 +809,7 @@ minstrel_ht_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
>> max_rates = sband->n_bitrates;
>> }
>>
>> - msp = kzalloc(sizeof(struct minstrel_ht_sta), gfp);
>> + msp = kzalloc(sizeof(struct minstrel_ht_sta_priv), gfp);
>
> Why not use sizeof(*msp)?
>
> Thanks,
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mac80211: correct size the argument to kzalloc in minstrel_ht
2012-06-29 5:00 ` thomas
@ 2012-06-29 7:50 ` Schrober
2012-06-29 13:15 ` thomas
0 siblings, 1 reply; 5+ messages in thread
From: Schrober @ 2012-06-29 7:50 UTC (permalink / raw)
To: thomas; +Cc: Julian Calaby, linux-wireless, johannes, nbd
On Thursday 28 June 2012 22:00:41 thomas wrote:
> Hi Julian,
>
> Compiler wise both of our suggestions will lead to the same machine code.
> So beside the matter of taste, I just followed the other overall usage
> pattern of kzalloc in minstrel_ht.
> And it seems to be explicitly using the struct type.
http://lxr.linux.no/linux/Documentation/CodingStyle
Chapter 14: Allocating memory
The kernel provides the following general purpose memory allocators:
kmalloc(), kzalloc(), kcalloc(), vmalloc(), and vzalloc(). Please refer to
the API documentation for further information about them.
The preferred form for passing a size of a struct is the following:
p = kmalloc(sizeof(*p), ...);
The alternative form where struct name is spelled out hurts readability and
introduces an opportunity for a bug when the pointer variable type is changed
but the corresponding sizeof that is passed to a memory allocator is not.
Casting the return value which is a void pointer is redundant. The conversion
from void pointer to any other pointer type is guaranteed by the C programming
language.
--
Franz Schrober
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] mac80211: correct size the argument to kzalloc in minstrel_ht
2012-06-29 7:50 ` Schrober
@ 2012-06-29 13:15 ` thomas
0 siblings, 0 replies; 5+ messages in thread
From: thomas @ 2012-06-29 13:15 UTC (permalink / raw)
To: Schrober; +Cc: Julian Calaby, linux-wireless, johannes, nbd
Schrober schrieb:
> On Thursday 28 June 2012 22:00:41 thomas wrote:
>> Hi Julian,
>>
>> Compiler wise both of our suggestions will lead to the same machine code.
>> So beside the matter of taste, I just followed the other overall usage
>> pattern of kzalloc in minstrel_ht.
>> And it seems to be explicitly using the struct type.
>
> http://lxr.linux.no/linux/Documentation/CodingStyle
>
> Chapter 14: Allocating memory
>
> The kernel provides the following general purpose memory allocators:
> kmalloc(), kzalloc(), kcalloc(), vmalloc(), and vzalloc(). Please refer to
> the API documentation for further information about them.
>
> The preferred form for passing a size of a struct is the following:
>
> p = kmalloc(sizeof(*p), ...);
>
> The alternative form where struct name is spelled out hurts readability and
> introduces an opportunity for a bug when the pointer variable type is changed
> but the corresponding sizeof that is passed to a memory allocator is not.
>
> Casting the return value which is a void pointer is redundant. The conversion
> from void pointer to any other pointer type is guaranteed by the C programming
> language.
Good to have this clarified. I will send a version 2.
Thx Thomas
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-06-29 13:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-28 23:28 [PATCH] mac80211: correct size the argument to kzalloc in minstrel_ht Thomas Huehn
2012-06-29 1:04 ` Julian Calaby
2012-06-29 5:00 ` thomas
2012-06-29 7:50 ` Schrober
2012-06-29 13:15 ` thomas
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).