All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Staging: rtl8192u: Use kzalloc instead of kmalloc and memset
@ 2016-03-01 14:55 Bhumika Goyal
  2016-03-11 18:01 ` [Outreachy kernel] " Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Bhumika Goyal @ 2016-03-01 14:55 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Bhumika Goyal

The code in this patch allocates some memory and then clears it. The
function kzalloc does the both so replace kmalloc and memset with
kzalloc. Also sizeof(struct ieee80211_txb) can be written as
sizeof(*txb) as txb is a pointer of type struct ieee80211_txb.
Done using coccinelle:

@@
expression e,e1,e2;
@@
- e=kmalloc(e1,e2);
+ e=kzalloc(e1,e2);
if(!e)
  return NULL;
...
- memset(e,...);

Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
---
 drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
index 1ab0aea..8662137 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
@@ -242,13 +242,11 @@ static struct ieee80211_txb *ieee80211_alloc_txb(int nr_frags, int txb_size,
 {
 	struct ieee80211_txb *txb;
 	int i;
-	txb = kmalloc(
-		sizeof(struct ieee80211_txb) + (sizeof(u8 *) * nr_frags),
-		gfp_mask);
+	txb = kzalloc(sizeof(*txb) + (sizeof(u8 *) * nr_frags),
+		      gfp_mask);
 	if (!txb)
 		return NULL;
 
-	memset(txb, 0, sizeof(struct ieee80211_txb));
 	txb->nr_frags = nr_frags;
 	txb->frag_size = txb_size;
 
-- 
1.9.1



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

* Re: [Outreachy kernel] [PATCH] Staging: rtl8192u: Use kzalloc instead of kmalloc and memset
  2016-03-01 14:55 [PATCH] Staging: rtl8192u: Use kzalloc instead of kmalloc and memset Bhumika Goyal
@ 2016-03-11 18:01 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2016-03-11 18:01 UTC (permalink / raw)
  To: Bhumika Goyal; +Cc: outreachy-kernel

On Tue, Mar 01, 2016 at 08:25:39PM +0530, Bhumika Goyal wrote:
> The code in this patch allocates some memory and then clears it. The
> function kzalloc does the both so replace kmalloc and memset with
> kzalloc. Also sizeof(struct ieee80211_txb) can be written as
> sizeof(*txb) as txb is a pointer of type struct ieee80211_txb.
> Done using coccinelle:
> 
> @@
> expression e,e1,e2;
> @@
> - e=kmalloc(e1,e2);
> + e=kzalloc(e1,e2);
> if(!e)
>   return NULL;
> ...
> - memset(e,...);
> 
> Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
> ---
>  drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
> index 1ab0aea..8662137 100644
> --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
> +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
> @@ -242,13 +242,11 @@ static struct ieee80211_txb *ieee80211_alloc_txb(int nr_frags, int txb_size,
>  {
>  	struct ieee80211_txb *txb;
>  	int i;
> -	txb = kmalloc(
> -		sizeof(struct ieee80211_txb) + (sizeof(u8 *) * nr_frags),
> -		gfp_mask);
> +	txb = kzalloc(sizeof(*txb) + (sizeof(u8 *) * nr_frags),
> +		      gfp_mask);

This no longer needs to be line-wrapped, right?

Please fix.

thanks,

greg k-h


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

end of thread, other threads:[~2016-03-11 18:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-01 14:55 [PATCH] Staging: rtl8192u: Use kzalloc instead of kmalloc and memset Bhumika Goyal
2016-03-11 18:01 ` [Outreachy kernel] " Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.