mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Brian Masney <bmasney@redhat.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	 "Rafael J. Wysocki" <rafael@kernel.org>,
	Danilo Krummrich <dakr@kernel.org>,
	 Bjorn Andersson <andersson@kernel.org>,
	Stephen Boyd <sboyd@kernel.org>,
	 Jerome Brunet <jbrunet+clk@baylibre.com>,
	 Geert Uytterhoeven <geert+renesas@glider.be>
Cc: driver-core@lists.linux.dev, linux-kernel@vger.kernel.org,
	 linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org,
	 linux-renesas-soc@vger.kernel.org,
	Brian Masney <bmasney@redhat.com>
Subject: [PATCH 1/4] driver: core: add subsys_driver() macro
Date: Tue, 08 Sep 2026 13:47:18 -0400	[thread overview]
Message-ID: <20260908-subsys_initcall-v1-1-cbccf4cd4288@redhat.com> (raw)
In-Reply-To: <20260908-subsys_initcall-v1-0-cbccf4cd4288@redhat.com>

Add a new macro subsys_driver() to eliminate some boilerplate code in
drivers that need to register earlier in the boot at the subsys_initcall
level.

Signed-off-by: Brian Masney <bmasney@redhat.com>
Assisted-by: Claude:claude-opus-4-8
---
 include/linux/device/driver.h | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/include/linux/device/driver.h b/include/linux/device/driver.h
index 768a1334c0a1..29fbc01ef06f 100644
--- a/include/linux/device/driver.h
+++ b/include/linux/device/driver.h
@@ -297,4 +297,35 @@ static int __init __driver##_init(void) \
 } \
 device_initcall(__driver##_init);
 
+/**
+ * subsys_driver() - Helper macro for drivers that don't do anything special
+ * in init/exit but have to register earlier, at subsys_initcall level, when
+ * built in. This eliminates a lot of boilerplate. Each driver may only use
+ * this macro once, and calling it replaces the init/exit boilerplate.
+ *
+ * @__driver: driver name
+ * @__register: register function for this driver type
+ * @__unregister: unregister function for this driver type
+ * @...: Additional arguments to be passed to __register and __unregister.
+ *
+ * This is meant to be a direct parallel of module_driver() above, but with
+ * the init call promoted to subsys_initcall() for built-in drivers so they
+ * are available earlier during boot. When built as a module subsys_initcall()
+ * collapses to module_init() and the normal module init/exit paths are used.
+ *
+ * Use this macro to construct bus specific macros for registering drivers,
+ * and do not use it on its own.
+ */
+#define subsys_driver(__driver, __register, __unregister, ...) \
+static int __init __driver##_init(void) \
+{ \
+	return __register(&(__driver), ##__VA_ARGS__); \
+} \
+subsys_initcall(__driver##_init) \
+static void __exit __driver##_exit(void) \
+{ \
+	__unregister(&(__driver), ##__VA_ARGS__); \
+} \
+module_exit(__driver##_exit)
+
 #endif	/* _DEVICE_DRIVER_H_ */

-- 
2.55.0


  reply	other threads:[~2026-09-08 17:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-08 17:47 [PATCH 0/4] driver: core: add subsys_platform_driver() to reduce boilerplate code in drivers Brian Masney
2026-09-08 17:47 ` Brian Masney [this message]
2026-09-09 11:44   ` [PATCH 1/4] driver: core: add subsys_driver() macro Abel Vesa
2026-09-09 15:14   ` Geert Uytterhoeven
2026-09-08 17:47 ` [PATCH 2/4] driver: core: platform: add subsys_platform_driver() macro Brian Masney
2026-09-09 11:44   ` Abel Vesa
2026-09-09 15:16   ` Geert Uytterhoeven
2026-09-08 17:47 ` [PATCH 3/4] clk: qcom: convert drivers over to use subsys_platform_driver() Brian Masney
2026-09-09 11:25   ` Konrad Dybcio
2026-09-09 11:45   ` Abel Vesa
2026-09-09 12:10     ` Brian Masney
2026-09-08 17:47 ` [PATCH 4/4] clk: renesas: " Brian Masney
2026-09-09 15:19   ` Geert Uytterhoeven
2026-09-09 14:40 ` [PATCH 0/4] driver: core: add subsys_platform_driver() to reduce boilerplate code in drivers Pankaj Patil

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=20260908-subsys_initcall-v1-1-cbccf4cd4288@redhat.com \
    --to=bmasney@redhat.com \
    --cc=andersson@kernel.org \
    --cc=dakr@kernel.org \
    --cc=driver-core@lists.linux.dev \
    --cc=geert+renesas@glider.be \
    --cc=gregkh@linuxfoundation.org \
    --cc=jbrunet+clk@baylibre.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=sboyd@kernel.org \
    /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®