2022-06-22 15:34:03

by Felix Schlepper

[permalink] [raw]
Subject: [PATCH v3 2/3] Staging: rtl8192e: Using kzalloc and delete memset

By using kzalloc, we can delete a memset and avoid
memory initialization defects.

Signed-off-by: Felix Schlepper <[email protected]>
---
drivers/staging/rtl8192e/rtllib_tx.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8192e/rtllib_tx.c b/drivers/staging/rtl8192e/rtllib_tx.c
index f2ef32e943ae..1307cf55741a 100644
--- a/drivers/staging/rtl8192e/rtllib_tx.c
+++ b/drivers/staging/rtl8192e/rtllib_tx.c
@@ -205,11 +205,10 @@ static struct rtllib_txb *rtllib_alloc_txb(int nr_frags, int txb_size,
struct rtllib_txb *txb;
int i;

- txb = kmalloc(struct_size(txb, fragments, nr_frags), gfp_mask);
+ txb = kzalloc(struct_size(txb, fragments, 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);

--
2.36.1


2022-06-23 07:30:20

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH v3 2/3] Staging: rtl8192e: Using kzalloc and delete memset

On Wed, Jun 22, 2022 at 05:12:45PM +0200, Felix Schlepper wrote:
> By using kzalloc, we can delete a memset and avoid
> memory initialization defects.
>

This commit message is slightly confusing. The "avoid memory
initialization defects" bit is very vague.

The difference between the original code and patched code is that the
patched code zeroes out the txb->fragments[] array. The original code
worked. The new code is slightly cleaner, but also slower. Whatever,
either way is fine.

But just state it clearly in the commit message.

"By using kzalloc, we can delete a memset. The practical difference
is that using kzalloc() will zero out the txb->fragments[] array.
The original code worked fine, but zeroing everything seems nicer."

regards,
dan carpenter