diff mbox series

[v3,16/25] tpm: Use size_t to hold sizes

Message ID 20190220010232.18731-17-philmd@redhat.com (mailing list archive)
State New, archived
Headers show
Series chardev: Convert qemu_chr_write() to take a size_t argument | expand

Commit Message

Philippe Mathieu-Daudé Feb. 20, 2019, 1:02 a.m. UTC
Avoid to use a signed type to hold an unsigned value.

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

Comments

Marc-André Lureau Feb. 20, 2019, 11:22 a.m. UTC | #1
On Wed, Feb 20, 2019 at 2:06 AM Philippe Mathieu-Daudé
<philmd@redhat.com> wrote:
>
> Avoid to use a signed type to hold an unsigned value.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>


Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

> ---
>  hw/tpm/tpm_emulator.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c
> index 70f4b10284..931e56f6ed 100644
> --- a/hw/tpm/tpm_emulator.c
> +++ b/hw/tpm/tpm_emulator.c
> @@ -87,17 +87,18 @@ static int tpm_emulator_ctrlcmd(TPMEmulator *tpm, unsigned long cmd, void *msg,
>  {
>      CharBackend *dev = &tpm->ctrl_chr;
>      uint32_t cmd_no = cpu_to_be32(cmd);
> -    ssize_t n = sizeof(uint32_t) + msg_len_in;
> +    size_t sz = sizeof(uint32_t) + msg_len_in;
> +    ssize_t n;
>      uint8_t *buf = NULL;
>      int ret = -1;
>
>      qemu_mutex_lock(&tpm->mutex);
>
> -    buf = g_alloca(n);
> +    buf = g_alloca(sz);
>      memcpy(buf, &cmd_no, sizeof(cmd_no));
>      memcpy(buf + sizeof(cmd_no), msg, msg_len_in);
>
> -    n = qemu_chr_fe_write_all(dev, buf, n);
> +    n = qemu_chr_fe_write_all(dev, buf, sz);
>      if (n <= 0) {
>          goto end;
>      }
> --
> 2.20.1
>
diff mbox series

Patch

diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c
index 70f4b10284..931e56f6ed 100644
--- a/hw/tpm/tpm_emulator.c
+++ b/hw/tpm/tpm_emulator.c
@@ -87,17 +87,18 @@  static int tpm_emulator_ctrlcmd(TPMEmulator *tpm, unsigned long cmd, void *msg,
 {
     CharBackend *dev = &tpm->ctrl_chr;
     uint32_t cmd_no = cpu_to_be32(cmd);
-    ssize_t n = sizeof(uint32_t) + msg_len_in;
+    size_t sz = sizeof(uint32_t) + msg_len_in;
+    ssize_t n;
     uint8_t *buf = NULL;
     int ret = -1;
 
     qemu_mutex_lock(&tpm->mutex);
 
-    buf = g_alloca(n);
+    buf = g_alloca(sz);
     memcpy(buf, &cmd_no, sizeof(cmd_no));
     memcpy(buf + sizeof(cmd_no), msg, msg_len_in);
 
-    n = qemu_chr_fe_write_all(dev, buf, n);
+    n = qemu_chr_fe_write_all(dev, buf, sz);
     if (n <= 0) {
         goto end;
     }