From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752267AbbE1GnM (ORCPT ); Thu, 28 May 2015 02:43:12 -0400 Received: from mail-pa0-f46.google.com ([209.85.220.46]:35214 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751082AbbE1GnJ (ORCPT ); Thu, 28 May 2015 02:43:09 -0400 Date: Thu, 28 May 2015 12:12:56 +0530 From: Sudip Mukherjee To: Felipe Balbi Cc: Greg KH , Alan Stern , Heikki Krogerus , Tal Shorer , Sasha Levin , USB list , "" , David Cohen , Lu Baolu Subject: Re: [PATCH] usb: ulpi: don't register drivers if bus doesn't exist Message-ID: <20150528064256.GA30988@sudip-PC> References: <20150527083933.GA13844@kuha.fi.intel.com> <20150527152116.GA1972@kroah.com> <20150528053938.GB2944@sudip-PC> <20150528055459.GC10509@saruman.tx.rr.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150528055459.GC10509@saruman.tx.rr.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 28, 2015 at 12:54:59AM -0500, Felipe Balbi wrote: > On Thu, May 28, 2015 at 11:09:38AM +0530, Sudip Mukherjee wrote: > > On Wed, May 27, 2015 at 08:21:16AM -0700, Greg KH wrote: > > > On Wed, May 27, 2015 at 11:16:34AM -0400, Alan Stern wrote: > > > > On Wed, 27 May 2015, Heikki Krogerus wrote: > > > > > > Maybe we need to test for this in the driver core, not allowing drivers > > > for busses that are not registered, that might solve the main problem > > > here. I'll try to look at it tonight. > > may i suggest something like this ? > > buildtest with allmodconfig and allyesconfig on x86_64. > > built and booted on x86. > > > > > > diff --git a/drivers/base/bus.c b/drivers/base/bus.c > > index 5005924..95cefa0 100644 > > --- a/drivers/base/bus.c > > +++ b/drivers/base/bus.c > > @@ -943,6 +943,7 @@ int bus_register(struct bus_type *bus) > > if (retval) > > goto bus_groups_fail; > > > > + bus->registered = true; > > once set, it's never cleared. It should be cleared when we go for bus_unregister. > > > pr_debug("bus: '%s': registered\n", bus->name); > > return 0; > > > > diff --git a/drivers/base/driver.c b/drivers/base/driver.c > > index 4eabfe2..1acae5b 100644 > > --- a/drivers/base/driver.c > > +++ b/drivers/base/driver.c > > @@ -150,6 +150,11 @@ int driver_register(struct device_driver *drv) > > int ret; > > struct device_driver *other; > > > > + if (!drv->bus->registered) { > > + pr_err("Driver %s registration failed. bus not yet registered\n", > > + drv->name); > > + return -ENODEV; > > + } > > BUG_ON(!drv->bus->p); > > > > if ((drv->bus->probe && drv->probe) || > > diff --git a/include/linux/device.h b/include/linux/device.h > > index 00ac57c..8fe4745 100644 > > --- a/include/linux/device.h > > +++ b/include/linux/device.h > > @@ -126,6 +126,7 @@ struct bus_type { > > const struct dev_pm_ops *pm; > > > > const struct iommu_ops *iommu_ops; > > + bool registered; /* DON'T TOUCH THIS */ > > I would rather use an atomic_t ok. This was just an idea, if Greg and you all are okay with it then I can submit a formal patch. BTW, the original comment that I thought was: /* don't use else Greg will scold */ regards sudip > > -- > balbi