From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752128AbdJTOsp (ORCPT ); Fri, 20 Oct 2017 10:48:45 -0400 Received: from verein.lst.de ([213.95.11.211]:49280 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752102AbdJTOsl (ORCPT ); Fri, 20 Oct 2017 10:48:41 -0400 Date: Fri, 20 Oct 2017 16:48:39 +0200 From: Christoph Hellwig To: 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 Message-ID: <20171020144839.GA4550@lst.de> References: <175838453318108ae69be344c4d3a2b75c2edc69.1508434514.git.mario.limonciello@dell.com> <20171020132138.GA23973@kroah.com> <19e30ca305e449de86b702ae8900d306@ausx13mpc120.AMER.DELL.COM> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <19e30ca305e449de86b702ae8900d306@ausx13mpc120.AMER.DELL.COM> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > > Cc: dvhart@infradead.org; Andy Shevchenko ; > > LKML ; platform-driver-x86@vger.kernel.org; Andy > > Lutomirski ; quasisec@google.com; pali.rohar@gmail.com; > > rjw@rjwysocki.net; mjg59@google.com; hch@lst.de; Alan Cox > > > > 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.