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

Geert Uytterhoeven posted 52 patches 2 years, 3 months ago
There is a newer version of this series
[PATCH 25/52] m68k: apollo: Replace set but not used variable by READ_ONCE()
Posted by Geert Uytterhoeven 2 years, 3 months ago
When building with W=1:

    arch/m68k/apollo/config.c: In function ‘dn_timer_int’:
    arch/m68k/apollo/config.c:171:32: warning: variable ‘x’ set but not used [-Wunused-but-set-variable]
      149 |         volatile unsigned char x;
	  |                                ^

Fix this by using READ_ONCE(), and removing the variable.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 arch/m68k/apollo/config.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/m68k/apollo/config.c b/arch/m68k/apollo/config.c
index 0e6801eecbaf6361..fef9b8a1be673bad 100644
--- 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;
 }
-- 
2.34.1

Re: [PATCH 25/52] m68k: apollo: Replace set but not used variable by READ_ONCE()
Posted by Finn Thain 2 years, 3 months ago
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.
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));
Re: [PATCH 25/52] m68k: apollo: Replace set but not used variable by READ_ONCE()
Posted by Geert Uytterhoeven 2 years, 3 months ago
Hi Finn,

On Fri, Sep 8, 2023 at 1:37 AM Finn Thain <fthain@linux-m68k.org> 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@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
Re: [PATCH 25/52] m68k: apollo: Replace set but not used variable by READ_ONCE()
Posted by Arnd Bergmann 2 years, 3 months ago
On Fri, Sep 8, 2023, at 08:51, Geert Uytterhoeven wrote:
>
> On Fri, Sep 8, 2023 at 1:37 AM Finn Thain <fthain@linux-m68k.org> 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.

I think ideally you'd want apollo_timer or IO_BASE to be marked __iomem
and passed to readb() instead. OTOH, I don't think anyone actually
cares about apollo, so your version is probably good enough.

     Arnd