msp has type struct minstrel_ht_sta_priv not struct minstrel_ht_sta.
Signed-off-by: Thomas Huehn <[email protected]>
---
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
Hi Thomas,
On Fri, Jun 29, 2012 at 9:28 AM, Thomas Huehn
<[email protected]> wrote:
> msp has type struct minstrel_ht_sta_priv not struct minstrel_ht_sta.
>
> Signed-off-by: Thomas Huehn <[email protected]>
> ---
> ?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: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
.Plan: http://sites.google.com/site/juliancalaby/
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
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
> <[email protected]> wrote:
>> msp has type struct minstrel_ht_sta_priv not struct minstrel_ht_sta.
>>
>> Signed-off-by: Thomas Huehn <[email protected]>
>> ---
>> 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,
>
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