mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Randy Dunlap <rdunlap@xenotime.net>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Dan Kruchinin <dubalom@gmail.com>, Greg KH <greg@kroah.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Kernel development list <linux-kernel@vger.kernel.org>,
	USB development list <linux-usb-devel@lists.sourceforge.net>
Subject: Re: [linux-usb-devel] [PATCH -mm] drivers/usb/core/config.c: kzalloc(0, ..)
Date: Tue, 8 May 2007 09:45:02 -0700	[thread overview]
Message-ID: <20070508094502.efc32182.rdunlap@xenotime.net> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0705081152590.3217-100000@iolanthe.rowland.org>

On Tue, 8 May 2007 11:57:07 -0400 (EDT) Alan Stern wrote:

> On Tue, 8 May 2007, Greg KH wrote:
> 
> > >  The problem was in drivers/usb/core/config.c in function 
> > >  usb_parse_interface:
> > >  ---
> > >  num_ep = num_ep_orig = alt->desc.bNumEndpoints;
> > >  ...
> > >  len = sizeof(struct usb_host_endpoint) * num_ep;
> > >  alt->endpoint = kzalloc(len, GFP_KERNEL);
> > >  ---
> > > 
> > >  num_ep can be 0, as it was in my case, so following patch makes this
> > >  situation more obvious
> > >  and clear.
> 
> How about instead just doing:
> 
> +	num_ep = max(num_ep, 1);
>  	len = sizeof(struct usb_host_endpoint) * num_ep;
> 
> Also, wasn't it true at one point that it was legal to call kmalloc() with 
> a length of 0?  ISTR seeing somewhere that it's true for regular malloc().

kmalloc(0) was legal with CONFIG_SLAB=y.  However, there is now
something called SLUB, which just returned an error when size == 0.
It has recently been modified to mirror the SLAB behavior but also
do a stack dump so that "bad" callers can be fixed.

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

  reply	other threads:[~2007-05-08 16:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-08  3:03 [PATCH -mm] drivers/usb/core/config.c: kzalloc(0,..) Dan Kruchinin
2007-05-08 11:32 ` Jiri Slaby
2007-05-08 14:14 ` Greg KH
2007-05-08 15:57   ` [linux-usb-devel] [PATCH -mm] drivers/usb/core/config.c: kzalloc(0, ..) Alan Stern
2007-05-08 16:45     ` Randy Dunlap [this message]
2007-05-10  6:41       ` Dan Kruchinin

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=20070508094502.efc32182.rdunlap@xenotime.net \
    --to=rdunlap@xenotime.net \
    --cc=akpm@linux-foundation.org \
    --cc=dubalom@gmail.com \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb-devel@lists.sourceforge.net \
    --cc=stern@rowland.harvard.edu \
    /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®