From: Joe Perches <joe@perches.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Quentin Lambert <lambert.quentin@gmail.com>,
Shigekatsu Tateno <shigekatsu.tateno@atmel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
devel@driverdev.osuosl.org, kernel-janitors@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/1] staging: ozwpan: Remove allocation from delaration line
Date: Tue, 10 Feb 2015 14:41:59 +0000 [thread overview]
Message-ID: <1423579319.8339.1.camel@perches.com> (raw)
In-Reply-To: <20150210101312.GG5206@mwanda>
On Tue, 2015-02-10 at 13:13 +0300, Dan Carpenter wrote:
> > diff --git a/drivers/staging/ozwpan/ozhcd.c b/drivers/staging/ozwpan/ozhcd.c
[]
> > @@ -280,8 +280,9 @@ static void oz_free_urb_link(struct oz_urb_link *urbl)
> > */
> > static struct oz_endpoint *oz_ep_alloc(int buffer_size, gfp_t mem_flags)
> > {
> > - struct oz_endpoint *ep > > - kzalloc(sizeof(struct oz_endpoint)+buffer_size, mem_flags);
> > + struct oz_endpoint *ep;
> > +
> > + ep = kzalloc(sizeof(struct oz_endpoint)+buffer_size, mem_flags);
> > if (ep) {
>
> Also notice how in the original code, we had to mangle the code to make
> it fit into 80 characters so the new code looks much better.
or maybe
ep = kzalloc(sizeof(*ep) + buffer_size, mem_flags);
The current function also tests the return of ep slightly backwards.
static struct oz_endpoint *oz_ep_alloc(int buffer_size, gfp_t mem_flags)
{
struct oz_endpoint *ep kzalloc(sizeof(struct oz_endpoint)+buffer_size, mem_flags);
if (ep) {
INIT_LIST_HEAD(&ep->urb_list);
INIT_LIST_HEAD(&ep->link);
ep->credit = -1;
if (buffer_size) {
ep->buffer_size = buffer_size;
ep->buffer = (u8 *)(ep+1);
}
}
return ep;
}
Perhaps more typical would be:
static struct oz_endpoint *oz_ep_alloc(int buffer_size, gfp_t mem_flags)
{
struct oz_endpoint *ep;
ep = kzalloc(sizeof(*ep) + buffer_size, mem_flags);
if (!ep)
return NULL;
INIT_LIST_HEAD(&ep->urb_list);
INIT_LIST_HEAD(&ep->link);
ep->credit = -1;
if (buffer_size) {
ep->buffer_size = buffer_size;
ep->buffer = (u8 *)(ep + 1);
}
return ep;
}
Maybe buffer_size should be size_t too to avoid
possible negative values.
WARNING: multiple messages have this Message-ID (diff)
From: Joe Perches <joe@perches.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Quentin Lambert <lambert.quentin@gmail.com>,
Shigekatsu Tateno <shigekatsu.tateno@atmel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
devel@driverdev.osuosl.org, kernel-janitors@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/1] staging: ozwpan: Remove allocation from delaration line
Date: Tue, 10 Feb 2015 06:41:59 -0800 [thread overview]
Message-ID: <1423579319.8339.1.camel@perches.com> (raw)
In-Reply-To: <20150210101312.GG5206@mwanda>
On Tue, 2015-02-10 at 13:13 +0300, Dan Carpenter wrote:
> > diff --git a/drivers/staging/ozwpan/ozhcd.c b/drivers/staging/ozwpan/ozhcd.c
[]
> > @@ -280,8 +280,9 @@ static void oz_free_urb_link(struct oz_urb_link *urbl)
> > */
> > static struct oz_endpoint *oz_ep_alloc(int buffer_size, gfp_t mem_flags)
> > {
> > - struct oz_endpoint *ep =
> > - kzalloc(sizeof(struct oz_endpoint)+buffer_size, mem_flags);
> > + struct oz_endpoint *ep;
> > +
> > + ep = kzalloc(sizeof(struct oz_endpoint)+buffer_size, mem_flags);
> > if (ep) {
>
> Also notice how in the original code, we had to mangle the code to make
> it fit into 80 characters so the new code looks much better.
or maybe
ep = kzalloc(sizeof(*ep) + buffer_size, mem_flags);
The current function also tests the return of ep slightly backwards.
static struct oz_endpoint *oz_ep_alloc(int buffer_size, gfp_t mem_flags)
{
struct oz_endpoint *ep =
kzalloc(sizeof(struct oz_endpoint)+buffer_size, mem_flags);
if (ep) {
INIT_LIST_HEAD(&ep->urb_list);
INIT_LIST_HEAD(&ep->link);
ep->credit = -1;
if (buffer_size) {
ep->buffer_size = buffer_size;
ep->buffer = (u8 *)(ep+1);
}
}
return ep;
}
Perhaps more typical would be:
static struct oz_endpoint *oz_ep_alloc(int buffer_size, gfp_t mem_flags)
{
struct oz_endpoint *ep;
ep = kzalloc(sizeof(*ep) + buffer_size, mem_flags);
if (!ep)
return NULL;
INIT_LIST_HEAD(&ep->urb_list);
INIT_LIST_HEAD(&ep->link);
ep->credit = -1;
if (buffer_size) {
ep->buffer_size = buffer_size;
ep->buffer = (u8 *)(ep + 1);
}
return ep;
}
Maybe buffer_size should be size_t too to avoid
possible negative values.
next prev parent reply other threads:[~2015-02-10 14:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-10 9:24 [PATCH v2 1/1] staging: ozwpan: Remove allocation from delaration line Quentin Lambert
2015-02-10 9:24 ` Quentin Lambert
2015-02-10 10:13 ` Dan Carpenter
2015-02-10 10:13 ` Dan Carpenter
2015-02-10 14:41 ` Joe Perches [this message]
2015-02-10 14:41 ` Joe Perches
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=1423579319.8339.1.camel@perches.com \
--to=joe@perches.com \
--cc=dan.carpenter@oracle.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=lambert.quentin@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=shigekatsu.tateno@atmel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.