mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Akshay Gujar <Akshay.Gujar@harman.com>
To: <gregkh@linuxfoundation.org>
Cc: <Akshay.Gujar@harman.com>, <linux-kernel@vger.kernel.org>,
	<linux-usb@vger.kernel.org>, <naveen.v@harman.com>,
	<oneukum@suse.com>, <stern@rowland.harvard.edu>
Subject: Re: [PATCH v5 1/3] driver core: add device_enumeration_failure_notify() helper
Date: Fri, 24 Jul 2026 22:22:41 +0000	[thread overview]
Message-ID: <20260724222241.471042-1-Akshay.Gujar@harman.com> (raw)
In-Reply-To: <2026071752-proponent-ruckus-36bc@gregkh>

On Fri, Jul 17, 2026 at 12:40:43PM +0000, Greg KH wrote:
> > Hotpluggable buses may detect that a device is physically present,
> > but enumeration can fail early due to protocol-level errors. Such
> > failures are currently only visible via kernel log messages, with no
> > structured notification to userspace.
> > 
> > Introduce device_enumeration_failure_notify(), a helper in the driver
> > core that emits a KOBJ_CHANGE uevent with
> > 
> >   DEVICE_ENUMERATION_FAILURE=<dev_name>
> > 
> > This helper is intended for use by bus drivers such as USB and PCI.
> > 
> > Signed-off-by: Akshay Gujar <Akshay.Gujar@harman.com>
> > ---
> >  drivers/base/core.c    | 44 ++++++++++++++++++++++++++++++++++++++++++
> >  include/linux/device.h |  2 ++
> >  2 files changed, 46 insertions(+)
> > 
> > diff --git a/drivers/base/core.c b/drivers/base/core.c
> > index 4d026682944f2..6694a0c30f61b 100644
> > --- a/drivers/base/core.c
> > +++ b/drivers/base/core.c
> > @@ -3830,6 +3830,50 @@ int device_add(struct device *dev)
> >  }
> >  EXPORT_SYMBOL_GPL(device_add);
> >  
> > +/**
> > + * device_enumeration_failure_notify - notify userspace of enumeration failure
> > + * @dev: device that failed to enumerate a connected child
> > + *
> > + * Emit a KOBJ_CHANGE uevent with
> > + * DEVICE_ENUMERATION_FAILURE=<dev_name>.
> > + *
> > + * If @dev has not yet emitted its ADD uevent, the event may be sent
> > + * from the parent device instead.
> > + *
> > + * The caller must hold a reference to @dev.
> > + *
> > + * See Documentation/ABI/testing/sysfs-uevent for more details.
> > + */
> > +void device_enumeration_failure_notify(struct device *dev)
> > +{
> > +	char *envp[2] = { NULL, NULL };
> > +	struct device *uevent_dev;
> > +
> > +	if (!dev)
> > +		return;
> > +
> > +	/*
> > +	 * If enumeration fails before @dev has emitted its ADD uevent, the
> > +	 * device may still be in an early state (e.g. without a bus or class
> > +	 * assigned). Emit the event from the parent device instead, while
> > +	 * including DEVICE_ENUMERATION_FAILURE=<dev_name>.
> > +	 *
> > +	 * The caller holds a reference to @dev, so dev->parent remains valid.
> > +	 */
> > +	uevent_dev = dev->kobj.state_add_uevent_sent ? dev : dev->parent;
> 
> This is going to confuse people, if events show up for a parent device,
> and for an actual device, in different busses/times, right?  Why
> shouldn't the device itself always just be the one as it's up to the bus
> to determine when to call this?
> 
> For your USB example, is the uevent sent state ever hit yet when you
> want to emit this?

No. Passing &port_dev->dev directly drops the uevent in kobject_uevent_env() 
because dev_uevent_filter() returns 0 for usb_port devices (no bus/class).

The event must therefore be emitted from the port's registered parent,
the hub's usb_interface device (port_dev->dev.parent).

To keep the helper simple, v6 will explicitly take the emitting device 
and the failed identifier, removing all internal fallback logic:

    int device_enumeration_failure_notify(struct device *dev,
                                          const char *failed_id);

USB caller in hub_port_connect():

    device_enumeration_failure_notify(port_dev->dev.parent,
                                      dev_name(&port_dev->dev));

> > +	if (!uevent_dev)
> > +		return;
> 
> How can that happen?  A device will ALWAYS have a valid parent pointer.

With the fallback removed there is no parent handling in the helper
at all, so this check will be gone in v6.

> > +
> > +	envp[0] = kasprintf(GFP_KERNEL, "DEVICE_ENUMERATION_FAILURE=%s",
> > +			    dev_name(dev));
> > +	if (!envp[0])
> > +		return;
> > +
> > +	kobject_uevent_env(&uevent_dev->kobj, KOBJ_CHANGE, envp);
> 
> You loose this error if something went wrong?

Will return the error to the caller.

	ret = kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
	kfree(envp[0]);
	return ret;

Will send v6 with these changes.

Thanks,
Akshay

  reply	other threads:[~2026-07-24 22:22 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-15 11:40 [PATCH v5 0/3] driver core: add enumeration failure uevent helper Akshay Gujar
2026-07-15 11:40 ` [PATCH v5 1/3] driver core: add device_enumeration_failure_notify() helper Akshay Gujar
2026-07-17 10:40   ` Greg KH
2026-07-24 22:22     ` Akshay Gujar [this message]
2026-07-15 11:40 ` [PATCH v5 2/3] Documentation: ABI: document DEVICE_ENUMERATION_FAILURE uevent Akshay Gujar
2026-07-17 10:37   ` Greg KH
2026-07-24 22:25     ` Akshay Gujar
2026-07-25  5:21       ` Greg KH
2026-07-27 13:32         ` Akshay Gujar
2026-07-27 19:31           ` Greg KH
2026-07-15 11:40 ` [PATCH v5 3/3] usb: hub: send enumeration failure uevent Akshay Gujar
2026-07-17 10:35 ` [PATCH v5 0/3] driver core: add enumeration failure uevent helper Greg KH
2026-07-24 22:26   ` Akshay Gujar
2026-07-26 23:14 ` Michal Pecio

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260724222241.471042-1-Akshay.Gujar@harman.com \
    --to=akshay.gujar@harman.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=naveen.v@harman.com \
    --cc=oneukum@suse.com \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®