driverdev-devel.linuxdriverproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] staging: rtl8192u: ieee80211: replace kmalloc/memset with kzalloc
@ 2020-10-25 17:54 Elena Afanasova
  2020-10-25 18:30 ` [Outreachy kernel] " Julia Lawall
  2020-10-26  9:43 ` Dan Carpenter
  0 siblings, 2 replies; 3+ messages in thread
From: Elena Afanasova @ 2020-10-25 17:54 UTC (permalink / raw)
  To: gregkh; +Cc: devel, outreachy-kernel

Replace kmalloc + memset 0 by a call to kzalloc which zeroes memory too.
Found with Coccinelle.

Signed-off-by: Elena Afanasova <eafanasova@gmail.com>
---
Changes in v3:
        - use array_size()
Changes in v2:
        - correct the subject line
        - correct the commit message

 drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
index 63a561ab4a76..53ce97aae206 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
@@ -227,13 +227,10 @@ 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) + array_size(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 = __cpu_to_le16(txb_size);
 
-- 
2.25.1


_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [Outreachy kernel] [PATCH v3] staging: rtl8192u: ieee80211: replace kmalloc/memset with kzalloc
  2020-10-25 17:54 [PATCH v3] staging: rtl8192u: ieee80211: replace kmalloc/memset with kzalloc Elena Afanasova
@ 2020-10-25 18:30 ` Julia Lawall
  2020-10-26  9:43 ` Dan Carpenter
  1 sibling, 0 replies; 3+ messages in thread
From: Julia Lawall @ 2020-10-25 18:30 UTC (permalink / raw)
  To: Elena Afanasova; +Cc: devel, gregkh, outreachy-kernel



On Sun, 25 Oct 2020, Elena Afanasova wrote:

> Replace kmalloc + memset 0 by a call to kzalloc which zeroes memory too.
> Found with Coccinelle.
>
> Signed-off-by: Elena Afanasova <eafanasova@gmail.com>
> ---
> Changes in v3:
>         - use array_size()
> Changes in v2:
>         - correct the subject line
>         - correct the commit message
>
>  drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
> index 63a561ab4a76..53ce97aae206 100644
> --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
> +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
> @@ -227,13 +227,10 @@ 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) + array_size(sizeof(u8 *), nr_frags), gfp_mask);

There is no need to exceed 80 characters here.

julia

>  	if (!txb)
>  		return NULL;
>
> -	memset(txb, 0, sizeof(struct ieee80211_txb));
>  	txb->nr_frags = nr_frags;
>  	txb->frag_size = __cpu_to_le16(txb_size);
>
> --
> 2.25.1
>
>
> --
> You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/43e637becf35f98a952c38ee1a5b690798c62c75.camel%40gmail.com.
>
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [PATCH v3] staging: rtl8192u: ieee80211: replace kmalloc/memset with kzalloc
  2020-10-25 17:54 [PATCH v3] staging: rtl8192u: ieee80211: replace kmalloc/memset with kzalloc Elena Afanasova
  2020-10-25 18:30 ` [Outreachy kernel] " Julia Lawall
@ 2020-10-26  9:43 ` Dan Carpenter
  1 sibling, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2020-10-26  9:43 UTC (permalink / raw)
  To: Elena Afanasova; +Cc: devel, gregkh, outreachy-kernel

On Sun, Oct 25, 2020 at 10:54:31AM -0700, Elena Afanasova wrote:
> Replace kmalloc + memset 0 by a call to kzalloc which zeroes memory too.
> Found with Coccinelle.
> 
> Signed-off-by: Elena Afanasova <eafanasova@gmail.com>
> ---
> Changes in v3:
>         - use array_size()

struct_size() is more correct than array_size().  If there were really
a danger from array overflows then array_size() would not prevent it
100%.

There should probably be a static checker warning for when people do
"expr + array_size()".  If you're looking for something to write, that's
an idea you could implement with Coccinelle or Smatch.

regards,
dan carpenter


_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

end of thread, other threads:[~2020-10-26  9:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-25 17:54 [PATCH v3] staging: rtl8192u: ieee80211: replace kmalloc/memset with kzalloc Elena Afanasova
2020-10-25 18:30 ` [Outreachy kernel] " Julia Lawall
2020-10-26  9:43 ` Dan Carpenter

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