diff mbox series

[v2,35/35] sh: mach-x3proto: rework ilsel_enable()

Message ID 20231203193307.542794-34-yury.norov@gmail.com (mailing list archive)
State New
Headers show
Series bitops: add atomic find_bit() operations | expand

Commit Message

Yury Norov Dec. 3, 2023, 7:33 p.m. UTC
Fix opencoded find_and_set_bit(), which also suppresses potential
KCSAN warning.

CC: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
 arch/sh/boards/mach-x3proto/ilsel.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Geert Uytterhoeven Jan. 19, 2024, 8:48 a.m. UTC | #1
On Sun, Dec 3, 2023 at 8:34 PM Yury Norov <yury.norov@gmail.com> wrote:
> Fix opencoded find_and_set_bit(), which also suppresses potential
> KCSAN warning.
>
> CC: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
> Signed-off-by: Yury Norov <yury.norov@gmail.com>

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

> --- a/arch/sh/boards/mach-x3proto/ilsel.c
> +++ b/arch/sh/boards/mach-x3proto/ilsel.c
> @@ -99,8 +99,8 @@ int ilsel_enable(ilsel_source_t set)
>         }
>
>         do {
> -               bit = find_first_zero_bit(&ilsel_level_map, ILSEL_LEVELS);
> -       } while (test_and_set_bit(bit, &ilsel_level_map));
> +               bit = find_and_set_bit(&ilsel_level_map, ILSEL_LEVELS);
> +       } while (bit >= ILSEL_LEVELS);
>
>         __ilsel_enable(set, bit);

BTW, I don't think the old code worked as intended: the first time no
free bit is found, bit would have been ILSEL_LEVELS, and
test_and_set_bit() would have returned false, thus terminating the loop,
and continuing with an out-of-range bit value?  Hence to work correctly,
bit ILSEL_LEVELS of ilsel_level_map should have been initialized to one?
Or am I missing something?

The new code does not have that issue.

Anyway, this should probably never happen in real life.

Gr{oetje,eeting}s,

                        Geert
diff mbox series

Patch

diff --git a/arch/sh/boards/mach-x3proto/ilsel.c b/arch/sh/boards/mach-x3proto/ilsel.c
index f0d5eb41521a..7fadc479a80b 100644
--- a/arch/sh/boards/mach-x3proto/ilsel.c
+++ b/arch/sh/boards/mach-x3proto/ilsel.c
@@ -99,8 +99,8 @@  int ilsel_enable(ilsel_source_t set)
 	}
 
 	do {
-		bit = find_first_zero_bit(&ilsel_level_map, ILSEL_LEVELS);
-	} while (test_and_set_bit(bit, &ilsel_level_map));
+		bit = find_and_set_bit(&ilsel_level_map, ILSEL_LEVELS);
+	} while (bit >= ILSEL_LEVELS);
 
 	__ilsel_enable(set, bit);