Staging: rtl8192e: Use kzalloc instead of kmalloc and memset
PATCH 1/1 Staging: rtl8192e: Use kzalloc instead of kmalloc and memset
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.
Done using coccinelle:
@@
expression e,e1,e2;
@@
- e=kmalloc(e1,e2);
+ e=kzalloc(e1,e2);
if(!e)
return NULL;
...
- memset(e,...);
--- drivers/staging/rtl8192e/rtllib_tx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/rtl8192e/rtllib_tx.c +1 -2
@@ -221,12 +221,11 @@ static struct rtllib_txb *rtllib_alloc_txb(int nr_frags, int txb_size,struct rtllib_txb *txb;int i; - txb =kmalloc (sizeof (struct rtllib_txb ) + (sizeof (u8 *) * nr_frags), + txb =kzalloc (sizeof (struct rtllib_txb ) + (sizeof (u8 *) * nr_frags), gfp_mask);if (!txb)return NULL ; -memset (txb,0 ,sizeof (struct rtllib_txb )); txb->nr_frags = nr_frags; txb->frag_size =cpu_to_le16 (txb_size);
Signature · 1 line
1.9.1
Quoted 25 lines · 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.
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 <[email protected]>--- drivers/staging/rtl8192e/rtllib_tx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/staging/rtl8192e/rtllib_tx.c +0
-0
drivers/staging/rtl8192e/rtllib_tx.c static struct rtllib_txb *rtllib_alloc_txb(int nr_frags, int txb_size, · line 229
Quoted 10 lines
drivers/staging/rtl8192e/rtllib_tx.c +1
-2@@ -221,12 +221,11 @@ static struct rtllib_txb *rtllib_alloc_txb(int nr_frags, int txb_size,struct rtllib_txb *txb;int i; - txb =kmalloc (sizeof (struct rtllib_txb ) + (sizeof (u8 *) * nr_frags), + txb =kzalloc (sizeof (struct rtllib_txb ) + (sizeof (u8 *) * nr_frags), gfp_mask);if (!txb)return NULL ; -memset (txb,0 ,sizeof (struct rtllib_txb ));
The sizes are not the same. I don't know if this is a performance issue.
julia
Quoted 13 lines
drivers/staging/rtl8192e/rtllib_tx.c +0
-1txb->nr_frags = nr_frags; txb->frag_size =cpu_to_le16 (txb_size); --1.9.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 [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1456844212-29057-1-git-send-email-bhumirks%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Quoted 36 lines · Julia Lawall
Quoted 34 lines · 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.
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 <[email protected]>--- drivers/staging/rtl8192e/rtllib_tx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/staging/rtl8192e/rtllib_tx.c +1
-1@@ -221,12 +221,11 @@ static struct rtllib_txb *rtllib_alloc_txb(int nr_frags, int txb_size,struct rtllib_txb *txb;int i; - txb =kmalloc (sizeof (struct rtllib_txb ) + (sizeof (u8 *) * nr_frags), + txb =kzalloc (sizeof (struct rtllib_txb ) + (sizeof (u8 *) * nr_frags), gfp_mask);if (!txb)return NULL ;
Quoted 4 lines
drivers/staging/rtl8192e/rtllib_tx.c static struct rtllib_txb *rtllib_alloc_txb(int nr_frags, int txb_size, · line 229
Quoted 1 line
drivers/staging/rtl8192e/rtllib_tx.c +0
-1-memset (txb,0 ,sizeof (struct rtllib_txb ));The sizes are not the same. I don't know if this is a performance issue.
By sizes do you mean the size of memory allocated by kmalloc and kzalloc? I think this won't be an issue when the second argument is GFP_KERNEL.
Thanks,
Bhumika
Quoted 15 lines
julia
Quoted 13 lines
drivers/staging/rtl8192e/rtllib_tx.c +0
-1txb->nr_frags = nr_frags; txb->frag_size =cpu_to_le16 (txb_size); --1.9.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 [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1456844212-29057-1-git-send-email-bhumirks%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Quoted 37 lines · Bhumika Goyal
Quoted 36 lines · Julia Lawall
Quoted 34 lines · 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.
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 <[email protected]>--- drivers/staging/rtl8192e/rtllib_tx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/staging/rtl8192e/rtllib_tx.c +1
-1@@ -221,12 +221,11 @@ static struct rtllib_txb *rtllib_alloc_txb(int nr_frags, int txb_size,struct rtllib_txb *txb;int i; - txb =kmalloc (sizeof (struct rtllib_txb ) + (sizeof (u8 *) * nr_frags), + txb =kzalloc (sizeof (struct rtllib_txb ) + (sizeof (u8 *) * nr_frags), gfp_mask);if (!txb)return NULL ;
Quoted 8 lines
Quoted 4 lines
drivers/staging/rtl8192e/rtllib_tx.c static struct rtllib_txb *rtllib_alloc_txb(int nr_frags, int txb_size, · line 229
Quoted 1 line
drivers/staging/rtl8192e/rtllib_tx.c +0
-1-memset (txb,0 ,sizeof (struct rtllib_txb ));The sizes are not the same. I don't know if this is a performance issue.
By sizes do you mean the size of memory allocated by kmalloc and kzalloc? I think this won't be an issue when the second argument is
GFP_KERNEL.
The size that is allocated is A + B.
The size that is zeroed is only A.
In your code, the size that is zeroed is A + B. Since B contains a multiplication, that might be much bigger. In at least some contexts zeroing takes time.
julia
Quoted 26 lines
Thanks,
BhumikaQuoted 15 lines
julia
Quoted 13 lines
drivers/staging/rtl8192e/rtllib_tx.c +0
-1txb->nr_frags = nr_frags; txb->frag_size =cpu_to_le16 (txb_size); --1.9.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 [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1456844212-29057-1-git-send-email-bhumirks%40gmail.com.
For more options, visit https://groups.google.com/d/optout.--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/CAOH%2B1jG58L8Mjg2bO3t48bMoCJgR0%3DDi-sbHi0vj7DCWqOBbqw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Quoted 50 lines · Julia Lawall
Quoted 37 lines · Bhumika Goyal
Quoted 36 lines · Julia Lawall
Quoted 34 lines · 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.
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 <[email protected]>--- drivers/staging/rtl8192e/rtllib_tx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/staging/rtl8192e/rtllib_tx.c +1
-1@@ -221,12 +221,11 @@ static struct rtllib_txb *rtllib_alloc_txb(int nr_frags, int txb_size,struct rtllib_txb *txb;int i; - txb =kmalloc (sizeof (struct rtllib_txb ) + (sizeof (u8 *) * nr_frags), + txb =kzalloc (sizeof (struct rtllib_txb ) + (sizeof (u8 *) * nr_frags), gfp_mask);if (!txb)return NULL ;Quoted 8 lines
Quoted 4 lines
drivers/staging/rtl8192e/rtllib_tx.c static struct rtllib_txb *rtllib_alloc_txb(int nr_frags, int txb_size, · line 229
Quoted 1 line
drivers/staging/rtl8192e/rtllib_tx.c +0
-1-memset (txb,0 ,sizeof (struct rtllib_txb ));The sizes are not the same. I don't know if this is a performance issue.
By sizes do you mean the size of memory allocated by kmalloc and kzalloc? I think this won't be an issue when the second argument is
GFP_KERNEL.
Quoted 9 lines
The size that is allocated is A + B.
The size that is zeroed is only A.In your code, the size that is zeroed is A + B. Since B contains a multiplication, that might be much bigger. In at least some contexts zeroing takes time.
julia
Thanks for explaining. I will find issues where the size allocated and zeroed is only A .
Thanks,
Bhumika
Quoted 26 lines
Quoted 26 lines
Thanks,
BhumikaQuoted 15 lines
julia
Quoted 13 lines
drivers/staging/rtl8192e/rtllib_tx.c +0
-1txb->nr_frags = nr_frags; txb->frag_size =cpu_to_le16 (txb_size); --1.9.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 [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1456844212-29057-1-git-send-email-bhumirks%40gmail.com.
For more options, visit https://groups.google.com/d/optout.--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/CAOH%2B1jG58L8Mjg2bO3t48bMoCJgR0%3DDi-sbHi0vj7DCWqOBbqw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Quoted 58 lines · Bhumika Goyal
Quoted 57 lines · Julia Lawall
Quoted 37 lines · Bhumika Goyal
Quoted 36 lines · Julia Lawall
Quoted 34 lines · 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.
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 <[email protected]>--- drivers/staging/rtl8192e/rtllib_tx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/staging/rtl8192e/rtllib_tx.c +1
-1@@ -221,12 +221,11 @@ static struct rtllib_txb *rtllib_alloc_txb(int nr_frags, int txb_size,struct rtllib_txb *txb;int i; - txb =kmalloc (sizeof (struct rtllib_txb ) + (sizeof (u8 *) * nr_frags), + txb =kzalloc (sizeof (struct rtllib_txb ) + (sizeof (u8 *) * nr_frags), gfp_mask);if (!txb)return NULL ;Quoted 8 lines
Quoted 4 lines
drivers/staging/rtl8192e/rtllib_tx.c static struct rtllib_txb *rtllib_alloc_txb(int nr_frags, int txb_size, · line 229
Quoted 1 line
drivers/staging/rtl8192e/rtllib_tx.c +0
-1-memset (txb,0 ,sizeof (struct rtllib_txb ));The sizes are not the same. I don't know if this is a performance issue.
By sizes do you mean the size of memory allocated by kmalloc and kzalloc? I think this won't be an issue when the second argument is
GFP_KERNEL.The size that is allocated is A + B.
The size that is zeroed is only A.In your code, the size that is zeroed is A + B. Since B contains a multiplication, that might be much bigger. In at least some contexts zeroing takes time.
Quoted 5 lines
Quoted 2 lines
julia
Thanks for explaining. I will find issues where the size allocated and zeroed is only A .
I'm not sure that there is anything to do here. It s perfectly legitimate to zero less than the full allocated data, as long as no fields of the allocated data are then used uninitialized.
julia
Quoted 37 lines
Thanks,
BhumikaQuoted 19 lines
Quoted 19 lines
Thanks,
BhumikaQuoted 15 lines
julia
Quoted 13 lines
drivers/staging/rtl8192e/rtllib_tx.c +0
-1txb->nr_frags = nr_frags; txb->frag_size =cpu_to_le16 (txb_size); --1.9.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 [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1456844212-29057-1-git-send-email-bhumirks%40gmail.com.
For more options, visit https://groups.google.com/d/optout.Quoted 7 lines
Quoted 7 lines
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/CAOH%2B1jG58L8Mjg2bO3t48bMoCJgR0%3DDi-sbHi0vj7DCWqOBbqw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/CAOH%2B1jEACWU7f8PkFp0vpagn4NiEFygp7BgBcd6zjLSG0gBemw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.