lkml.org 
[lkml]   [2017]   [Oct]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: [PATCH v10 13/15] platform/x86: wmi: create userspace interface for drivers
Date
> -----Original Message-----
> From: Christoph Hellwig [mailto:hch@lst.de]
> Sent: Friday, October 20, 2017 9:49 AM
> To: Limonciello, Mario <Mario_Limonciello@Dell.com>
> Cc: greg@kroah.com; dvhart@infradead.org; andy.shevchenko@gmail.com; linux-
> kernel@vger.kernel.org; platform-driver-x86@vger.kernel.org; luto@kernel.org;
> quasisec@google.com; pali.rohar@gmail.com; rjw@rjwysocki.net;
> mjg59@google.com; hch@lst.de; gnomes@lxorguk.ukuu.org.uk
> Subject: Re: [PATCH v10 13/15] platform/x86: wmi: create userspace interface for
> drivers
>
> On Fri, Oct 20, 2017 at 01:54:36PM +0000, Mario.Limonciello@dell.com wrote:
> > > -----Original Message-----
> > > From: Greg KH [mailto:greg@kroah.com]
> > > Sent: Friday, October 20, 2017 8:22 AM
> > > To: Limonciello, Mario <Mario_Limonciello@Dell.com>
> > > Cc: dvhart@infradead.org; Andy Shevchenko <andy.shevchenko@gmail.com>;
> > > LKML <linux-kernel@vger.kernel.org>; platform-driver-x86@vger.kernel.org;
> Andy
> > > Lutomirski <luto@kernel.org>; quasisec@google.com; pali.rohar@gmail.com;
> > > rjw@rjwysocki.net; mjg59@google.com; hch@lst.de; Alan Cox
> > > <gnomes@lxorguk.ukuu.org.uk>
> > > 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?

No drivers do this today, it's obviously not a good idea.
I was just saying it's hypothetical.

I see that the other methods exported (wmi_evaluate_method and such) to drivers
require that it's part of a wblock, so this seems like a reasonable expectation
from other drivers. I'll remove this invalid check.

> > 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.

> container_of() is just pointer math. If you pass in NULL, you will get
> a non-NULL value (incremented or decremented). If you pass in a very
> tiny number, you might get NULL, but that's still really wrong.
>
> In other words, these tests will _NEVER_ fail. Go ahead, try it :)

I was seeing failures (with NULL) when I tested with some drivers unbound,
but I now understand my check is definitely wrong. I'll adjust the check and make
sure it's valid.

Thank you both for your feedback here.

\
 
 \ /
  Last update: 2017-10-22 17:42    [W:0.062 / U:0.952 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site