diff mbox series

[v4,03/42] linker_lists: Allow use in data structures

Message ID 20210315172537.v4.3.If4b6aad281b0987643878ab428b5120dbdbbecfb@changeid
State Accepted
Commit 851144350b6ff1d4982b9af2f9b0fe48aed24b3c
Delegated to: Simon Glass
Headers show
Series dm: Implement OF_PLATDATA_INST in driver model (part E) | expand

Commit Message

Simon Glass March 15, 2021, 4:25 a.m. UTC
At present linker lists are designed for use in code. They make use of
statements within expressions ({...}), for example.

It is possible to generate a reference to a linker_list entry that can
be used in data structures, where such features are not permitted. It
requires that the reference first be declared as extern. In other
words the existing macro needs to be split into two parts.

Add new macros to support this.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v3)

Changes in v3:
- Drop the decl() variant since it is just as easy to use extern

 include/linker_lists.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Simon Glass March 17, 2021, 1:29 a.m. UTC | #1
At present linker lists are designed for use in code. They make use of
statements within expressions ({...}), for example.

It is possible to generate a reference to a linker_list entry that can
be used in data structures, where such features are not permitted. It
requires that the reference first be declared as extern. In other
words the existing macro needs to be split into two parts.

Add new macros to support this.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v3)

Changes in v3:
- Drop the decl() variant since it is just as easy to use extern

 include/linker_lists.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Applied to u-boot-dm/next, thanks!
diff mbox series

Patch

diff --git a/include/linker_lists.h b/include/linker_lists.h
index fd98ecd297c..0ca30da4172 100644
--- a/include/linker_lists.h
+++ b/include/linker_lists.h
@@ -211,6 +211,18 @@ 
 		_ll_result;						\
 	})
 
+/**
+ * ll_entry_ref() - Get a reference to a linker-generated array entry
+ *
+ * Once ll_entry_decl() has been used to declare the reference, this macro
+ * allows the entry to be accessed.
+ *
+ * This is like ll_entry_get(), but without the extra code, so it is suitable
+ * for putting into data structures.
+ */
+#define ll_entry_ref(_type, _name, _list)				\
+	((_type *)&_u_boot_list_2_##_list##_2_##_name)
+
 /**
  * ll_start() - Point to first entry of first linker-generated array
  * @_type:	Data type of the entry