Patchwork [v3,08/29] dump: change cpu_get_note_size to return ssize_t

login
register
mail settings
Submitter Paolo Bonzini
Date June 7, 2012, 7:39 a.m.
Message ID <1339054814-20939-9-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/163528/
State New
Headers show

Comments

Paolo Bonzini - June 7, 2012, 7:39 a.m.
So that it can use the same prototype in both cases.  Check for failure.

Cc: Wen Congyang <wency@cn.fujitsu.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 cpu-all.h               |    4 ++--
 dump.c                  |    9 +++++++--
 target-i386/arch_dump.c |    2 +-
 3 files changed, 10 insertions(+), 5 deletions(-)
Wen Congyang - June 11, 2012, 1:52 a.m.
Hi, Paolo

Thank you for doing this.

At 06/07/2012 03:39 PM, Paolo Bonzini Wrote:
> So that it can use the same prototype in both cases.  Check for failure.
> 
> Cc: Wen Congyang <wency@cn.fujitsu.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  cpu-all.h               |    4 ++--
>  dump.c                  |    9 +++++++--
>  target-i386/arch_dump.c |    2 +-
>  3 files changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/cpu-all.h b/cpu-all.h
> index e8749de..624030d 100644
> --- a/cpu-all.h
> +++ b/cpu-all.h
> @@ -552,7 +552,7 @@ int cpu_write_elf64_qemunote(write_core_dump_function f, CPUArchState *env,
>  int cpu_write_elf32_qemunote(write_core_dump_function f, CPUArchState *env,
>                               void *opaque);
>  int cpu_get_dump_info(ArchDumpInfo *info);
> -size_t cpu_get_note_size(int class, int machine, int nr_cpus);
> +ssize_t cpu_get_note_size(int class, int machine, int nr_cpus);
>  #else
>  static inline int cpu_write_elf64_note(write_core_dump_function f,
>                                         CPUArchState *env, int cpuid,
> @@ -587,7 +587,7 @@ static inline int cpu_get_dump_info(ArchDumpInfo *info)
>      return -1;
>  }
>  
> -static inline int cpu_get_note_size(int class, int machine, int nr_cpus)
> +static inline ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
>  {
>      return -1;
>  }
> diff --git a/dump.c b/dump.c
> index 0ca14f8..b24d4be 100644
> --- a/dump.c
> +++ b/dump.c
> @@ -750,6 +750,13 @@ static int dump_init(DumpState *s, int fd, bool paging, bool has_filter,
>          goto cleanup;
>      }
>  
> +    s->note_size = cpu_get_note_size(s->dump_info.d_class,
> +                                     s->dump_info.d_machine, nr_cpus);
> +    if (ret < 0) {

Hmm, I guess you want to check cpu_get_note_size()'s return value here.

Thanks
Wen Congyang

> +        error_set(errp, QERR_UNSUPPORTED);
> +        goto cleanup;
> +    }
> +
>      /* get memory mapping */
>      memory_mapping_list_init(&s->list);
>      if (paging) {
> @@ -784,8 +791,6 @@ static int dump_init(DumpState *s, int fd, bool paging, bool has_filter,
>          }
>      }
>  
> -    s->note_size = cpu_get_note_size(s->dump_info.d_class,
> -                                     s->dump_info.d_machine, nr_cpus);
>      if (s->dump_info.d_class == ELFCLASS64) {
>          if (s->have_section) {
>              s->memory_offset = sizeof(Elf64_Ehdr) +
> diff --git a/target-i386/arch_dump.c b/target-i386/arch_dump.c
> index 135d855..7c2b514 100644
> --- a/target-i386/arch_dump.c
> +++ b/target-i386/arch_dump.c
> @@ -415,7 +415,7 @@ int cpu_get_dump_info(ArchDumpInfo *info)
>      return 0;
>  }
>  
> -size_t cpu_get_note_size(int class, int machine, int nr_cpus)
> +ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
>  {
>      int name_size = 5; /* "CORE" or "QEMU" */
>      size_t elf_note_size = 0;

Patch

diff --git a/cpu-all.h b/cpu-all.h
index e8749de..624030d 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -552,7 +552,7 @@  int cpu_write_elf64_qemunote(write_core_dump_function f, CPUArchState *env,
 int cpu_write_elf32_qemunote(write_core_dump_function f, CPUArchState *env,
                              void *opaque);
 int cpu_get_dump_info(ArchDumpInfo *info);
-size_t cpu_get_note_size(int class, int machine, int nr_cpus);
+ssize_t cpu_get_note_size(int class, int machine, int nr_cpus);
 #else
 static inline int cpu_write_elf64_note(write_core_dump_function f,
                                        CPUArchState *env, int cpuid,
@@ -587,7 +587,7 @@  static inline int cpu_get_dump_info(ArchDumpInfo *info)
     return -1;
 }
 
-static inline int cpu_get_note_size(int class, int machine, int nr_cpus)
+static inline ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
 {
     return -1;
 }
diff --git a/dump.c b/dump.c
index 0ca14f8..b24d4be 100644
--- a/dump.c
+++ b/dump.c
@@ -750,6 +750,13 @@  static int dump_init(DumpState *s, int fd, bool paging, bool has_filter,
         goto cleanup;
     }
 
+    s->note_size = cpu_get_note_size(s->dump_info.d_class,
+                                     s->dump_info.d_machine, nr_cpus);
+    if (ret < 0) {
+        error_set(errp, QERR_UNSUPPORTED);
+        goto cleanup;
+    }
+
     /* get memory mapping */
     memory_mapping_list_init(&s->list);
     if (paging) {
@@ -784,8 +791,6 @@  static int dump_init(DumpState *s, int fd, bool paging, bool has_filter,
         }
     }
 
-    s->note_size = cpu_get_note_size(s->dump_info.d_class,
-                                     s->dump_info.d_machine, nr_cpus);
     if (s->dump_info.d_class == ELFCLASS64) {
         if (s->have_section) {
             s->memory_offset = sizeof(Elf64_Ehdr) +
diff --git a/target-i386/arch_dump.c b/target-i386/arch_dump.c
index 135d855..7c2b514 100644
--- a/target-i386/arch_dump.c
+++ b/target-i386/arch_dump.c
@@ -415,7 +415,7 @@  int cpu_get_dump_info(ArchDumpInfo *info)
     return 0;
 }
 
-size_t cpu_get_note_size(int class, int machine, int nr_cpus)
+ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
 {
     int name_size = 5; /* "CORE" or "QEMU" */
     size_t elf_note_size = 0;