X-GM-THRID: 6257098330259587072 X-Received: by 10.194.24.233 with SMTP id x9mr2446855wjf.0.1456845455435; Tue, 01 Mar 2016 07:17:35 -0800 (PST) X-BeenThere: outreachy-kernel@googlegroups.com Received: by 10.28.131.145 with SMTP id f139ls178818wmd.51.canary; Tue, 01 Mar 2016 07:17:34 -0800 (PST) X-Received: by 10.28.85.137 with SMTP id j131mr571415wmb.1.1456845454837; Tue, 01 Mar 2016 07:17:34 -0800 (PST) Return-Path: Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr. [192.134.164.104]) by gmr-mx.google.com with ESMTPS id e130si715247wme.2.2016.03.01.07.17.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Mar 2016 07:17:34 -0800 (PST) Received-SPF: neutral (google.com: 192.134.164.104 is neither permitted nor denied by domain of julia.lawall@lip6.fr) client-ip=192.134.164.104; Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 192.134.164.104 is neither permitted nor denied by domain of julia.lawall@lip6.fr) smtp.mailfrom=julia.lawall@lip6.fr X-IronPort-AV: E=Sophos;i="5.22,523,1449529200"; d="scan'208";a="166511672" Received: from vaio-julia.rsr.lip6.fr ([132.227.76.33]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 01 Mar 2016 16:17:34 +0100 Date: Tue, 1 Mar 2016 16:17:28 +0100 (CET) From: Julia Lawall X-X-Sender: jll@hadrien To: Bhumika Goyal cc: outreachy-kernel@googlegroups.com Subject: Re: [Outreachy kernel] [PATCH] Staging: rtl8192e: Use kzalloc instead of kmalloc and memset In-Reply-To: Message-ID: References: <1456844212-29057-1-git-send-email-bhumirks@gmail.com> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Tue, 1 Mar 2016, Bhumika Goyal wrote: > On Tue, Mar 1, 2016 at 8:31 PM, Julia Lawall wrote: > > On Tue, 1 Mar 2016, 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. > >> 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 > >> --- > >> 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 58fc70e..1642f29 100644 > >> --- a/drivers/staging/rtl8192e/rtllib_tx.c > >> +++ b/drivers/staging/rtl8192e/rtllib_tx.c > >> @@ -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. > > > > 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 > > Thanks, > Bhumika > > julia > > > >> txb->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 outreachy-kernel+unsubscribe@googlegroups.com. > >> To post to this group, send email to outreachy-kernel@googlegroups.com. > >> 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 outreachy-kernel+unsubscribe@googlegroups.com. > To post to this group, send email to outreachy-kernel@googlegroups.com. > 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. >