All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Grant Likely <grant.likely@secretlab.ca>,
	Rob Herring <rob.herring@calxeda.com>,
	Lars-Peter Clausen <lars@metafoo.de>,
	linux-kernel@vger.kernel.org,
	devicetree-discuss@lists.ozlabs.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [patch] driver-core: dev_to_node() should handle NULL pointers
Date: Thu, 16 Aug 2012 17:23:47 +0000	[thread overview]
Message-ID: <20120816172347.GA27415@kroah.com> (raw)
In-Reply-To: <20120720151846.GQ16348@mwanda>

On Fri, Jul 20, 2012 at 06:18:46PM +0300, Dan Carpenter wrote:
> On Fri, Jul 20, 2012 at 08:00:42AM -0700, Greg Kroah-Hartman wrote:
> > On Fri, Jul 20, 2012 at 09:56:23AM +0300, Dan Carpenter wrote:
> > > What prompted this patch is that in dma_pool_create() we call
> > > dev_to_node() before checking whether "dev" is NULL.  It looks like
> > > there are places which call dma_pool_create() with a NULL pointer.  An
> > > example is in drivers/usb/gadget/amd5536udc.c.
> > > 
> > > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > > ---
> > > Static checker fix.
> > > 
> > > diff --git a/include/linux/device.h b/include/linux/device.h
> > > index aa7b3b4..c80e7a8d 100644
> > > --- a/include/linux/device.h
> > > +++ b/include/linux/device.h
> > > @@ -714,7 +714,9 @@ int dev_set_name(struct device *dev, const char *name, ...);
> > >  #ifdef CONFIG_NUMA
> > >  static inline int dev_to_node(struct device *dev)
> > >  {
> > > -	return dev->numa_node;
> > > +	if (dev)
> > > +		return dev->numa_node;
> > > +	return -1;
> > 
> > What happens if this function returns -1?  Can the callers properly
> > handle this?
> > 
> 
> Gar.  Now I'm not sure any more.
> 
> -1 means no affinity and it's what the dev_to_node() returns if NUMA
> is disabled.  But now I think probably it's important to get the
> NUMA node correct in dma_pool_create() so this isn't the right
> answer.
> 
> dma_pool_create() is not correct.  It has code to handle a NULL
> "dev" pointer, but the dev_to_node() dereference will cause an oops
> before we reach it.  I'm think this is a real issue that affects a
> couple drivers.  Maybe those people compile without NUMA?
> 
> I'm not sure the right fix now.

Ok, I'll drop this one then.

greg k-h

WARNING: multiple messages have this Message-ID (diff)
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Grant Likely <grant.likely@secretlab.ca>,
	Rob Herring <rob.herring@calxeda.com>,
	Lars-Peter Clausen <lars@metafoo.de>,
	linux-kernel@vger.kernel.org,
	devicetree-discuss@lists.ozlabs.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [patch] driver-core: dev_to_node() should handle NULL pointers
Date: Thu, 16 Aug 2012 10:23:47 -0700	[thread overview]
Message-ID: <20120816172347.GA27415@kroah.com> (raw)
In-Reply-To: <20120720151846.GQ16348@mwanda>

On Fri, Jul 20, 2012 at 06:18:46PM +0300, Dan Carpenter wrote:
> On Fri, Jul 20, 2012 at 08:00:42AM -0700, Greg Kroah-Hartman wrote:
> > On Fri, Jul 20, 2012 at 09:56:23AM +0300, Dan Carpenter wrote:
> > > What prompted this patch is that in dma_pool_create() we call
> > > dev_to_node() before checking whether "dev" is NULL.  It looks like
> > > there are places which call dma_pool_create() with a NULL pointer.  An
> > > example is in drivers/usb/gadget/amd5536udc.c.
> > > 
> > > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > > ---
> > > Static checker fix.
> > > 
> > > diff --git a/include/linux/device.h b/include/linux/device.h
> > > index aa7b3b4..c80e7a8d 100644
> > > --- a/include/linux/device.h
> > > +++ b/include/linux/device.h
> > > @@ -714,7 +714,9 @@ int dev_set_name(struct device *dev, const char *name, ...);
> > >  #ifdef CONFIG_NUMA
> > >  static inline int dev_to_node(struct device *dev)
> > >  {
> > > -	return dev->numa_node;
> > > +	if (dev)
> > > +		return dev->numa_node;
> > > +	return -1;
> > 
> > What happens if this function returns -1?  Can the callers properly
> > handle this?
> > 
> 
> Gar.  Now I'm not sure any more.
> 
> -1 means no affinity and it's what the dev_to_node() returns if NUMA
> is disabled.  But now I think probably it's important to get the
> NUMA node correct in dma_pool_create() so this isn't the right
> answer.
> 
> dma_pool_create() is not correct.  It has code to handle a NULL
> "dev" pointer, but the dev_to_node() dereference will cause an oops
> before we reach it.  I'm think this is a real issue that affects a
> couple drivers.  Maybe those people compile without NUMA?
> 
> I'm not sure the right fix now.

Ok, I'll drop this one then.

greg k-h

  reply	other threads:[~2012-08-16 17:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-20  6:56 [patch] driver-core: dev_to_node() should handle NULL pointers Dan Carpenter
2012-07-20  6:56 ` Dan Carpenter
2012-07-20 15:00 ` Greg Kroah-Hartman
2012-07-20 15:00   ` Greg Kroah-Hartman
2012-07-20 15:18   ` Dan Carpenter
2012-07-20 15:18     ` Dan Carpenter
2012-08-16 17:23     ` Greg Kroah-Hartman [this message]
2012-08-16 17:23       ` Greg Kroah-Hartman

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=20120816172347.GA27415@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=dan.carpenter@oracle.com \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=grant.likely@secretlab.ca \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rob.herring@calxeda.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.