qemu-trivial
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2] hw/rtc/twl92230: Silence warnings about missing fallthrou


From: Markus Armbruster
Subject: Re: [PATCH v2] hw/rtc/twl92230: Silence warnings about missing fallthrough statements
Date: Wed, 21 Oct 2020 04:50:59 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)

Thomas Huth <thuth@redhat.com> writes:

> When compiling with -Werror=implicit-fallthrough, gcc complains about
> missing fallthrough annotations in this file. Looking at the code,
> the fallthrough is indeed wanted here, but instead of adding the
> annotations, it can be done more efficiently by simply calculating
> the offset with a subtraction instead of increasing a local variable
> one by one.
>
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  v2: Fixed copy-n-paste bug
>
>  hw/rtc/twl92230.c | 50 +++++++++++++++++++++++------------------------
>  1 file changed, 24 insertions(+), 26 deletions(-)
>
> diff --git a/hw/rtc/twl92230.c b/hw/rtc/twl92230.c
> index f838913b37..50b97a1fce 100644
> --- a/hw/rtc/twl92230.c
> +++ b/hw/rtc/twl92230.c
> @@ -271,37 +271,36 @@ static void menelaus_gpio_set(void *opaque, int line, 
> int level)
>  static uint8_t menelaus_read(void *opaque, uint8_t addr)
>  {
>      MenelausState *s = (MenelausState *) opaque;
> -    int reg = 0;
>  
>      switch (addr) {
>      case MENELAUS_REV:
>          return 0x22;
>  
> -    case MENELAUS_VCORE_CTRL5: reg ++;
> -    case MENELAUS_VCORE_CTRL4: reg ++;
> -    case MENELAUS_VCORE_CTRL3: reg ++;
> -    case MENELAUS_VCORE_CTRL2: reg ++;
> +    case MENELAUS_VCORE_CTRL5:
> +    case MENELAUS_VCORE_CTRL4:
> +    case MENELAUS_VCORE_CTRL3:
> +    case MENELAUS_VCORE_CTRL2:
>      case MENELAUS_VCORE_CTRL1:
> -        return s->vcore[reg];
> +        return s->vcore[addr - MENELAUS_VCORE_CTRL1];

Suggest to count up instead of down:

       case MENELAUS_VCORE_CTRL1:
  +    case MENELAUS_VCORE_CTRL2:
  +    case MENELAUS_VCORE_CTRL3:
  +    case MENELAUS_VCORE_CTRL4:
  +    case MENELAUS_VCORE_CTRL5:
  -        return s->vcore[reg];
  +        return s->vcore[addr - MENELAUS_VCORE_CTRL1];

[...]




reply via email to

[Prev in Thread] Current Thread [Next in Thread]