Re: [PATCH 2/2] platform: turris: use ffs() instead of __bf_shf()
From: Marek Behún
Date: Sun Apr 06 2025 - 16:12:28 EST
On Fri, Apr 04, 2025 at 03:55:26PM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@xxxxxxxx>
>
> __bf_shf() on a 64-bit variable causes a link failure during
> compile-testing:
>
> drivers-platform-cznic-turris-omnia-mcu-gpio.c:(.text):undefined-reference-to-__ffsdi2
>
> Open-code this using ffs()-1, which has the same result but avoids
> the library call.
>
> Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
> ---
> drivers/platform/cznic/turris-omnia-mcu-gpio.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/platform/cznic/turris-omnia-mcu-gpio.c b/drivers/platform/cznic/turris-omnia-mcu-gpio.c
> index 932383f7491a..c2df24ea8686 100644
> --- a/drivers/platform/cznic/turris-omnia-mcu-gpio.c
> +++ b/drivers/platform/cznic/turris-omnia-mcu-gpio.c
> @@ -1104,7 +1104,7 @@ int omnia_mcu_request_irq(struct omnia_mcu *mcu, u32 spec,
> if (!spec)
> return -EINVAL;
>
> - irq_idx = omnia_int_to_gpio_idx[__bf_shf(spec)];
> + irq_idx = omnia_int_to_gpio_idx[ffs(spec) - 1];
Weird that __bf_shf() procudes this error on non-constant input.
But I guess a variant of ffs() makes more sense semantically, since the
spec arugment isn't semantically a bitfield.
Shouldn't we consider using __ffs(), though?
With __ffs() we can drop the "- 1", i.e.:
irq_idx = omnia_int_to_gpio_idx[__ffs(spec)];
Both __ffs() and ffs() are used within the drivers/ subdir.
Of the 649 usages of ffs(), 482 are ffs(x) - 1, so they could be
converted to __ffs(x).
But I don't particularly care.
Marek