mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/4] base: use initcalls instead of linker lists to register classes
Date: Tue, 16 Jul 2024 13:57:09 +0200	[thread overview]
Message-ID: <20240716115711.1956907-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240716115711.1956907-1-a.fatoum@pengutronix.de>

BAREBOX_CLASSES is the only member of RO_DATA_SECTION that's indeed not
read-only. This will lead to issues when we start making to mark that
section read-only on sandbox.

Replace the linker list thus with an initcall.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/base/class.c              | 20 +-------------------
 include/asm-generic/barebox.lds.h |  7 -------
 include/device.h                  | 20 ++++++++++++++------
 3 files changed, 15 insertions(+), 32 deletions(-)

diff --git a/drivers/base/class.c b/drivers/base/class.c
index fd7d6b2d7a29..5fbbae0ff025 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -5,11 +5,9 @@
 
 LIST_HEAD(class_list);
 
-static int class_register(struct class *class)
+void class_register(struct class *class)
 {
 	list_add_tail(&class->list, &class_list);
-
-	return 0;
 }
 
 int class_add_device(struct class *class, struct device *dev)
@@ -23,19 +21,3 @@ void class_remove_device(struct class *class, struct device *dev)
 {
 	list_del(&dev->class_list);
 }
-
-extern struct class __barebox_class_start[];
-extern struct class __barebox_class_end[];
-
-static int register_classes(void)
-{
-	struct class *c;
-
-	for (c = __barebox_class_start;
-	     c != __barebox_class_end;
-	     c++)
-		class_register(c);
-
-	return 0;
-}
-device_initcall(register_classes);
diff --git a/include/asm-generic/barebox.lds.h b/include/asm-generic/barebox.lds.h
index 8bbf5907cdfd..d3736ebaed59 100644
--- a/include/asm-generic/barebox.lds.h
+++ b/include/asm-generic/barebox.lds.h
@@ -70,12 +70,6 @@
 	KEEP(*(SORT_BY_NAME(.barebox_magicvar*)))	\
 	__barebox_magicvar_end = .;
 
-#define BAREBOX_CLASSES				\
-	STRUCT_ALIGN();				\
-	__barebox_class_start = .;		\
-	KEEP(*(SORT_BY_NAME(.barebox_class*)))	\
-	__barebox_class_end = .;
-
 #define BAREBOX_CLK_TABLE			\
 	STRUCT_ALIGN();				\
 	__clk_of_table_start = .;		\
@@ -144,7 +138,6 @@
 	BAREBOX_SYMS				\
 	KERNEL_CTORS()				\
 	BAREBOX_MAGICVARS			\
-	BAREBOX_CLASSES				\
 	BAREBOX_CLK_TABLE			\
 	BAREBOX_DTB				\
 	BAREBOX_RSA_KEYS			\
diff --git a/include/device.h b/include/device.h
index 8550544ca807..4c76da2f82dd 100644
--- a/include/device.h
+++ b/include/device.h
@@ -7,6 +7,8 @@
 #define DEVICE_H
 
 #include <linux/types.h>
+#include <linux/list.h>
+#include <init.h>
 
 enum dev_dma_coherence {
 	DEV_DMA_COHERENCE_DEFAULT = 0,
@@ -110,12 +112,18 @@ struct class {
 	struct list_head list;
 };
 
-#define DEFINE_DEV_CLASS(_name, _classname)					\
-	struct class _name __ll_elem(.barebox_class_##_name) 			\
-	__aligned(__alignof__(struct class)) = {				\
-		.name = _classname,						\
-		.devices = LIST_HEAD_INIT(_name.devices),			\
-	}
+void class_register(struct class *class);
+
+#define DEFINE_DEV_CLASS(_name, _classname)			\
+	struct class _name = {					\
+		.name = _classname,				\
+		.devices = LIST_HEAD_INIT(_name.devices),	\
+	};							\
+	static int register_##_name(void) {			\
+		class_register(&_name);				\
+		return 0;					\
+	}							\
+	pure_initcall(register_##_name);
 
 int class_add_device(struct class *class, struct device *dev);
 void class_remove_device(struct class *class, struct device *dev);
-- 
2.39.2




  reply	other threads:[~2024-07-16 11:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-16 11:57 [PATCH 1/4] init: mark initcalls const Ahmad Fatoum
2024-07-16 11:57 ` Ahmad Fatoum [this message]
2024-07-16 11:57 ` [PATCH 3/4] watchdog: remove needless error checking for device parameter Ahmad Fatoum
2024-07-16 11:57 ` [PATCH 4/4] watchdog: factor out device registration into common class code Ahmad Fatoum
2024-07-19  6:26 ` [PATCH 1/4] init: mark initcalls const Sascha Hauer

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=20240716115711.1956907-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.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