Skip to contentSkip to conversation

jump_label: avoid unneeded casts in STATIC_KEY_INIT_{TRUE,FALSE}

PATCH Applied Masahiro Yamada 4 participants 6 messages Feb 13, 2022 – Feb 18, 2022 Static branch/call

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 jump_label: avoid unneeded casts in STATIC_KEY_INIT_{TRUE,FALSE}

Commit 3821fd35b58d ("jump_label: Reduce the size of struct static_key") introduced the union to struct static_key.

It is more natual to set JUMP_TYPE_* to the .type field without casting.

---

 include/linux/jump_label.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/jump_label.h +2 -2
index 48b9b2a82767..6924e6837e6d 100644
@@ -251,10 +251,10 @@ extern void static_key_disable_cpuslocked(struct static_key *key);
  */
 #define STATIC_KEY_INIT_TRUE					\
 	{ .enabled = { 1 },					\
-	  { .entries = (void *)JUMP_TYPE_TRUE } }
+	  { .type = JUMP_TYPE_TRUE } }
 #define STATIC_KEY_INIT_FALSE					\
 	{ .enabled = { 0 },					\
-	  { .entries = (void *)JUMP_TYPE_FALSE } }
+	  { .type = JUMP_TYPE_FALSE } }
 
 #else  /* !CONFIG_JUMP_LABEL */
 
Signature · 1 line
2.32.0
#1 lore raw

PATCH 2/2 jump_label: refactor #ifdef of struct static_key

Move #ifdef CONFIG_JUMP_LABEL inside the struct static_key.

---

 include/linux/jump_label.h | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
include/linux/jump_label.h +2 -7
index 6924e6837e6d..107751cc047b 100644
@@ -82,10 +82,9 @@ extern bool static_key_initialized;
 				    "%s(): static key '%pS' used before call to jump_label_init()", \
 				    __func__, (key))
 
-#ifdef CONFIG_JUMP_LABEL
-
 struct static_key {
 	atomic_t enabled;
+#ifdef CONFIG_JUMP_LABEL
 /*
  * Note:
  *   To make anonymous unions work with old compilers, the static
@@ -104,13 +103,9 @@ struct static_key {
 		struct jump_entry *entries;
 		struct static_key_mod *next;
 	};
+#endif	/* CONFIG_JUMP_LABEL */
 };
 
-#else
-struct static_key {
-	atomic_t enabled;
-};
-#endif	/* CONFIG_JUMP_LABEL */
 #endif /* __ASSEMBLY__ */
 
 #ifdef CONFIG_JUMP_LABEL
Signature · 1 line
2.32.0
#2 lore raw

[tip: locking/core] jump_label: Refactor #ifdef of struct static_key

The following commit has been merged into the locking/core branch of tip:

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     cd27ccfc727e99352321c0c75012ab9c5a90321e
Gitweb:        https://git.kernel.org/tip/cd27ccfc727e99352321c0c75012ab9c5a90321e
Author:        Masahiro Yamada <[email protected]>
AuthorDate:    Mon, 14 Feb 2022 01:57:17 +09:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Wed, 16 Feb 2022 15:57:58 +01:00

jump_label: Refactor #ifdef of struct static_key

Move #ifdef CONFIG_JUMP_LABEL inside the struct static_key.

---
 include/linux/jump_label.h |  9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
include/linux/jump_label.h +2 -7
index 6924e68..107751c 100644
@@ -82,10 +82,9 @@ extern bool static_key_initialized;
 				    "%s(): static key '%pS' used before call to jump_label_init()", \
 				    __func__, (key))
 
-#ifdef CONFIG_JUMP_LABEL
-
 struct static_key {
 	atomic_t enabled;
+#ifdef CONFIG_JUMP_LABEL
 /*
  * Note:
  *   To make anonymous unions work with old compilers, the static
@@ -104,13 +103,9 @@ struct static_key {
 		struct jump_entry *entries;
 		struct static_key_mod *next;
 	};
+#endif	/* CONFIG_JUMP_LABEL */
 };
 
-#else
-struct static_key {
-	atomic_t enabled;
-};
-#endif	/* CONFIG_JUMP_LABEL */
 #endif /* __ASSEMBLY__ */
 
 #ifdef CONFIG_JUMP_LABEL
maintainer Acked-by on v1 2/2
#3 lore raw

Re: [PATCH 2/2] jump_label: refactor #ifdef of struct static_key

In reply to Masahiro Yamada
Quoted 29 lines · Masahiro Yamada

Move #ifdef CONFIG_JUMP_LABEL inside the struct static_key.

---

 include/linux/jump_label.h | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
include/linux/jump_label.h +2 -2
index 6924e6837e6d..107751cc047b 100644
@@ -82,10 +82,9 @@ extern bool static_key_initialized;
 				    "%s(): static key '%pS' used before call to jump_label_init()", \
 				    __func__, (key))
 
-#ifdef CONFIG_JUMP_LABEL
-
 struct static_key {
 	atomic_t enabled;
+#ifdef CONFIG_JUMP_LABEL
 /*
  * Note:
  *   To make anonymous unions work with old compilers, the static
@@ -104,13 +103,9 @@ struct static_key {
 		struct jump_entry *entries;
 		struct static_key_mod *next;
 	};
+#endif	/* CONFIG_JUMP_LABEL */

include/linux/jump_label.h struct static_key { · line 111

Quoted 10 lines
include/linux/jump_label.h +0 -5
 };
 
-#else
-struct static_key {
-	atomic_t enabled;
-};
-#endif	/* CONFIG_JUMP_LABEL */
 #endif /* __ASSEMBLY__ */
 
 #ifdef CONFIG_JUMP_LABEL

These two cleanups look fine to me.

Thanks,

-Jason

#4 lore raw

Re: [PATCH 2/2] jump_label: refactor #ifdef of struct static_key

Quoted 39 lines · Jason Baron
Quoted 38 lines · Masahiro Yamada

Move #ifdef CONFIG_JUMP_LABEL inside the struct static_key.

---

 include/linux/jump_label.h | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
include/linux/jump_label.h +2 -7
index 6924e6837e6d..107751cc047b 100644
@@ -82,10 +82,9 @@ extern bool static_key_initialized;
 				    "%s(): static key '%pS' used before call to jump_label_init()", \
 				    __func__, (key))
 
-#ifdef CONFIG_JUMP_LABEL
-
 struct static_key {
 	atomic_t enabled;
+#ifdef CONFIG_JUMP_LABEL
 /*
  * Note:
  *   To make anonymous unions work with old compilers, the static
@@ -104,13 +103,9 @@ struct static_key {
 		struct jump_entry *entries;
 		struct static_key_mod *next;
 	};
+#endif	/* CONFIG_JUMP_LABEL */
 };
 
-#else
-struct static_key {
-	atomic_t enabled;
-};
-#endif	/* CONFIG_JUMP_LABEL */
 #endif /* __ASSEMBLY__ */
 
Quoted 6 lines

include/linux/jump_label.h struct static_key { · line 111

Quoted 1 line
include/linux/jump_label.h +0 -0
 #ifdef CONFIG_JUMP_LABEL

These two cleanups look fine to me.

Both look fine to me as well. For both patches:

Signature · 1 line
Josh
#5 lore raw

[tip: locking/core] jump_label: Avoid unneeded casts in STATIC_KEY_INIT_{TRUE,FALSE}

In reply to Masahiro Yamada
The following commit has been merged into the locking/core branch of tip:

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     fe65deb56e552a8c9bf7f27860dbdeac12a36116
Gitweb:        https://git.kernel.org/tip/fe65deb56e552a8c9bf7f27860dbdeac12a36116
Author:        Masahiro Yamada <[email protected]>
AuthorDate:    Mon, 14 Feb 2022 01:57:16 +09:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Wed, 16 Feb 2022 15:57:58 +01:00

jump_label: Avoid unneeded casts in STATIC_KEY_INIT_{TRUE,FALSE}

Commit 3821fd35b58d ("jump_label: Reduce the size of struct static_key") introduced the union to struct static_key.

It is more natual to set JUMP_TYPE_* to the .type field without casting.

---
 include/linux/jump_label.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/jump_label.h +2 -2
index 48b9b2a..6924e68 100644
@@ -251,10 +251,10 @@ extern void static_key_disable_cpuslocked(struct static_key *key);
  */
 #define STATIC_KEY_INIT_TRUE					\
 	{ .enabled = { 1 },					\
-	  { .entries = (void *)JUMP_TYPE_TRUE } }
+	  { .type = JUMP_TYPE_TRUE } }
 #define STATIC_KEY_INIT_FALSE					\
 	{ .enabled = { 0 },					\
-	  { .entries = (void *)JUMP_TYPE_FALSE } }
+	  { .type = JUMP_TYPE_FALSE } }
 
 #else  /* !CONFIG_JUMP_LABEL */