From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Geliang Tang <geliangtang@163.com>
Cc: devel@driverdev.osuosl.org,
"Raphaël Beamonte" <raphael.beamonte@gmail.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/4] staging: rtl8192u: r8192U_core: use kmalloc_array instead of kmalloc
Date: Mon, 22 Feb 2016 17:10:13 -0800 [thread overview]
Message-ID: <20160223011013.GA27444@kroah.com> (raw)
In-Reply-To: <20160223005504.GA1750@localhost.localdomain>
On Tue, Feb 23, 2016 at 08:55:04AM +0800, Geliang Tang wrote:
> On Sun, Feb 07, 2016 at 07:55:09PM -0800, Greg Kroah-Hartman wrote:
> > On Sun, Nov 08, 2015 at 10:17:54PM +0800, Geliang Tang wrote:
> > > Use kmalloc_array instead of kmalloc to allocate memory for an array.
> > >
> > > Signed-off-by: Geliang Tang <geliangtang@163.com>
> > > ---
> > > drivers/staging/rtl8192u/r8192U_core.c | 4 ++--
> > > 1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
> > > index e06864f..07a1447 100644
> > > --- a/drivers/staging/rtl8192u/r8192U_core.c
> > > +++ b/drivers/staging/rtl8192u/r8192U_core.c
> > > @@ -1725,8 +1725,8 @@ static short rtl8192_usb_initendpoints(struct net_device *dev)
> > > {
> > > struct r8192_priv *priv = ieee80211_priv(dev);
> > >
> > > - priv->rx_urb = kmalloc(sizeof(struct urb *) * (MAX_RX_URB + 1),
> > > - GFP_KERNEL);
> > > + priv->rx_urb = kmalloc_array(MAX_RX_URB + 1, sizeof(struct urb *),
> > > + GFP_KERNEL);
> >
> > I don't see the benefit here with this change, do you?
>
> It is highly likely that there is a checkpatch warning "kmalloc with multiplies"
> here. But the checkpatch script does not report this warning, I think it is
> because MAX_RX_URB is a macro, and there is a '+1' after it. Therefore although
> it passes,I think it still should be deemed as a warning. So to use kmalloc_array
> here seems better.
No, not for a statically defined size, it doesn't make any sense at all.
kmalloc_array() is to ensure that if you need to allocate a huge size of
memory, that you don't accidentally overflow the memory size with the
calculation you have made, so it does that calculation in a "safe" way.
For a static number, like you have here, it doesn't make any difference.
checkpatch.pl is a _HINT_ not a hard-and-fast-rule.
sorry,
greg k-h
next prev parent reply other threads:[~2016-02-23 1:10 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-08 14:17 [PATCH 1/4] staging: comedi: " Geliang Tang
2015-11-08 14:17 ` [PATCH 2/4] staging: rdma: " Geliang Tang
2015-11-08 14:17 ` [PATCH 3/4] staging: lustre: libcfs: " Geliang Tang
2015-11-08 14:17 ` [PATCH 4/4] staging: rtl8192u: r8192U_core: " Geliang Tang
2016-02-08 3:55 ` Greg Kroah-Hartman
2016-02-23 0:55 ` Geliang Tang
2016-02-23 1:10 ` Greg Kroah-Hartman [this message]
2015-11-09 13:49 ` [PATCH 1/4] staging: comedi: " Ian Abbott
2015-11-10 14:41 ` [PATCH v2] " Geliang Tang
2015-11-11 14:09 ` Ian Abbott
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160223011013.GA27444@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=devel@driverdev.osuosl.org \
--cc=geliangtang@163.com \
--cc=linux-kernel@vger.kernel.org \
--cc=raphael.beamonte@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®