[PATCH 6/6] hw/net/can: Make CanBusClientInfo::can_receive() return a boolean

Philippe Mathieu-Daudé posted 6 patches 5 years, 8 months ago
Maintainers: Max Filippov <jcmvbkbc@gmail.com>, "Michael S. Tsirkin" <mst@redhat.com>, "Cédric Le Goater" <clg@kaod.org>, Dmitry Fleytman <dmitry.fleytman@gmail.com>, Alistair Francis <alistair@alistair23.me>, Beniamino Galvani <b.galvani@gmail.com>, Peter Chubb <peter.chubb@nicta.com.au>, David Gibson <david@gibson.dropbear.id.au>, Andrew Jeffery <andrew@aj.id.au>, Jason Wang <jasowang@redhat.com>, Joel Stanley <joel@jms.id.au>, Richard Henderson <rth@twiddle.net>, Peter Maydell <peter.maydell@linaro.org>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>
[PATCH 6/6] hw/net/can: Make CanBusClientInfo::can_receive() return a boolean
Posted by Philippe Mathieu-Daudé 5 years, 8 months ago
The CanBusClientInfo::can_receive handler return whether the
device can or can not receive new frames. Make it obvious by
returning a boolean type.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/net/can/can_sja1000.h | 2 +-
 include/net/can_emu.h    | 2 +-
 hw/net/can/can_sja1000.c | 8 ++++----
 net/can/can_socketcan.c  | 4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/hw/net/can/can_sja1000.h b/hw/net/can/can_sja1000.h
index 220a622087..7ca9cd681e 100644
--- a/hw/net/can/can_sja1000.h
+++ b/hw/net/can/can_sja1000.h
@@ -137,7 +137,7 @@ void can_sja_disconnect(CanSJA1000State *s);
 
 int can_sja_init(CanSJA1000State *s, qemu_irq irq);
 
-int can_sja_can_receive(CanBusClientState *client);
+bool can_sja_can_receive(CanBusClientState *client);
 
 ssize_t can_sja_receive(CanBusClientState *client,
                         const qemu_can_frame *frames, size_t frames_cnt);
diff --git a/include/net/can_emu.h b/include/net/can_emu.h
index d4fc51b57d..fce9770928 100644
--- a/include/net/can_emu.h
+++ b/include/net/can_emu.h
@@ -83,7 +83,7 @@ typedef struct CanBusClientState CanBusClientState;
 typedef struct CanBusState CanBusState;
 
 typedef struct CanBusClientInfo {
-    int (*can_receive)(CanBusClientState *);
+    bool (*can_receive)(CanBusClientState *);
     ssize_t (*receive)(CanBusClientState *,
         const struct qemu_can_frame *frames, size_t frames_cnt);
 } CanBusClientInfo;
diff --git a/hw/net/can/can_sja1000.c b/hw/net/can/can_sja1000.c
index 39c78faf9b..ea915a023a 100644
--- a/hw/net/can/can_sja1000.c
+++ b/hw/net/can/can_sja1000.c
@@ -733,21 +733,21 @@ uint64_t can_sja_mem_read(CanSJA1000State *s, hwaddr addr, unsigned size)
     return temp;
 }
 
-int can_sja_can_receive(CanBusClientState *client)
+bool can_sja_can_receive(CanBusClientState *client)
 {
     CanSJA1000State *s = container_of(client, CanSJA1000State, bus_client);
 
     if (s->clock & 0x80) { /* PeliCAN Mode */
         if (s->mode & 0x01) { /* reset mode. */
-            return 0;
+            return false;
         }
     } else { /* BasicCAN mode */
         if (s->control & 0x01) {
-            return 0;
+            return false;
         }
     }
 
-    return 1; /* always return 1, when operation mode */
+    return true; /* always return true, when operation mode */
 }
 
 ssize_t can_sja_receive(CanBusClientState *client, const qemu_can_frame *frames,
diff --git a/net/can/can_socketcan.c b/net/can/can_socketcan.c
index 29bfacd4f8..807f31fcde 100644
--- a/net/can/can_socketcan.c
+++ b/net/can/can_socketcan.c
@@ -110,9 +110,9 @@ static void can_host_socketcan_read(void *opaque)
     }
 }
 
-static int can_host_socketcan_can_receive(CanBusClientState *client)
+static bool can_host_socketcan_can_receive(CanBusClientState *client)
 {
-    return 1;
+    return true;
 }
 
 static ssize_t can_host_socketcan_receive(CanBusClientState *client,
-- 
2.21.1


Re: [PATCH 6/6] hw/net/can: Make CanBusClientInfo::can_receive() return a boolean
Posted by Alistair Francis 5 years, 8 months ago
On Thu, Mar 5, 2020 at 9:59 AM Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>
> The CanBusClientInfo::can_receive handler return whether the
> device can or can not receive new frames. Make it obvious by
> returning a boolean type.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

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

Alistair

> ---
>  hw/net/can/can_sja1000.h | 2 +-
>  include/net/can_emu.h    | 2 +-
>  hw/net/can/can_sja1000.c | 8 ++++----
>  net/can/can_socketcan.c  | 4 ++--
>  4 files changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/hw/net/can/can_sja1000.h b/hw/net/can/can_sja1000.h
> index 220a622087..7ca9cd681e 100644
> --- a/hw/net/can/can_sja1000.h
> +++ b/hw/net/can/can_sja1000.h
> @@ -137,7 +137,7 @@ void can_sja_disconnect(CanSJA1000State *s);
>
>  int can_sja_init(CanSJA1000State *s, qemu_irq irq);
>
> -int can_sja_can_receive(CanBusClientState *client);
> +bool can_sja_can_receive(CanBusClientState *client);
>
>  ssize_t can_sja_receive(CanBusClientState *client,
>                          const qemu_can_frame *frames, size_t frames_cnt);
> diff --git a/include/net/can_emu.h b/include/net/can_emu.h
> index d4fc51b57d..fce9770928 100644
> --- a/include/net/can_emu.h
> +++ b/include/net/can_emu.h
> @@ -83,7 +83,7 @@ typedef struct CanBusClientState CanBusClientState;
>  typedef struct CanBusState CanBusState;
>
>  typedef struct CanBusClientInfo {
> -    int (*can_receive)(CanBusClientState *);
> +    bool (*can_receive)(CanBusClientState *);
>      ssize_t (*receive)(CanBusClientState *,
>          const struct qemu_can_frame *frames, size_t frames_cnt);
>  } CanBusClientInfo;
> diff --git a/hw/net/can/can_sja1000.c b/hw/net/can/can_sja1000.c
> index 39c78faf9b..ea915a023a 100644
> --- a/hw/net/can/can_sja1000.c
> +++ b/hw/net/can/can_sja1000.c
> @@ -733,21 +733,21 @@ uint64_t can_sja_mem_read(CanSJA1000State *s, hwaddr addr, unsigned size)
>      return temp;
>  }
>
> -int can_sja_can_receive(CanBusClientState *client)
> +bool can_sja_can_receive(CanBusClientState *client)
>  {
>      CanSJA1000State *s = container_of(client, CanSJA1000State, bus_client);
>
>      if (s->clock & 0x80) { /* PeliCAN Mode */
>          if (s->mode & 0x01) { /* reset mode. */
> -            return 0;
> +            return false;
>          }
>      } else { /* BasicCAN mode */
>          if (s->control & 0x01) {
> -            return 0;
> +            return false;
>          }
>      }
>
> -    return 1; /* always return 1, when operation mode */
> +    return true; /* always return true, when operation mode */
>  }
>
>  ssize_t can_sja_receive(CanBusClientState *client, const qemu_can_frame *frames,
> diff --git a/net/can/can_socketcan.c b/net/can/can_socketcan.c
> index 29bfacd4f8..807f31fcde 100644
> --- a/net/can/can_socketcan.c
> +++ b/net/can/can_socketcan.c
> @@ -110,9 +110,9 @@ static void can_host_socketcan_read(void *opaque)
>      }
>  }
>
> -static int can_host_socketcan_can_receive(CanBusClientState *client)
> +static bool can_host_socketcan_can_receive(CanBusClientState *client)
>  {
> -    return 1;
> +    return true;
>  }
>
>  static ssize_t can_host_socketcan_receive(CanBusClientState *client,
> --
> 2.21.1
>
>

Re: [PATCH 6/6] hw/net/can: Make CanBusClientInfo::can_receive() return a boolean
Posted by Cédric Le Goater 5 years, 8 months ago
On 3/5/20 6:56 PM, Philippe Mathieu-Daudé wrote:
> The CanBusClientInfo::can_receive handler return whether the
> device can or can not receive new frames. Make it obvious by
> returning a boolean type.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

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


> ---
>  hw/net/can/can_sja1000.h | 2 +-
>  include/net/can_emu.h    | 2 +-
>  hw/net/can/can_sja1000.c | 8 ++++----
>  net/can/can_socketcan.c  | 4 ++--
>  4 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/net/can/can_sja1000.h b/hw/net/can/can_sja1000.h
> index 220a622087..7ca9cd681e 100644
> --- a/hw/net/can/can_sja1000.h
> +++ b/hw/net/can/can_sja1000.h
> @@ -137,7 +137,7 @@ void can_sja_disconnect(CanSJA1000State *s);
>  
>  int can_sja_init(CanSJA1000State *s, qemu_irq irq);
>  
> -int can_sja_can_receive(CanBusClientState *client);
> +bool can_sja_can_receive(CanBusClientState *client);
>  
>  ssize_t can_sja_receive(CanBusClientState *client,
>                          const qemu_can_frame *frames, size_t frames_cnt);
> diff --git a/include/net/can_emu.h b/include/net/can_emu.h
> index d4fc51b57d..fce9770928 100644
> --- a/include/net/can_emu.h
> +++ b/include/net/can_emu.h
> @@ -83,7 +83,7 @@ typedef struct CanBusClientState CanBusClientState;
>  typedef struct CanBusState CanBusState;
>  
>  typedef struct CanBusClientInfo {
> -    int (*can_receive)(CanBusClientState *);
> +    bool (*can_receive)(CanBusClientState *);
>      ssize_t (*receive)(CanBusClientState *,
>          const struct qemu_can_frame *frames, size_t frames_cnt);
>  } CanBusClientInfo;
> diff --git a/hw/net/can/can_sja1000.c b/hw/net/can/can_sja1000.c
> index 39c78faf9b..ea915a023a 100644
> --- a/hw/net/can/can_sja1000.c
> +++ b/hw/net/can/can_sja1000.c
> @@ -733,21 +733,21 @@ uint64_t can_sja_mem_read(CanSJA1000State *s, hwaddr addr, unsigned size)
>      return temp;
>  }
>  
> -int can_sja_can_receive(CanBusClientState *client)
> +bool can_sja_can_receive(CanBusClientState *client)
>  {
>      CanSJA1000State *s = container_of(client, CanSJA1000State, bus_client);
>  
>      if (s->clock & 0x80) { /* PeliCAN Mode */
>          if (s->mode & 0x01) { /* reset mode. */
> -            return 0;
> +            return false;
>          }
>      } else { /* BasicCAN mode */
>          if (s->control & 0x01) {
> -            return 0;
> +            return false;
>          }
>      }
>  
> -    return 1; /* always return 1, when operation mode */
> +    return true; /* always return true, when operation mode */
>  }
>  
>  ssize_t can_sja_receive(CanBusClientState *client, const qemu_can_frame *frames,
> diff --git a/net/can/can_socketcan.c b/net/can/can_socketcan.c
> index 29bfacd4f8..807f31fcde 100644
> --- a/net/can/can_socketcan.c
> +++ b/net/can/can_socketcan.c
> @@ -110,9 +110,9 @@ static void can_host_socketcan_read(void *opaque)
>      }
>  }
>  
> -static int can_host_socketcan_can_receive(CanBusClientState *client)
> +static bool can_host_socketcan_can_receive(CanBusClientState *client)
>  {
> -    return 1;
> +    return true;
>  }
>  
>  static ssize_t can_host_socketcan_receive(CanBusClientState *client,
>