[Qemu-devel] [PATCH v2 05/18] hw/nvram/fw_cfg: Use the ldst API

Philippe Mathieu-Daudé posted 18 patches 6 years, 8 months ago
[Qemu-devel] [PATCH v2 05/18] hw/nvram/fw_cfg: Use the ldst API
Posted by Philippe Mathieu-Daudé 6 years, 8 months ago
The load/store API eases code review.

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

diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index 684c2cf00a..8eb76a382c 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -141,7 +141,7 @@ static char *read_splashfile(char *filename, gsize *file_sizep,
     }
 
     /* check magic ID */
-    filehead = ((content[0] & 0xff) + (content[1] << 8)) & 0xffff;
+    filehead = lduw_le_p(content);
     if (filehead == 0xd8ff) {
         file_type = JPG_FILE;
     } else if (filehead == 0x4d42) {
@@ -152,7 +152,7 @@ static char *read_splashfile(char *filename, gsize *file_sizep,
 
     /* check BMP bpp */
     if (file_type == BMP_FILE) {
-        bmp_bpp = (content[28] + (content[29] << 8)) & 0xffff;
+        bmp_bpp = lduw_le_p(&content[28]);
         if (bmp_bpp != 24) {
             goto error;
         }
-- 
2.20.1


Re: [Qemu-devel] [PATCH v2 05/18] hw/nvram/fw_cfg: Use the ldst API
Posted by Laszlo Ersek 6 years, 8 months ago
On 03/08/19 02:32, Philippe Mathieu-Daudé wrote:
> The load/store API eases code review.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  hw/nvram/fw_cfg.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
> index 684c2cf00a..8eb76a382c 100644
> --- a/hw/nvram/fw_cfg.c
> +++ b/hw/nvram/fw_cfg.c
> @@ -141,7 +141,7 @@ static char *read_splashfile(char *filename, gsize *file_sizep,
>      }
>  
>      /* check magic ID */
> -    filehead = ((content[0] & 0xff) + (content[1] << 8)) & 0xffff;
> +    filehead = lduw_le_p(content);
>      if (filehead == 0xd8ff) {
>          file_type = JPG_FILE;
>      } else if (filehead == 0x4d42) {
> @@ -152,7 +152,7 @@ static char *read_splashfile(char *filename, gsize *file_sizep,
>  
>      /* check BMP bpp */
>      if (file_type == BMP_FILE) {
> -        bmp_bpp = (content[28] + (content[29] << 8)) & 0xffff;
> +        bmp_bpp = lduw_le_p(&content[28]);
>          if (bmp_bpp != 24) {
>              goto error;
>          }
> 

Reviewed-by: Laszlo Ersek <lersek@redhat.com>