diff mbox series

[9/9] hw/timer/renesas_tmr: silence the compiler warnings

Message ID 20201028041819.2169003-10-kuhn.chenqun@huawei.com
State New
Headers show
Series silence the compiler warnings | expand

Commit Message

Chen Qun Oct. 28, 2020, 4:18 a.m. UTC
When using -Wimplicit-fallthrough in our CFLAGS, the compiler showed warning:
../hw/timer/renesas_tmr.c: In function ‘tmr_read’:
../hw/timer/renesas_tmr.c:221:19: warning: this statement may fall through [-Wimplicit-fallthrough=]
  221 |         } else if (ch == 0) {i
      |                   ^
../hw/timer/renesas_tmr.c:224:5: note: here
  224 |     case A_TCORB:
      |     ^~~~

Add the corresponding "fall through" comment to fix it.

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com>
---
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Magnus Damm <magnus.damm@gmail.com>
---
 hw/timer/renesas_tmr.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Philippe Mathieu-Daudé Oct. 28, 2020, 9:59 a.m. UTC | #1
On 10/28/20 5:18 AM, Chen Qun wrote:
> When using -Wimplicit-fallthrough in our CFLAGS, the compiler showed warning:
> ../hw/timer/renesas_tmr.c: In function ‘tmr_read’:
> ../hw/timer/renesas_tmr.c:221:19: warning: this statement may fall through [-Wimplicit-fallthrough=]
>   221 |         } else if (ch == 0) {i
>       |                   ^
> ../hw/timer/renesas_tmr.c:224:5: note: here
>   224 |     case A_TCORB:
>       |     ^~~~
> 
> Add the corresponding "fall through" comment to fix it.
> 
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com>
> ---
> Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
> Cc: Magnus Damm <magnus.damm@gmail.com>
> ---
>  hw/timer/renesas_tmr.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/hw/timer/renesas_tmr.c b/hw/timer/renesas_tmr.c
> index 446f2eacdd..e03a8155b2 100644
> --- a/hw/timer/renesas_tmr.c
> +++ b/hw/timer/renesas_tmr.c
> @@ -221,6 +221,7 @@ static uint64_t tmr_read(void *opaque, hwaddr addr, unsigned size)
>          } else if (ch == 0) {
>              return concat_reg(tmr->tcora);
>          }
> +        /* fall through */
>      case A_TCORB:
>          if (size == 1) {
>              return tmr->tcorb[ch];
> 

You fixed A_TCORA but not A_TCORB...

How the Euler Robot works? Like Coverity?
Thomas Huth Oct. 28, 2020, 3:04 p.m. UTC | #2
On 28/10/2020 10.59, Philippe Mathieu-Daudé wrote:
> On 10/28/20 5:18 AM, Chen Qun wrote:
>> When using -Wimplicit-fallthrough in our CFLAGS, the compiler showed warning:
>> ../hw/timer/renesas_tmr.c: In function ‘tmr_read’:
>> ../hw/timer/renesas_tmr.c:221:19: warning: this statement may fall through [-Wimplicit-fallthrough=]
>>   221 |         } else if (ch == 0) {i
>>       |                   ^
>> ../hw/timer/renesas_tmr.c:224:5: note: here
>>   224 |     case A_TCORB:
>>       |     ^~~~
>>
>> Add the corresponding "fall through" comment to fix it.
>>
>> Reported-by: Euler Robot <euler.robot@huawei.com>
>> Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com>
>> ---
>> Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
>> Cc: Magnus Damm <magnus.damm@gmail.com>
>> ---
>>  hw/timer/renesas_tmr.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/hw/timer/renesas_tmr.c b/hw/timer/renesas_tmr.c
>> index 446f2eacdd..e03a8155b2 100644
>> --- a/hw/timer/renesas_tmr.c
>> +++ b/hw/timer/renesas_tmr.c
>> @@ -221,6 +221,7 @@ static uint64_t tmr_read(void *opaque, hwaddr addr, unsigned size)
>>          } else if (ch == 0) {
>>              return concat_reg(tmr->tcora);
>>          }
>> +        /* fall through */
>>      case A_TCORB:
>>          if (size == 1) {
>>              return tmr->tcorb[ch];
>>
> 
> You fixed A_TCORA but not A_TCORB...

A_TCORB cannot fall through, since it always does a "return" in both
branches of the if-statement.

However, it also looks really odd that A_TCORA falls through to A_TCORB here
and return that register value instead. Is this really intended? Yoshinori,
could you please double-check whether this is a bug here, or intended?

 Thanks,
  Thomas
Peter Maydell Oct. 28, 2020, 8:14 p.m. UTC | #3
On Wed, 28 Oct 2020 at 15:07, Thomas Huth <thuth@redhat.com> wrote:
>
> On 28/10/2020 10.59, Philippe Mathieu-Daudé wrote:
> > On 10/28/20 5:18 AM, Chen Qun wrote:
> >> When using -Wimplicit-fallthrough in our CFLAGS, the compiler showed warning:
> >> ../hw/timer/renesas_tmr.c: In function ‘tmr_read’:
> >> ../hw/timer/renesas_tmr.c:221:19: warning: this statement may fall through [-Wimplicit-fallthrough=]
> >>   221 |         } else if (ch == 0) {i
> >>       |                   ^
> >> ../hw/timer/renesas_tmr.c:224:5: note: here
> >>   224 |     case A_TCORB:
> >>       |     ^~~~
> >>
> >> Add the corresponding "fall through" comment to fix it.
> >>
> >> Reported-by: Euler Robot <euler.robot@huawei.com>
> >> Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com>
> >> ---
> >> Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
> >> Cc: Magnus Damm <magnus.damm@gmail.com>
> >> ---
> >>  hw/timer/renesas_tmr.c | 1 +
> >>  1 file changed, 1 insertion(+)
> >>
> >> diff --git a/hw/timer/renesas_tmr.c b/hw/timer/renesas_tmr.c
> >> index 446f2eacdd..e03a8155b2 100644
> >> --- a/hw/timer/renesas_tmr.c
> >> +++ b/hw/timer/renesas_tmr.c
> >> @@ -221,6 +221,7 @@ static uint64_t tmr_read(void *opaque, hwaddr addr, unsigned size)
> >>          } else if (ch == 0) {
> >>              return concat_reg(tmr->tcora);
> >>          }
> >> +        /* fall through */
> >>      case A_TCORB:
> >>          if (size == 1) {
> >>              return tmr->tcorb[ch];
> >>
> >
> > You fixed A_TCORA but not A_TCORB...
>
> A_TCORB cannot fall through, since it always does a "return" in both
> branches of the if-statement.
>
> However, it also looks really odd that A_TCORA falls through to A_TCORB here
> and return that register value instead. Is this really intended? Yoshinori,
> could you please double-check whether this is a bug here, or intended?

See the discussion in this thread:
https://lore.kernel.org/qemu-devel/CAFEAcA8c2dywr=Zxz1ExAV-48JwFU5vbBDDfA=_KE98XamnXiA@mail.gmail.com/
from when Coverity spotting the fall-through.

I think this cleanup patch from Yoshinori deals with the fall-through
stuff by cleaning up that area of the timer device:
https://lore.kernel.org/qemu-devel/20200711154242.41222-1-ysato@users.sourceforge.jp/
It just needs somebody to code-review it :-)

thanks
-- PMM
Chen Qun Oct. 29, 2020, 8:12 a.m. UTC | #4
> -----Original Message-----
> From: Philippe Mathieu-Daudé [mailto:philippe.mathieu.daude@gmail.com]
> On Behalf Of Philippe Mathieu-Daudé
> Sent: Wednesday, October 28, 2020 6:00 PM
> To: Chenqun (kuhn) <kuhn.chenqun@huawei.com>; qemu-devel@nongnu.org;
> qemu-trivial@nongnu.org
> Cc: Zhanghailiang <zhang.zhanghailiang@huawei.com>; Yoshinori Sato
> <ysato@users.sourceforge.jp>; Magnus Damm <magnus.damm@gmail.com>;
> ganqixin <ganqixin@huawei.com>; Euler Robot <euler.robot@huawei.com>
> Subject: Re: [PATCH 9/9] hw/timer/renesas_tmr: silence the compiler warnings
> 
> On 10/28/20 5:18 AM, Chen Qun wrote:
> > When using -Wimplicit-fallthrough in our CFLAGS, the compiler showed
> warning:
> > ../hw/timer/renesas_tmr.c: In function ‘tmr_read’:
> > ../hw/timer/renesas_tmr.c:221:19: warning: this statement may fall through
> [-Wimplicit-fallthrough=]
> >   221 |         } else if (ch == 0) {i
> >       |                   ^
> > ../hw/timer/renesas_tmr.c:224:5: note: here
> >   224 |     case A_TCORB:
> >       |     ^~~~
> >
> > Add the corresponding "fall through" comment to fix it.
> >
> > Reported-by: Euler Robot <euler.robot@huawei.com>
> > Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com>
> > ---
> > Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
> > Cc: Magnus Damm <magnus.damm@gmail.com>
> > ---
> >  hw/timer/renesas_tmr.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/hw/timer/renesas_tmr.c b/hw/timer/renesas_tmr.c index
> > 446f2eacdd..e03a8155b2 100644
> > --- a/hw/timer/renesas_tmr.c
> > +++ b/hw/timer/renesas_tmr.c
> > @@ -221,6 +221,7 @@ static uint64_t tmr_read(void *opaque, hwaddr addr,
> unsigned size)
> >          } else if (ch == 0) {
> >              return concat_reg(tmr->tcora);
> >          }
> > +        /* fall through */
> >      case A_TCORB:
> >          if (size == 1) {
> >              return tmr->tcorb[ch];
> >
> 
> You fixed A_TCORA but not A_TCORB...
> 
Hi Philippe,
 My first feeling is the same as you when this warning found.
But, the number of branches for A_TCORA and A_TCORB is different.

In A_TCORA case:"} else if (ch == 0) {"
In A_TCORB case:"} else {"

Obviously, A_TCOB have all return values. But A_TCOA is not, it need to fall through or break.

> How the Euler Robot works? Like Coverity?

No, unlike Coverity, Coverity is essentially a good discovery bug tool.
But EulerRobot is a virtualization software quality automation project that integrates some tools and test suites such as gcc/clang make test, qemu ut, qtest, coccinelle scripts and avocado-vt.

Thanks,
Chen Qun
Chen Qun Oct. 29, 2020, 8:26 a.m. UTC | #5
> -----Original Message-----
> From: Peter Maydell [mailto:peter.maydell@linaro.org]
> Sent: Thursday, October 29, 2020 4:15 AM
> To: Thomas Huth <thuth@redhat.com>
> Cc: Philippe Mathieu-Daudé <f4bug@amsat.org>; Chenqun (kuhn)
> <kuhn.chenqun@huawei.com>; QEMU Developers <qemu-devel@nongnu.org>;
> QEMU Trivial <qemu-trivial@nongnu.org>; Yoshinori Sato
> <ysato@users.sourceforge.jp>; Magnus Damm <magnus.damm@gmail.com>;
> Zhanghailiang <zhang.zhanghailiang@huawei.com>; ganqixin
> <ganqixin@huawei.com>; Euler Robot <euler.robot@huawei.com>
> Subject: Re: [PATCH 9/9] hw/timer/renesas_tmr: silence the compiler warnings
> 
> On Wed, 28 Oct 2020 at 15:07, Thomas Huth <thuth@redhat.com> wrote:
> >
> > On 28/10/2020 10.59, Philippe Mathieu-Daudé wrote:
> > > On 10/28/20 5:18 AM, Chen Qun wrote:
> > >> When using -Wimplicit-fallthrough in our CFLAGS, the compiler showed
> warning:
> > >> ../hw/timer/renesas_tmr.c: In function ‘tmr_read’:
> > >> ../hw/timer/renesas_tmr.c:221:19: warning: this statement may fall
> through [-Wimplicit-fallthrough=]
> > >>   221 |         } else if (ch == 0) {i
> > >>       |                   ^
> > >> ../hw/timer/renesas_tmr.c:224:5: note: here
> > >>   224 |     case A_TCORB:
> > >>       |     ^~~~
> > >>
> > >> Add the corresponding "fall through" comment to fix it.
> > >>
> > >> Reported-by: Euler Robot <euler.robot@huawei.com>
> > >> Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com>
> > >> ---
> > >> Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
> > >> Cc: Magnus Damm <magnus.damm@gmail.com>
> > >> ---
> > >>  hw/timer/renesas_tmr.c | 1 +
> > >>  1 file changed, 1 insertion(+)
> > >>
> > >> diff --git a/hw/timer/renesas_tmr.c b/hw/timer/renesas_tmr.c index
> > >> 446f2eacdd..e03a8155b2 100644
> > >> --- a/hw/timer/renesas_tmr.c
> > >> +++ b/hw/timer/renesas_tmr.c
> > >> @@ -221,6 +221,7 @@ static uint64_t tmr_read(void *opaque, hwaddr
> addr, unsigned size)
> > >>          } else if (ch == 0) {
> > >>              return concat_reg(tmr->tcora);
> > >>          }
> > >> +        /* fall through */
> > >>      case A_TCORB:
> > >>          if (size == 1) {
> > >>              return tmr->tcorb[ch];
> > >>
> > >
> > > You fixed A_TCORA but not A_TCORB...
> >
> > A_TCORB cannot fall through, since it always does a "return" in both
> > branches of the if-statement.
> >
> > However, it also looks really odd that A_TCORA falls through to
> > A_TCORB here and return that register value instead. Is this really
> > intended? Yoshinori, could you please double-check whether this is a bug here,
> or intended?
> 
> See the discussion in this thread:
> https://lore.kernel.org/qemu-devel/CAFEAcA8c2dywr=Zxz1ExAV-48JwFU5vbBD
> DfA=_KE98XamnXiA@mail.gmail.com/
> from when Coverity spotting the fall-through.
> 
> I think this cleanup patch from Yoshinori deals with the fall-through stuff by
> cleaning up that area of the timer device:
> https://lore.kernel.org/qemu-devel/20200711154242.41222-1-ysato@users.so
> urceforge.jp/
> It just needs somebody to code-review it :-)

This cleanup patch has been modified more thoroughly, so let's wait for it merge :-)

Thanks,
Chen Qun
diff mbox series

Patch

diff --git a/hw/timer/renesas_tmr.c b/hw/timer/renesas_tmr.c
index 446f2eacdd..e03a8155b2 100644
--- a/hw/timer/renesas_tmr.c
+++ b/hw/timer/renesas_tmr.c
@@ -221,6 +221,7 @@  static uint64_t tmr_read(void *opaque, hwaddr addr, unsigned size)
         } else if (ch == 0) {
             return concat_reg(tmr->tcora);
         }
+        /* fall through */
     case A_TCORB:
         if (size == 1) {
             return tmr->tcorb[ch];