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: [PATCH v6 1/3] driver core: add device_enumeration_failure_notify() helper
Date: Sun, 2 Aug 2026 23:31:06 +0000 [thread overview]
Message-ID: <20260802233108.70950-2-Akshay.Gujar@harman.com> (raw)
In-Reply-To: <20260802233108.70950-1-Akshay.Gujar@harman.com>
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=<failed_id>
The emitting device and the identifier are separate arguments because
the device being enumerated usually does not exist yet. The event is
emitted from a device the bus driver has already registered, and the
identifier names the port or slot that failed.
Signed-off-by: Akshay Gujar <Akshay.Gujar@harman.com>
---
drivers/base/core.c | 35 +++++++++++++++++++++++++++++++++++
include/linux/device.h | 2 ++
2 files changed, 37 insertions(+)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 4d026682944f2..af6901799df58 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -3830,6 +3830,41 @@ int device_add(struct device *dev)
}
EXPORT_SYMBOL_GPL(device_add);
+/**
+ * device_enumeration_failure_notify - notify userspace of enumeration failure
+ * @dev: device to emit the uevent from
+ * @failed_id: bus-specific identifier of the port or slot that failed to
+ * enumerate, e.g. the port device name for USB
+ *
+ * Emit a KOBJ_CHANGE uevent from @dev carrying
+ * DEVICE_ENUMERATION_FAILURE=@failed_id.
+ *
+ * Return: 0 on success, a negative error code otherwise.
+ *
+ * See Documentation/ABI/testing/sysfs-uevent for more details.
+ */
+int device_enumeration_failure_notify(struct device *dev,
+ const char *failed_id)
+{
+ char *envp[2] = { NULL, NULL };
+ int ret;
+
+ if (!failed_id || !*failed_id)
+ return -EINVAL;
+
+ envp[0] = kasprintf(GFP_KERNEL, "DEVICE_ENUMERATION_FAILURE=%s",
+ failed_id);
+
+ if (!envp[0])
+ return -ENOMEM;
+
+ ret = kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
+ kfree(envp[0]);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(device_enumeration_failure_notify);
+
/**
* device_register - register a device with the system.
* @dev: pointer to the device structure
diff --git a/include/linux/device.h b/include/linux/device.h
index 7b2baffdd2f55..7dc9b2316ea24 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -1394,4 +1394,6 @@ static inline bool device_link_test(const struct device_link *link, u32 flags)
#define MODULE_ALIAS_CHARDEV_MAJOR(major) \
MODULE_ALIAS("char-major-" __stringify(major) "-*")
+int device_enumeration_failure_notify(struct device *dev, const char *failed_id);
+
#endif /* _DEVICE_H_ */
--
2.19.0
next prev parent reply other threads:[~2026-08-02 23:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-02 23:31 [PATCH v6 0/3] driver core: add enumeration failure uevent helper Akshay Gujar
2026-08-02 23:31 ` Akshay Gujar [this message]
2026-08-02 23:31 ` [PATCH v6 2/3] Documentation: ABI: document DEVICE_ENUMERATION_FAILURE uevent Akshay Gujar
2026-08-02 23:31 ` [PATCH v6 3/3] usb: hub: send enumeration failure uevent Akshay Gujar
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=20260802233108.70950-2-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