diff mbox series

[3/6] hw/net/rtl8139: Simplify if/else statement

Message ID 20200305175651.4563-4-philmd@redhat.com (mailing list archive)
State New, archived
Headers show
Series hw/net: Make Net/CanBus can_receive() handlers return a boolean | expand

Commit Message

Philippe Mathieu-Daudé March 5, 2020, 5:56 p.m. UTC
Rewrite:

      if (E) {
          return A;
      } else {
          return B;
      }
      /* EOF */
  }

as:

      if (E) {
          return A;
      }
      return B;
  }

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/net/rtl8139.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Alistair Francis March 5, 2020, 6:49 p.m. UTC | #1
On Thu, Mar 5, 2020 at 9:59 AM Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>
> Rewrite:
>
>       if (E) {
>           return A;
>       } else {
>           return B;
>       }
>       /* EOF */
>   }
>
> as:
>
>       if (E) {
>           return A;
>       }
>       return B;
>   }
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  hw/net/rtl8139.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c
> index ae4739bc09..ef3211537f 100644
> --- a/hw/net/rtl8139.c
> +++ b/hw/net/rtl8139.c
> @@ -808,11 +808,11 @@ static int rtl8139_can_receive(NetClientState *nc)
>          /* ??? Flow control not implemented in c+ mode.
>             This is a hack to work around slirp deficiencies anyway.  */
>          return 1;
> -    } else {
> -        avail = MOD2(s->RxBufferSize + s->RxBufPtr - s->RxBufAddr,
> -                     s->RxBufferSize);
> -        return (avail == 0 || avail >= 1514 || (s->IntrMask & RxOverflow));
>      }
> +
> +    avail = MOD2(s->RxBufferSize + s->RxBufPtr - s->RxBufAddr,
> +                 s->RxBufferSize);
> +    return avail == 0 || avail >= 1514 || (s->IntrMask & RxOverflow);
>  }
>
>  static ssize_t rtl8139_do_receive(NetClientState *nc, const uint8_t *buf, size_t size_, int do_interrupt)
> --
> 2.21.1
>
>
Cédric Le Goater March 6, 2020, 3:26 p.m. UTC | #2
On 3/5/20 6:56 PM, Philippe Mathieu-Daudé wrote:
> Rewrite:
> 
>       if (E) {
>           return A;
>       } else {
>           return B;
>       }
>       /* EOF */
>   }
> 
> as:
> 
>       if (E) {
>           return A;
>       }
>       return B;
>   }
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Reviewed-by: Cédric Le Goater <clg@kaod.org>

> ---
>  hw/net/rtl8139.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c
> index ae4739bc09..ef3211537f 100644
> --- a/hw/net/rtl8139.c
> +++ b/hw/net/rtl8139.c
> @@ -808,11 +808,11 @@ static int rtl8139_can_receive(NetClientState *nc)
>          /* ??? Flow control not implemented in c+ mode.
>             This is a hack to work around slirp deficiencies anyway.  */
>          return 1;
> -    } else {
> -        avail = MOD2(s->RxBufferSize + s->RxBufPtr - s->RxBufAddr,
> -                     s->RxBufferSize);
> -        return (avail == 0 || avail >= 1514 || (s->IntrMask & RxOverflow));
>      }
> +
> +    avail = MOD2(s->RxBufferSize + s->RxBufPtr - s->RxBufAddr,
> +                 s->RxBufferSize);
> +    return avail == 0 || avail >= 1514 || (s->IntrMask & RxOverflow);
>  }
>  
>  static ssize_t rtl8139_do_receive(NetClientState *nc, const uint8_t *buf, size_t size_, int do_interrupt)
>
diff mbox series

Patch

diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c
index ae4739bc09..ef3211537f 100644
--- a/hw/net/rtl8139.c
+++ b/hw/net/rtl8139.c
@@ -808,11 +808,11 @@  static int rtl8139_can_receive(NetClientState *nc)
         /* ??? Flow control not implemented in c+ mode.
            This is a hack to work around slirp deficiencies anyway.  */
         return 1;
-    } else {
-        avail = MOD2(s->RxBufferSize + s->RxBufPtr - s->RxBufAddr,
-                     s->RxBufferSize);
-        return (avail == 0 || avail >= 1514 || (s->IntrMask & RxOverflow));
     }
+
+    avail = MOD2(s->RxBufferSize + s->RxBufPtr - s->RxBufAddr,
+                 s->RxBufferSize);
+    return avail == 0 || avail >= 1514 || (s->IntrMask & RxOverflow);
 }
 
 static ssize_t rtl8139_do_receive(NetClientState *nc, const uint8_t *buf, size_t size_, int do_interrupt)