mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] driver core: Add __must_init annotations to core registration structs
@ 2026-11-30 22:53 Ian Rogers
  2026-11-30 22:53 ` [PATCH 1/3] driver core: Require explicit initialization of class and bus_type name Ian Rogers
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Ian Rogers @ 2026-11-30 22:53 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J . Wysocki, Danilo Krummrich,
	Johan Hovold, Luis Chamberlain
  Cc: Dave Ertman, Ira Weiny, Leon Romanovsky, Kees Cook, Miguel Ojeda,
	Nathan Chancellor, driver-core, llvm, linux-kernel, Ian Rogers

Following the addition of __must_init in driver-core-next, this series
annotates mandatory fields in core device-model and firmware upload
structures whose registration functions reject missing values at
runtime:

  1. struct bus_type::name and struct class::name (checked via
     kobject_set_name() in bus_register() and class_register())
  2. struct auxiliary_driver::probe and id_table (checked with WARN_ON()
     in __auxiliary_driver_register())
  3. struct fw_upload_ops::prepare, write, poll_complete, and cancel
     (checked in firmware_upload_register())

All existing in-tree initializers already populate these fields; tested
with an x86_64 LLVM=1 build on top of driver-core-next with zero
warnings.

Tooling note: Clang's require_explicit_initialization attribute
(__must_init) was used to verify all in-tree initializers, and an AI
coding assistant helped audit the registration paths and draft the
commit messages. All changes were reviewed and build-tested locally.

Ian Rogers (3):
  driver core: Require explicit initialization of class and bus_type
    name
  driver core: auxiliary: Annotate probe and id_table with __must_init
  firmware_loader: Annotate mandatory fw_upload_ops with __must_init

 include/linux/auxiliary_bus.h | 5 +++--
 include/linux/device/bus.h    | 2 +-
 include/linux/device/class.h  | 2 +-
 include/linux/firmware.h      | 9 +++++----
 4 files changed, 10 insertions(+), 8 deletions(-)


base-commit: f62fba71a846ebe59423bfd057af023b418935a0
-- 
2.56.1.839.g22a8290db9-goog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] driver core: Require explicit initialization of class and bus_type name
  2026-11-30 22:53 [PATCH 0/3] driver core: Add __must_init annotations to core registration structs Ian Rogers
@ 2026-11-30 22:53 ` Ian Rogers
  2026-12-01  8:26   ` Johan Hovold
  2026-11-30 22:53 ` [PATCH 2/3] driver core: auxiliary: Annotate probe and id_table with __must_init Ian Rogers
  2026-11-30 22:53 ` [PATCH 3/3] firmware_loader: Annotate mandatory fw_upload_ops " Ian Rogers
  2 siblings, 1 reply; 7+ messages in thread
From: Ian Rogers @ 2026-11-30 22:53 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J . Wysocki, Danilo Krummrich,
	Johan Hovold, Luis Chamberlain
  Cc: Dave Ertman, Ira Weiny, Leon Romanovsky, Kees Cook, Miguel Ojeda,
	Nathan Chancellor, driver-core, llvm, linux-kernel, Ian Rogers

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@google.com>
---
 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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/3] driver core: auxiliary: Annotate probe and id_table with __must_init
  2026-11-30 22:53 [PATCH 0/3] driver core: Add __must_init annotations to core registration structs Ian Rogers
  2026-11-30 22:53 ` [PATCH 1/3] driver core: Require explicit initialization of class and bus_type name Ian Rogers
@ 2026-11-30 22:53 ` Ian Rogers
  2026-12-01  8:32   ` Johan Hovold
  2026-11-30 22:53 ` [PATCH 3/3] firmware_loader: Annotate mandatory fw_upload_ops " Ian Rogers
  2 siblings, 1 reply; 7+ messages in thread
From: Ian Rogers @ 2026-11-30 22:53 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J . Wysocki, Danilo Krummrich,
	Johan Hovold, Luis Chamberlain
  Cc: Dave Ertman, Ira Weiny, Leon Romanovsky, Kees Cook, Miguel Ojeda,
	Nathan Chancellor, driver-core, llvm, linux-kernel, Ian Rogers

__auxiliary_driver_register() rejects auxiliary_driver structures that
omit probe or id_table with WARN_ON(!auxdrv->probe) and
WARN_ON(!auxdrv->id_table), returning -EINVAL.

Annotate probe and id_table in struct auxiliary_driver with __must_init
so missing initializers are caught at compile time.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 include/linux/auxiliary_bus.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/linux/auxiliary_bus.h b/include/linux/auxiliary_bus.h
index de0ecd0fb05a..387f2af85526 100644
--- a/include/linux/auxiliary_bus.h
+++ b/include/linux/auxiliary_bus.h
@@ -191,14 +191,15 @@ struct auxiliary_device {
  *         };
  */
 struct auxiliary_driver {
-	int (*probe)(struct auxiliary_device *auxdev, const struct auxiliary_device_id *id);
+	int (*probe)(struct auxiliary_device *auxdev,
+		     const struct auxiliary_device_id *id) __must_init;
 	void (*remove)(struct auxiliary_device *auxdev);
 	void (*shutdown)(struct auxiliary_device *auxdev);
 	int (*suspend)(struct auxiliary_device *auxdev, pm_message_t state);
 	int (*resume)(struct auxiliary_device *auxdev);
 	const char *name;
 	struct device_driver driver;
-	const struct auxiliary_device_id *id_table;
+	const struct auxiliary_device_id *id_table __must_init;
 };
 
 static inline void *auxiliary_get_drvdata(struct auxiliary_device *auxdev)
-- 
2.56.1.839.g22a8290db9-goog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/3] firmware_loader: Annotate mandatory fw_upload_ops with __must_init
  2026-11-30 22:53 [PATCH 0/3] driver core: Add __must_init annotations to core registration structs Ian Rogers
  2026-11-30 22:53 ` [PATCH 1/3] driver core: Require explicit initialization of class and bus_type name Ian Rogers
  2026-11-30 22:53 ` [PATCH 2/3] driver core: auxiliary: Annotate probe and id_table with __must_init Ian Rogers
@ 2026-11-30 22:53 ` Ian Rogers
  2026-12-01  8:35   ` Johan Hovold
  2 siblings, 1 reply; 7+ messages in thread
From: Ian Rogers @ 2026-11-30 22:53 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J . Wysocki, Danilo Krummrich,
	Johan Hovold, Luis Chamberlain
  Cc: Dave Ertman, Ira Weiny, Leon Romanovsky, Kees Cook, Miguel Ojeda,
	Nathan Chancellor, driver-core, llvm, linux-kernel, Ian Rogers

firmware_upload_register() requires prepare, write, poll_complete, and
cancel in struct fw_upload_ops and returns ERR_PTR(-EINVAL) if any are
omitted.

Annotate these mandatory callbacks with __must_init so missing callbacks
are caught at compile time.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 include/linux/firmware.h | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/include/linux/firmware.h b/include/linux/firmware.h
index 0fa3b027f02f..65126ca6c8d9 100644
--- a/include/linux/firmware.h
+++ b/include/linux/firmware.h
@@ -69,12 +69,13 @@ struct fw_upload {
  */
 struct fw_upload_ops {
 	enum fw_upload_err (*prepare)(struct fw_upload *fw_upload,
-				      const u8 *data, u32 size);
+				      const u8 *data, u32 size) __must_init;
 	enum fw_upload_err (*write)(struct fw_upload *fw_upload,
 				    const u8 *data, u32 offset,
-				    u32 size, u32 *written);
-	enum fw_upload_err (*poll_complete)(struct fw_upload *fw_upload);
-	void (*cancel)(struct fw_upload *fw_upload);
+				    u32 size, u32 *written) __must_init;
+	enum fw_upload_err (*poll_complete)(struct fw_upload *fw_upload)
+		__must_init;
+	void (*cancel)(struct fw_upload *fw_upload) __must_init;
 	void (*cleanup)(struct fw_upload *fw_upload);
 };
 
-- 
2.56.1.839.g22a8290db9-goog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] driver core: Require explicit initialization of class and bus_type name
  2026-11-30 22:53 ` [PATCH 1/3] driver core: Require explicit initialization of class and bus_type name Ian Rogers
@ 2026-12-01  8:26   ` Johan Hovold
  0 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2026-12-01  8:26 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Greg Kroah-Hartman, Rafael J . Wysocki, Danilo Krummrich,
	Luis Chamberlain, Dave Ertman, Ira Weiny, Leon Romanovsky,
	Kees Cook, Miguel Ojeda, Nathan Chancellor, driver-core, llvm,
	linux-kernel

On Mon, Nov 30, 2026 at 02:53:38PM -0800, Ian Rogers wrote:
> 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.

I don't see the point in doing this as any superficial testing
(i.e. registering the bus or class) will catch this.

Johan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] driver core: auxiliary: Annotate probe and id_table with __must_init
  2026-11-30 22:53 ` [PATCH 2/3] driver core: auxiliary: Annotate probe and id_table with __must_init Ian Rogers
@ 2026-12-01  8:32   ` Johan Hovold
  0 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2026-12-01  8:32 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Greg Kroah-Hartman, Rafael J . Wysocki, Danilo Krummrich,
	Luis Chamberlain, Dave Ertman, Ira Weiny, Leon Romanovsky,
	Kees Cook, Miguel Ojeda, Nathan Chancellor, driver-core, llvm,
	linux-kernel

On Mon, Nov 30, 2026 at 02:53:39PM -0800, Ian Rogers wrote:
> __auxiliary_driver_register() rejects auxiliary_driver structures that
> omit probe or id_table with WARN_ON(!auxdrv->probe) and
> WARN_ON(!auxdrv->id_table), returning -EINVAL.

IIUC you can't drop the WARN_ON() yet and any superficial testing of the
driver (i.e. probing a device) will catch this. So there's not much to
be gained here either.

Johan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] firmware_loader: Annotate mandatory fw_upload_ops with __must_init
  2026-11-30 22:53 ` [PATCH 3/3] firmware_loader: Annotate mandatory fw_upload_ops " Ian Rogers
@ 2026-12-01  8:35   ` Johan Hovold
  0 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2026-12-01  8:35 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Greg Kroah-Hartman, Rafael J . Wysocki, Danilo Krummrich,
	Luis Chamberlain, Dave Ertman, Ira Weiny, Leon Romanovsky,
	Kees Cook, Miguel Ojeda, Nathan Chancellor, driver-core, llvm,
	linux-kernel

On Mon, Nov 30, 2026 at 02:53:40PM -0800, Ian Rogers wrote:
> firmware_upload_register() requires prepare, write, poll_complete, and
> cancel in struct fw_upload_ops and returns ERR_PTR(-EINVAL) if any are
> omitted.

And same here, as you cannot drop the sanity checks during registration
yet, even if I guess this may aid a developer while writing a driver a
tiny bit (i.e. before the first test run).

Johan

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-12-01  8:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30 22:53 [PATCH 0/3] driver core: Add __must_init annotations to core registration structs Ian Rogers
2026-11-30 22:53 ` [PATCH 1/3] driver core: Require explicit initialization of class and bus_type name Ian Rogers
2026-12-01  8:26   ` Johan Hovold
2026-11-30 22:53 ` [PATCH 2/3] driver core: auxiliary: Annotate probe and id_table with __must_init Ian Rogers
2026-12-01  8:32   ` Johan Hovold
2026-11-30 22:53 ` [PATCH 3/3] firmware_loader: Annotate mandatory fw_upload_ops " Ian Rogers
2026-12-01  8:35   ` Johan Hovold

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®