[PATCH 1/3] driver core: Require explicit initialization of class and bus_type name
From: Ian Rogers
Date: Mon Nov 30 2026 - 17:53:57 EST
class_register() and bus_register() pass .name to kobject_set_name() to
register the subsystem kset in sysfs, which fails with -ENOMEM if .name
is NULL.
Annotate .name on struct class and struct bus_type with __must_init so
missing names are caught at compile time.
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
include/linux/device/bus.h | 2 +-
include/linux/device/class.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h
index 9ef7538a9a7f..f6409b1004e3 100644
--- a/include/linux/device/bus.h
+++ b/include/linux/device/bus.h
@@ -79,7 +79,7 @@ struct fwnode_handle;
* private data.
*/
struct bus_type {
- const char *name;
+ const char *name __must_init;
const char *dev_name;
const struct attribute_group *const *bus_groups;
const struct attribute_group *const *dev_groups;
diff --git a/include/linux/device/class.h b/include/linux/device/class.h
index 9db1d61ba743..032b5dce2e0a 100644
--- a/include/linux/device/class.h
+++ b/include/linux/device/class.h
@@ -48,7 +48,7 @@ struct fwnode_handle;
* connected or how they work.
*/
struct class {
- const char *name;
+ const char *name __must_init;
const struct attribute_group *const *class_groups;
const struct attribute_group *const *dev_groups;
--
2.56.1.839.g22a8290db9-goog