Re: [PATCH 25/52] m68k: apollo: Replace set but not used variable by READ_ONCE()

From: Geert Uytterhoeven
Date: Fri Sep 08 2023 - 02:52:02 EST


Hi Finn,

On Fri, Sep 8, 2023 at 1:37 AM Finn Thain <fthain@xxxxxxxxxxxxxx> wrote:
> On Thu, 7 Sep 2023, Geert Uytterhoeven wrote:
> > --- a/arch/m68k/apollo/config.c
> > +++ b/arch/m68k/apollo/config.c
> > @@ -146,13 +146,11 @@ void __init config_apollo(void)
> >
> > irqreturn_t dn_timer_int(int irq, void *dev_id)
> > {
> > - volatile unsigned char x;
> > -
> > legacy_timer_tick(1);
> > timer_heartbeat();
> >
> > - x = *(volatile unsigned char *)(apollo_timer + 3);
> > - x = *(volatile unsigned char *)(apollo_timer + 5);
> > + READ_ONCE(*(volatile unsigned char *)(apollo_timer + 3));
> > + READ_ONCE(*(volatile unsigned char *)(apollo_timer + 5));
> >
> > return IRQ_HANDLED;
> > }
> >
>
> I believe the volatile cast is redundant here, as READ_ONCE does that.

Yes it does. I didn't drop the volatile out of fear of introducing
some higher W-level warning about casting away volatility, but upon
closer look, the apollo_timer definition itself does not use volatile.

> Perhaps the remaining cast could be deduplicated like so:
>
> - volatile unsigned char x;
> + unsigned char *at = (unsigned char *)apollo_timer;
>
> legacy_timer_tick(1);
> timer_heartbeat();
>
> - x = *(volatile unsigned char *)(apollo_timer + 3);
> - x = *(volatile unsigned char *)(apollo_timer + 5);
> + READ_ONCE(*(at + 3));
> + READ_ONCE(*(at + 5));

Thanks for the suggestion!

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

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