public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Hank Janssen <hjanssen@microsoft.com>,
	"'linux-kernel@vger.kernel.org'" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] Fix null pointer error after vmbus loading
Date: Thu, 22 Oct 2009 15:55:30 -0700	[thread overview]
Message-ID: <20091022225530.GA11244@suse.de> (raw)
In-Reply-To: <1FB5E1D5CA062146B38059374562DF72180B3D51@TK5EX14MBXC126.redmond.corp.microsoft.com>

On Thu, Oct 22, 2009 at 03:39:05PM +0000, Haiyang Zhang wrote:
> > >         /* Make sure we are not registered already */
> > > -       if (strlen(dev_name(&child_device_ctx->device)) != 0) {
> > > +       if (dev_name(&child_device_ctx->device) != NULL &&
> > > +           strlen(dev_name(&child_device_ctx->device)) != 0) {
> > 
> > Why would the device name ever be NULL?  Why would you need to check it
> > here?
> 
> In recently kernel versions, char bus_id[BUS_ID_SIZE] in struct device
> has been replaced by char* type kobj.name, which is NULL if name is
> not yet set.

Yes, but you should never care about this being NULL.

> The function vmbus_child_device_create() alloc the memory for struct
> device_context, which includes struct device as a member. All data are
> initialized to zero, so the device name ptr, aka kobj.name, is NULL at
> the beginning:
> 	child_device_ctx = kzalloc(sizeof(struct device_context), GFP_KERNEL);
> So, a NULL pointer checking is added to avoid null pointer dereference
> error if strlen() is called on the NULL name pointer. After we confirm
> the device isn't registered yet, we will set the name and register the
> device.

But this is not how you check to see if your device is registered at
all, you can not rely on the driver core to have the name set or not to
reflect the status of the device.  Devices have many stages in their
lifecycle, and the name reliably shows none of them.

Actually, why do you need to know this?  Shouldn't you always know the
state of your device, how can you get passed an unregistered device?

That is the real fix that needs to be done here.

thanks,

greg k-h

  reply	other threads:[~2009-10-22 22:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1FB5E1D5CA062146B38059374562DF72180B39CA@TK5EX14MBXC126.redmond.corp.microsoft.com>
2009-10-21 22:43 ` [PATCH] Fix null pointer error after vmbus loading Greg KH
2009-10-22 15:39   ` Haiyang Zhang
2009-10-22 22:55     ` Greg KH [this message]
2009-10-23 16:22       ` Haiyang Zhang
2009-10-21 22:45 ` Greg KH

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=20091022225530.GA11244@suse.de \
    --to=gregkh@suse.de \
    --cc=haiyangz@microsoft.com \
    --cc=hjanssen@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    /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