Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752175AbcJIPgr (ORCPT ); Sun, 9 Oct 2016 11:36:47 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:59521 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751056AbcJIPgq (ORCPT ); Sun, 9 Oct 2016 11:36:46 -0400 Date: Sun, 9 Oct 2016 17:25:23 +0200 From: Greg KH To: Sergio Paracuellos Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] staging: wlan-ng: get memory from kernel allocators instead of big static buffer Message-ID: <20161009152523.GA23652@kroah.com> References: <20161009143119.GB4231@kroah.com> <1476026092-15393-1-git-send-email-sergio.paracuellos@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1476026092-15393-1-git-send-email-sergio.paracuellos@gmail.com> User-Agent: Mutt/1.7.0 (2016-08-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1405 Lines: 40 On Sun, Oct 09, 2016 at 05:14:52PM +0200, Sergio Paracuellos wrote: > This patch fix the following sparse warnings in prism2fw.c: > warning: memset with byte count of 120000 > > Signed-off-by: Sergio Paracuellos > --- > drivers/staging/wlan-ng/prism2fw.c | 11 ++++++++--- > 1 file changed, 8 insertions(+), 3 deletions(-) > > diff --git a/drivers/staging/wlan-ng/prism2fw.c b/drivers/staging/wlan-ng/prism2fw.c > index 96aa211..7e33048 100644 > --- a/drivers/staging/wlan-ng/prism2fw.c > +++ b/drivers/staging/wlan-ng/prism2fw.c > @@ -124,7 +124,7 @@ struct imgchunk { > > /* Data records */ > static unsigned int ns3data; > -static struct s3datarec s3data[S3DATA_MAX]; > +static struct s3datarec *s3data; > > /* Plug records */ > static unsigned int ns3plug; > @@ -248,7 +248,12 @@ static int prism2_fwapply(const struct ihex_binrec *rfptr, > > /* Initialize the data structures */ > ns3data = 0; > - memset(s3data, 0, sizeof(s3data)); > + s3data = kcalloc(S3DATA_MAX, sizeof(*s3data), GFP_KERNEL); > + if (unlikely(!s3data)) { Unless you can measure the speed difference, NEVER use likely or unlikely in kernel code. The CPU and compiler knows better than you do what is going to happen, and optimizes it. Especially for allocating memory, that is a very common pattern and it knows what to do here. Please remove this and resend. thanks, greg k-h