On Fri, Oct 20, 2017 at 01:54:36PM +0000, [email protected] wrote:
> > -----Original Message-----
> > From: Greg KH [mailto:[email protected]]
> > Sent: Friday, October 20, 2017 8:22 AM
> > To: Limonciello, Mario <[email protected]>
> > Cc: [email protected]; Andy Shevchenko <[email protected]>;
> > LKML <[email protected]>; [email protected]; 
> > Andy
> > Lutomirski <[email protected]>; [email protected]; [email protected];
> > [email protected]; [email protected]; [email protected]; Alan Cox
> > <[email protected]>
> > Subject: Re: [PATCH v10 13/15] platform/x86: wmi: create userspace 
> > interface for
> > drivers
> > 
> > On Thu, Oct 19, 2017 at 12:50:16PM -0500, Mario Limonciello wrote:
> > > + wblock = container_of(wdev, struct wmi_block, dev);
> > > + if (!wblock)
> > > +         return -ENODEV;
> > 
> > How can container_of() ever return NULL?  If so, you have a very odd
> > memory layout...
> > 
> 
> I'm assuming this is from set_required_buffer_size right?
> 
> The symbol is exported out for other drivers to use.  It's possible for 
> another
> driver to allocate a wmi_device structure that's not part of a wblock.

container_of can never return NULL, it does arithmetics on a pointer
based on the type it is embedded into.

You better don't register a wmi_device that's not part of the block
with your driver.  Which others drivers are those, btw?

> > > + list_for_each_entry_safe(wblock, next, &wmi_block_list, list) {
> > > +         wdriver = container_of(wblock->dev.dev.driver,
> > > +                                 struct wmi_driver, driver);
> > > +         if (!wdriver)
> > > +                 continue;
> > 
> > Same here.  And other places in this file.
> > 
> 
> This one it's possible that a driver isn't bound to a device, and when
> that happens wdriver is NULL.

See above, no it can't.  Maybe wblock->dev.dev.driver can be NULL,
but in that case you must not call container_of on it.

Reply via email to