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

* Re: [PATCH] firmware: arm_scmi: Support loop control in quirk code snippets
  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
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Cristian Marussi @ 2026-03-16 15:55 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Sudeep Holla, Cristian Marussi, arm-scmi, linux-arm-kernel,
	linux-renesas-soc

On Mon, Mar 16, 2026 at 04:34:40PM +0100, Geert Uytterhoeven wrote:
> 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.

Hi Geert,

I was just now writing the quirk for the Renesas issue and realized
this limitation :P

Do you want me to pick this up with the quirk template for Renesas issue
that I am writing and post all in V3, or you have already the quirk too ?

Thanks,
Cristian


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

* Re: [PATCH] firmware: arm_scmi: Support loop control in quirk code snippets
  2026-03-16 15:55 ` Cristian Marussi
@ 2026-03-16 16:01   ` Geert Uytterhoeven
  0 siblings, 0 replies; 6+ messages in thread
From: Geert Uytterhoeven @ 2026-03-16 16:01 UTC (permalink / raw)
  To: Cristian Marussi
  Cc: Sudeep Holla, arm-scmi, linux-arm-kernel, linux-renesas-soc

Hi Christian,

On Mon, 16 Mar 2026 at 16:55, Cristian Marussi <cristian.marussi@arm.com> wrote:
> On Mon, Mar 16, 2026 at 04:34:40PM +0100, Geert Uytterhoeven wrote:
> > 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.
>
> I was just now writing the quirk for the Renesas issue and realized
> this limitation :P
>
> Do you want me to pick this up with the quirk template for Renesas issue
> that I am writing and post all in V3, or you have already the quirk too ?

I do have a preliminary quirk, but I don't think it is ready for
merging yet.  Getting this limitation relaxed is something that can
already move forward, though.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds


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

* Re: [PATCH] firmware: arm_scmi: Support loop control in quirk code snippets
  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:53 ` Cristian Marussi
  2026-03-17  7:25 ` Peng Fan
  2026-03-18 16:27 ` Sudeep Holla
  3 siblings, 0 replies; 6+ messages in thread
From: Cristian Marussi @ 2026-03-16 16:53 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Sudeep Holla, Cristian Marussi, arm-scmi, linux-arm-kernel,
	linux-renesas-soc

On Mon, Mar 16, 2026 at 04:34:40PM +0100, Geert Uytterhoeven wrote:
> 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.

Hi,

indeed...good catch, thanks for this.
I think, no need to backport as Fixes since existing quirks are NOT
impacted.

LGTM.
Reviewed-by: Cristian Marussi <cristian.marussi@arm.com>

Thanks,
Cristian


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

* Re: [PATCH] firmware: arm_scmi: Support loop control in quirk code snippets
  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:53 ` Cristian Marussi
@ 2026-03-17  7:25 ` Peng Fan
  2026-03-18 16:27 ` Sudeep Holla
  3 siblings, 0 replies; 6+ messages in thread
From: Peng Fan @ 2026-03-17  7:25 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Sudeep Holla, Cristian Marussi, arm-scmi, linux-arm-kernel,
	linux-renesas-soc

On Mon, Mar 16, 2026 at 04:34:40PM +0100, Geert Uytterhoeven wrote:
>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>

Reviewed-by: Peng Fan <peng.fan@nxp.com>


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

* Re: [PATCH] firmware: arm_scmi: Support loop control in quirk code snippets
  2026-03-16 15:34 [PATCH] firmware: arm_scmi: Support loop control in quirk code snippets Geert Uytterhoeven
                   ` (2 preceding siblings ...)
  2026-03-17  7:25 ` Peng Fan
@ 2026-03-18 16:27 ` Sudeep Holla
  3 siblings, 0 replies; 6+ messages in thread
From: Sudeep Holla @ 2026-03-18 16:27 UTC (permalink / raw)
  To: Cristian Marussi, Geert Uytterhoeven
  Cc: Sudeep Holla, arm-scmi, linux-arm-kernel, linux-renesas-soc

On Mon, 16 Mar 2026 16:34:40 +0100, Geert Uytterhoeven wrote:
> 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.
> 
> [...]

Applied to sudeep.holla/linux (for-next/scmi/updates), thanks!

[1/1] firmware: arm_scmi: Support loop control in quirk code snippets
      https://git.kernel.org/sudeep.holla/c/0a7ec808abec
--
Regards,
Sudeep



^ permalink raw reply	[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