public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] firmware: arm_scmi: Support loop control in quirk code snippets
@ 2026-03-16 15:34 Geert Uytterhoeven
  2026-03-16 15:55 ` Cristian Marussi
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Geert Uytterhoeven @ 2026-03-16 15:34 UTC (permalink / raw)
  To: Sudeep Holla, Cristian Marussi
  Cc: arm-scmi, linux-arm-kernel, linux-renesas-soc, Geert Uytterhoeven

Each SCMI firmware quirk contains a code snippet, which handles the
quirk, and has full access to the surrounding context.  When this
context is (part of) a loop body, the code snippet may want to use loop
control statements like "break" and "continue".  Unfortunately the
SCMI_QUIRK() macro implementation contains a dummy loop, taking
precedence over any outer loops.  Hence quirk code cannot use loop
control statements, but has to resort to polluting the surrounding
context with a label, and use goto.

Fix this by replacing the "do { ... } while (0)" construct in the
SCMI_QUIRK() implementation by "({ ... })".

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
Example:

    #define QUIRK_EXAMPLE					\
	    ({							\
		    if (ret == -EOPNOTSUPP)			\
			    continue;				\
	    })

    for (unsigned int i = 0; i < n; i++) {
	    ret = foo(handle, i);
	    SCMI_QUIRK(example_quirk, QUIRK_EXAMPLE);
	    if (ret)
		    return ret;

	    ret = bar(handle, i);
	    if (ret)
		    return ret;
    }
---
 drivers/firmware/arm_scmi/quirks.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/firmware/arm_scmi/quirks.h b/drivers/firmware/arm_scmi/quirks.h
index a71fde85a5272aff..d8ba60b956522d04 100644
--- a/drivers/firmware/arm_scmi/quirks.h
+++ b/drivers/firmware/arm_scmi/quirks.h
@@ -20,10 +20,10 @@
  * named as _qn.
  */
 #define SCMI_QUIRK(_qn, _blk)						\
-	do {								\
+	({								\
 		if (static_branch_unlikely(&(scmi_quirk_ ## _qn)))	\
 			(_blk);						\
-	} while (0)
+	})
 
 void scmi_quirks_initialize(void);
 void scmi_quirks_enable(struct device *dev, const char *vend,
@@ -34,10 +34,10 @@ void scmi_quirks_enable(struct device *dev, const char *vend,
 #define DECLARE_SCMI_QUIRK(_qn)
 /* Force quirks compilation even when SCMI Quirks are disabled */
 #define SCMI_QUIRK(_qn, _blk)						\
-	do {								\
+	({								\
 		if (0)							\
 			(_blk);						\
-	} while (0)
+	})
 
 static inline void scmi_quirks_initialize(void) { }
 static inline void scmi_quirks_enable(struct device *dev, const char *vend,
-- 
2.43.0



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

end of thread, other threads:[~2026-03-18 16:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-16 15:34 [PATCH] firmware: arm_scmi: Support loop control in quirk code snippets Geert Uytterhoeven
2026-03-16 15:55 ` Cristian Marussi
2026-03-16 16:01   ` Geert Uytterhoeven
2026-03-16 16:53 ` Cristian Marussi
2026-03-17  7:25 ` Peng Fan
2026-03-18 16:27 ` Sudeep Holla

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox