From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andy Shevchenko Subject: Re: [PATCH v2 1/7] device core: add BUS_NOTIFY_BIND_DRIVER_ERROR notification Date: Fri, 27 Nov 2015 11:46:20 +0200 Message-ID: <1448617580.15393.99.camel@linux.intel.com> References: <1448551153-84719-1-git-send-email-andriy.shevchenko@linux.intel.com> <1448551153-84719-2-git-send-email-andriy.shevchenko@linux.intel.com> <10826039.DB5kcb9LL1@vostro.rjw.lan> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: Received: from mga11.intel.com ([192.55.52.93]:40995 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754040AbbK0JqM (ORCPT ); Fri, 27 Nov 2015 04:46:12 -0500 In-Reply-To: <10826039.DB5kcb9LL1@vostro.rjw.lan> Sender: linux-acpi-owner@vger.kernel.org List-Id: linux-acpi@vger.kernel.org To: "Rafael J. Wysocki" Cc: linux-acpi@vger.kernel.org, Vinod Koul , dmaengine@vger.kernel.org, Thomas Gleixner , Greg Kroah-Hartman , Jarkko Nikula , linux-kernel@vger.kernel.org, Mika Westerberg On Fri, 2015-11-27 at 00:09 +0100, Rafael J. Wysocki wrote: > On Thursday, November 26, 2015 05:19:07 PM Andy Shevchenko wrote: > > In case ->probe() fails the notifier does not inform a subscriber > > about this. > > In the result it might happend that some resources that had been > > allocated will > > stay allocated and therefore lead to resource leak. > >=20 > > Introduce a new notification to inform the subscriber that > > ->probe() failed. > >=20 > > Signed-off-by: Andy Shevchenko >=20 > I'd rather say the problem is that the users of > BUS_NOTIFY_BIND_DRIVER have no > chance to do any cleanup in case of a probe failure (there may be > problems even > if resources aren't leaked). Thanks, Rafael, all of your comments sound reasonable for me. Will be taken into consideration in next version. >=20 > > --- > > =C2=A0drivers/base/dd.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0| 8 ++++= ++-- > > =C2=A0include/linux/device.h | 1 + > > =C2=A02 files changed, 7 insertions(+), 2 deletions(-) > >=20 > > diff --git a/drivers/base/dd.c b/drivers/base/dd.c > > index a641cf3..ac071a5 100644 > > --- a/drivers/base/dd.c > > +++ b/drivers/base/dd.c > > @@ -290,7 +290,7 @@ static int really_probe(struct device *dev, > > struct device_driver *drv) > > =C2=A0 /* If using pinctrl, bind pins now before probing */ > > =C2=A0 ret =3D pinctrl_bind_pins(dev); > > =C2=A0 if (ret) > > - goto probe_failed; > > + goto pinctrl_bind_failed; > > =C2=A0 > > =C2=A0 if (driver_sysfs_add(dev)) { > > =C2=A0 printk(KERN_ERR "%s: driver_sysfs_add(%s) > > failed\n", > > @@ -334,6 +334,11 @@ static int really_probe(struct device *dev, > > struct device_driver *drv) > > =C2=A0 goto done; > > =C2=A0 > > =C2=A0probe_failed: > > + if (dev->bus) > > + blocking_notifier_call_chain(&dev->bus->p- > > >bus_notifier, > > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0BUS_NOTIFY_BIND_DRIVE > > R_ERROR, > > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0dev); >=20 > Well, if we do that, device_bind_driver() needs to send that > notification too > in case it doesn't call driver_bound(). >=20 > > +pinctrl_bind_failed: > > =C2=A0 devres_release_all(dev); > > =C2=A0 driver_sysfs_remove(dev); > > =C2=A0 dev->driver =3D NULL; > > @@ -701,7 +706,6 @@ static void __device_release_driver(struct > > device *dev) > > =C2=A0 blocking_notifier_call_chain(&dev->bus->p- > > >bus_notifier, > > =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0BUS_NOTIFY_UN > > BOUND_DRIVER, > > =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0dev); > > - > > =C2=A0 } > > =C2=A0} > > =C2=A0 > > diff --git a/include/linux/device.h b/include/linux/device.h > > index b8f411b..87cf423 100644 > > --- a/include/linux/device.h > > +++ b/include/linux/device.h > > @@ -191,6 +191,7 @@ extern int bus_unregister_notifier(struct > > bus_type *bus, > > =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0unbound */ > > =C2=A0#define BUS_NOTIFY_UNBOUND_DRIVER 0x00000007 /* driver is > > unbound > > =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0from the > > device */ > > +#define BUS_NOTIFY_BIND_DRIVER_ERROR 0x80000004 /* driver > > fails to be bound */ >=20 > I'd call it BUS_NOTIFY_DRIVER_NOT_BOUND. >=20 > > =C2=A0 > > =C2=A0extern struct kset *bus_get_kset(struct bus_type *bus); > > =C2=A0extern struct klist *bus_get_device_klist(struct bus_type *bu= s); > >=20 >=20 > Thanks, > Rafael >=20 --=20 Andy Shevchenko Intel Finland Oy -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" i= n the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754412AbbK0JqQ (ORCPT ); Fri, 27 Nov 2015 04:46:16 -0500 Received: from mga11.intel.com ([192.55.52.93]:40995 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754040AbbK0JqM (ORCPT ); Fri, 27 Nov 2015 04:46:12 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,351,1444719600"; d="scan'208";a="848111907" Message-ID: <1448617580.15393.99.camel@linux.intel.com> Subject: Re: [PATCH v2 1/7] device core: add BUS_NOTIFY_BIND_DRIVER_ERROR notification From: Andy Shevchenko To: "Rafael J. Wysocki" Cc: linux-acpi@vger.kernel.org, Vinod Koul , dmaengine@vger.kernel.org, Thomas Gleixner , Greg Kroah-Hartman , Jarkko Nikula , linux-kernel@vger.kernel.org, Mika Westerberg Date: Fri, 27 Nov 2015 11:46:20 +0200 In-Reply-To: <10826039.DB5kcb9LL1@vostro.rjw.lan> References: <1448551153-84719-1-git-send-email-andriy.shevchenko@linux.intel.com> <1448551153-84719-2-git-send-email-andriy.shevchenko@linux.intel.com> <10826039.DB5kcb9LL1@vostro.rjw.lan> Organization: Intel Finland Oy Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.18.2-1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2015-11-27 at 00:09 +0100, Rafael J. Wysocki wrote: > On Thursday, November 26, 2015 05:19:07 PM Andy Shevchenko wrote: > > In case ->probe() fails the notifier does not inform a subscriber > > about this. > > In the result it might happend that some resources that had been > > allocated will > > stay allocated and therefore lead to resource leak. > > > > Introduce a new notification to inform the subscriber that > > ->probe() failed. > > > > Signed-off-by: Andy Shevchenko > > I'd rather say the problem is that the users of > BUS_NOTIFY_BIND_DRIVER have no > chance to do any cleanup in case of a probe failure (there may be > problems even > if resources aren't leaked). Thanks, Rafael, all of your comments sound reasonable for me. Will be taken into consideration in next version. > > > --- > >  drivers/base/dd.c      | 8 ++++++-- > >  include/linux/device.h | 1 + > >  2 files changed, 7 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/base/dd.c b/drivers/base/dd.c > > index a641cf3..ac071a5 100644 > > --- a/drivers/base/dd.c > > +++ b/drivers/base/dd.c > > @@ -290,7 +290,7 @@ static int really_probe(struct device *dev, > > struct device_driver *drv) > >   /* If using pinctrl, bind pins now before probing */ > >   ret = pinctrl_bind_pins(dev); > >   if (ret) > > - goto probe_failed; > > + goto pinctrl_bind_failed; > >   > >   if (driver_sysfs_add(dev)) { > >   printk(KERN_ERR "%s: driver_sysfs_add(%s) > > failed\n", > > @@ -334,6 +334,11 @@ static int really_probe(struct device *dev, > > struct device_driver *drv) > >   goto done; > >   > >  probe_failed: > > + if (dev->bus) > > + blocking_notifier_call_chain(&dev->bus->p- > > >bus_notifier, > > +      BUS_NOTIFY_BIND_DRIVE > > R_ERROR, > > +      dev); > > Well, if we do that, device_bind_driver() needs to send that > notification too > in case it doesn't call driver_bound(). > > > +pinctrl_bind_failed: > >   devres_release_all(dev); > >   driver_sysfs_remove(dev); > >   dev->driver = NULL; > > @@ -701,7 +706,6 @@ static void __device_release_driver(struct > > device *dev) > >   blocking_notifier_call_chain(&dev->bus->p- > > >bus_notifier, > >        BUS_NOTIFY_UN > > BOUND_DRIVER, > >        dev); > > - > >   } > >  } > >   > > diff --git a/include/linux/device.h b/include/linux/device.h > > index b8f411b..87cf423 100644 > > --- a/include/linux/device.h > > +++ b/include/linux/device.h > > @@ -191,6 +191,7 @@ extern int bus_unregister_notifier(struct > > bus_type *bus, > >         unbound */ > >  #define BUS_NOTIFY_UNBOUND_DRIVER 0x00000007 /* driver is > > unbound > >         from the > > device */ > > +#define BUS_NOTIFY_BIND_DRIVER_ERROR 0x80000004 /* driver > > fails to be bound */ > > I'd call it BUS_NOTIFY_DRIVER_NOT_BOUND. > > >   > >  extern struct kset *bus_get_kset(struct bus_type *bus); > >  extern struct klist *bus_get_device_klist(struct bus_type *bus); > > > > Thanks, > Rafael > -- Andy Shevchenko Intel Finland Oy