linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging/wilc1000: fixes kzalloc call
@ 2016-05-27 17:51 Lidza Louina
  2016-05-27 18:07 ` Joe Perches
  0 siblings, 1 reply; 3+ messages in thread
From: Lidza Louina @ 2016-05-27 17:51 UTC (permalink / raw)
  To: johnny.kim, austin.shin, chris.park, tony.cho, glen.lee, leo.kim,
	gregkh, linux-wireless, devel
  Cc: Lidza Louina

The wl pointer was initialized as a pointer to a struct wilc and
assigned to a piece of memory the size of the pointer. It should be the
size of struct wilc.

Signed-off-by: Lidza Louina <lidza.louina@oracle.com>
---
 drivers/staging/wilc1000/linux_wlan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index 4f93c11..d1853f6 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -1260,7 +1260,7 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
 
 	sema_init(&close_exit_sync, 0);
 
-	wl = kzalloc(sizeof(*wl), GFP_KERNEL);
+	wl = kzalloc(sizeof(struct wilc), GFP_KERNEL);
 	if (!wl)
 		return -ENOMEM;
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging/wilc1000: fixes kzalloc call
  2016-05-27 17:51 [PATCH] staging/wilc1000: fixes kzalloc call Lidza Louina
@ 2016-05-27 18:07 ` Joe Perches
  2016-05-27 18:24   ` Lidza Louina
  0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2016-05-27 18:07 UTC (permalink / raw)
  To: Lidza Louina, johnny.kim, austin.shin, chris.park, tony.cho,
	glen.lee, leo.kim, gregkh, linux-wireless, devel

On Fri, 2016-05-27 at 13:51 -0400, Lidza Louina wrote:
> The wl pointer was initialized as a pointer to a struct wilc and
> assigned to a piece of memory the size of the pointer. It should be the
> size of struct wilc.

This isn't necessary.

The code in question is:

	struct wilc *wl;

	sema_init(&close_exit_sync, 0);

	wl = kzalloc(sizeof(*wl), GFP_KERNEL);
	if (!wl)
		return -ENOMEM;

	*wilc = wl;

so this isn't any real change and the generally desired form for
allocations from CodingStyle (Chapter 14: Allocating Memory) is:

The preferred form for passing a size of a struct is the following:	p = kmalloc(sizeof(*p), ...);

> diff --git a/drivers/staging/wilc1000/linux_wlan.c
[]
> @@ -1260,7 +1260,7 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
>  
>  	sema_init(&close_exit_sync, 0);
>  
> -	wl = kzalloc(sizeof(*wl), GFP_KERNEL);
> +	wl = kzalloc(sizeof(struct wilc), GFP_KERNEL);
>  	if (!wl)
>  		return -ENOMEM;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging/wilc1000: fixes kzalloc call
  2016-05-27 18:07 ` Joe Perches
@ 2016-05-27 18:24   ` Lidza Louina
  0 siblings, 0 replies; 3+ messages in thread
From: Lidza Louina @ 2016-05-27 18:24 UTC (permalink / raw)
  To: Joe Perches, johnny.kim, austin.shin, chris.park, tony.cho,
	glen.lee, leo.kim, gregkh, linux-wireless, devel



On 05/27/2016 02:07 PM, Joe Perches wrote:
> On Fri, 2016-05-27 at 13:51 -0400, Lidza Louina wrote:
>> The wl pointer was initialized as a pointer to a struct wilc and
>> assigned to a piece of memory the size of the pointer. It should be the
>> size of struct wilc.
> This isn't necessary.
>
> The code in question is:
>
> 	struct wilc *wl;
>
> 	sema_init(&close_exit_sync, 0);
>
> 	wl = kzalloc(sizeof(*wl), GFP_KERNEL);
> 	if (!wl)
> 		return -ENOMEM;
>
> 	*wilc = wl;
>
> so this isn't any real change and the generally desired form for
> allocations from CodingStyle (Chapter 14: Allocating Memory) is:
>
> The preferred form for passing a size of a struct is the following:	p = kmalloc(sizeof(*p), ...);

Ahh, okay. I see that in the documentation. Thanks.

Lidza

>
>> diff --git a/drivers/staging/wilc1000/linux_wlan.c
> []
>> @@ -1260,7 +1260,7 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
>>   
>>   	sema_init(&close_exit_sync, 0);
>>   
>> -	wl = kzalloc(sizeof(*wl), GFP_KERNEL);
>> +	wl = kzalloc(sizeof(struct wilc), GFP_KERNEL);
>>   	if (!wl)
>>   		return -ENOMEM;


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-05-27 18:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-27 17:51 [PATCH] staging/wilc1000: fixes kzalloc call Lidza Louina
2016-05-27 18:07 ` Joe Perches
2016-05-27 18:24   ` Lidza Louina

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).