lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:	Tue, 10 Feb 2015 06:41:59 -0800
From:	Joe Perches <joe@...ches.com>
To:	Dan Carpenter <dan.carpenter@...cle.com>
Cc:	Quentin Lambert <lambert.quentin@...il.com>,
	Shigekatsu Tateno <shigekatsu.tateno@...el.com>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	devel@...verdev.osuosl.org, kernel-janitors@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 1/1] staging: ozwpan: Remove allocation from
 delaration line

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.


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ