[PATCH v4 1/7] dump: Replace tswapN() -> cpu_to_dumpN()

Philippe Mathieu-Daudé posted 7 patches 2 years, 2 months ago
There is a newer version of this series
[PATCH v4 1/7] dump: Replace tswapN() -> cpu_to_dumpN()
Posted by Philippe Mathieu-Daudé 2 years, 2 months ago
All uses of tswap in that file are wrong, and should be using
cpu_to_dumpN, which correctly tests the endianness of the output.

Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 dump/dump.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/dump/dump.c b/dump/dump.c
index 279b07f09b..7101169ecb 100644
--- a/dump/dump.c
+++ b/dump/dump.c
@@ -907,13 +907,13 @@ static void get_note_sizes(DumpState *s, const void *note,
     if (dump_is_64bit(s)) {
         const Elf64_Nhdr *hdr = note;
         note_head_sz = sizeof(Elf64_Nhdr);
-        name_sz = tswap64(hdr->n_namesz);
-        desc_sz = tswap64(hdr->n_descsz);
+        name_sz = cpu_to_dump64(s, hdr->n_namesz);
+        desc_sz = cpu_to_dump64(s, hdr->n_descsz);
     } else {
         const Elf32_Nhdr *hdr = note;
         note_head_sz = sizeof(Elf32_Nhdr);
-        name_sz = tswap32(hdr->n_namesz);
-        desc_sz = tswap32(hdr->n_descsz);
+        name_sz = cpu_to_dump32(s, hdr->n_namesz);
+        desc_sz = cpu_to_dump32(s, hdr->n_descsz);
     }
 
     if (note_head_size) {
-- 
2.38.1


Re: [PATCH v4 1/7] dump: Replace tswapN() -> cpu_to_dumpN()
Posted by Thomas Huth 2 years, 2 months ago
On 24/02/2023 00.17, Philippe Mathieu-Daudé wrote:
> All uses of tswap in that file are wrong, and should be using
> cpu_to_dumpN, which correctly tests the endianness of the output.
> 
> Suggested-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   dump/dump.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/dump/dump.c b/dump/dump.c
> index 279b07f09b..7101169ecb 100644
> --- a/dump/dump.c
> +++ b/dump/dump.c
> @@ -907,13 +907,13 @@ static void get_note_sizes(DumpState *s, const void *note,
>       if (dump_is_64bit(s)) {
>           const Elf64_Nhdr *hdr = note;
>           note_head_sz = sizeof(Elf64_Nhdr);
> -        name_sz = tswap64(hdr->n_namesz);
> -        desc_sz = tswap64(hdr->n_descsz);
> +        name_sz = cpu_to_dump64(s, hdr->n_namesz);
> +        desc_sz = cpu_to_dump64(s, hdr->n_descsz);
>       } else {
>           const Elf32_Nhdr *hdr = note;
>           note_head_sz = sizeof(Elf32_Nhdr);
> -        name_sz = tswap32(hdr->n_namesz);
> -        desc_sz = tswap32(hdr->n_descsz);
> +        name_sz = cpu_to_dump32(s, hdr->n_namesz);
> +        desc_sz = cpu_to_dump32(s, hdr->n_descsz);
>       }

Those tswaps looked suspiciuous indeed.

Reviewed-by: Thomas Huth <thuth@redhat.com>



Re: [PATCH v4 1/7] dump: Replace tswapN() -> cpu_to_dumpN()
Posted by Richard Henderson 2 years, 2 months ago
On 2/23/23 13:17, Philippe Mathieu-Daudé wrote:
> All uses of tswap in that file are wrong, and should be using
> cpu_to_dumpN, which correctly tests the endianness of the output.
> 
> Suggested-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   dump/dump.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~