[13/14] hw/s390x/ipl: avoid taking address of fields in packed struct
diff mbox series

Message ID 20190329111104.17223-14-berrange@redhat.com
State New
Headers show
Series
  • misc set of fixes for warnings under GCC 9
Related show

Commit Message

Daniel P. Berrangé March 29, 2019, 11:11 a.m. UTC
Compiling with GCC 9 complains

hw/s390x/ipl.c: In function ‘s390_ipl_set_boot_menu’:
hw/s390x/ipl.c:256:25: warning: taking address of packed member of ‘struct QemuIplParameters’ may result in an unaligned pointer value [-Waddress-of-packed-member]
  256 |     uint32_t *timeout = &ipl->qipl.boot_menu_timeout;
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

This local variable is only present to save a little bit of
typing when setting the field later. Get rid of this to avoid
the warning about unaligned accesses.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hw/s390x/ipl.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

Comments

David Hildenbrand March 29, 2019, 11:41 a.m. UTC | #1
On 29.03.19 12:11, Daniel P. Berrangé wrote:
> Compiling with GCC 9 complains
> 
> hw/s390x/ipl.c: In function ‘s390_ipl_set_boot_menu’:
> hw/s390x/ipl.c:256:25: warning: taking address of packed member of ‘struct QemuIplParameters’ may result in an unaligned pointer value [-Waddress-of-packed-member]
>   256 |     uint32_t *timeout = &ipl->qipl.boot_menu_timeout;
>       |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> This local variable is only present to save a little bit of
> typing when setting the field later. Get rid of this to avoid
> the warning about unaligned accesses.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  hw/s390x/ipl.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c
> index 896888bf8f..51b272e190 100644
> --- a/hw/s390x/ipl.c
> +++ b/hw/s390x/ipl.c
> @@ -252,8 +252,6 @@ static void s390_ipl_set_boot_menu(S390IPLState *ipl)
>  {
>      QemuOptsList *plist = qemu_find_opts("boot-opts");
>      QemuOpts *opts = QTAILQ_FIRST(&plist->head);
> -    uint8_t *flags = &ipl->qipl.qipl_flags;
> -    uint32_t *timeout = &ipl->qipl.boot_menu_timeout;
>      const char *tmp;
>      unsigned long splash_time = 0;
>  
> @@ -269,7 +267,7 @@ static void s390_ipl_set_boot_menu(S390IPLState *ipl)
>      case S390_IPL_TYPE_CCW:
>          /* In the absence of -boot menu, use zipl parameters */
>          if (!qemu_opt_get(opts, "menu")) {
> -            *flags |= QIPL_FLAG_BM_OPTS_ZIPL;
> +            ipl->qipl.qipl_flags |= QIPL_FLAG_BM_OPTS_ZIPL;
>              return;
>          }
>          break;
> @@ -286,23 +284,23 @@ static void s390_ipl_set_boot_menu(S390IPLState *ipl)
>          return;
>      }
>  
> -    *flags |= QIPL_FLAG_BM_OPTS_CMD;
> +    ipl->qipl.qipl_flags |= QIPL_FLAG_BM_OPTS_CMD;
>  
>      tmp = qemu_opt_get(opts, "splash-time");
>  
>      if (tmp && qemu_strtoul(tmp, NULL, 10, &splash_time)) {
>          error_report("splash-time is invalid, forcing it to 0");
> -        *timeout = 0;
> +        ipl->qipl.boot_menu_timeout = 0;
>          return;
>      }
>  
>      if (splash_time > 0xffffffff) {
>          error_report("splash-time is too large, forcing it to max value");
> -        *timeout = 0xffffffff;
> +        ipl->qipl.boot_menu_timeout = 0xffffffff;
>          return;
>      }
>  
> -    *timeout = cpu_to_be32(splash_time);
> +    ipl->qipl.boot_menu_timeout = cpu_to_be32(splash_time);
>  }
>  
>  static CcwDevice *s390_get_ccw_device(DeviceState *dev_st)
> 

Reviewed-by: David Hildenbrand <david@redhat.com>
Thomas Huth March 29, 2019, 3:51 p.m. UTC | #2
On 29/03/2019 12.11, Daniel P. Berrangé wrote:
> Compiling with GCC 9 complains
> 
> hw/s390x/ipl.c: In function ‘s390_ipl_set_boot_menu’:
> hw/s390x/ipl.c:256:25: warning: taking address of packed member of ‘struct QemuIplParameters’ may result in an unaligned pointer value [-Waddress-of-packed-member]
>   256 |     uint32_t *timeout = &ipl->qipl.boot_menu_timeout;
>       |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> This local variable is only present to save a little bit of
> typing when setting the field later. Get rid of this to avoid
> the warning about unaligned accesses.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---

Reviewed-by: Thomas Huth <thuth@redhat.com>
Farhan Ali April 2, 2019, 2:11 p.m. UTC | #3
On 03/29/2019 07:11 AM, Daniel P. Berrangé wrote:
> Compiling with GCC 9 complains
> 
> hw/s390x/ipl.c: In function ‘s390_ipl_set_boot_menu’:
> hw/s390x/ipl.c:256:25: warning: taking address of packed member of ‘struct QemuIplParameters’ may result in an unaligned pointer value [-Waddress-of-packed-member]
>    256 |     uint32_t *timeout = &ipl->qipl.boot_menu_timeout;
>        |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> This local variable is only present to save a little bit of
> typing when setting the field later. Get rid of this to avoid
> the warning about unaligned accesses.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   hw/s390x/ipl.c | 12 +++++-------
>   1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c
> index 896888bf8f..51b272e190 100644
> --- a/hw/s390x/ipl.c
> +++ b/hw/s390x/ipl.c
> @@ -252,8 +252,6 @@ static void s390_ipl_set_boot_menu(S390IPLState *ipl)
>   {
>       QemuOptsList *plist = qemu_find_opts("boot-opts");
>       QemuOpts *opts = QTAILQ_FIRST(&plist->head);
> -    uint8_t *flags = &ipl->qipl.qipl_flags;
> -    uint32_t *timeout = &ipl->qipl.boot_menu_timeout;
>       const char *tmp;
>       unsigned long splash_time = 0;
>   
> @@ -269,7 +267,7 @@ static void s390_ipl_set_boot_menu(S390IPLState *ipl)
>       case S390_IPL_TYPE_CCW:
>           /* In the absence of -boot menu, use zipl parameters */
>           if (!qemu_opt_get(opts, "menu")) {
> -            *flags |= QIPL_FLAG_BM_OPTS_ZIPL;
> +            ipl->qipl.qipl_flags |= QIPL_FLAG_BM_OPTS_ZIPL;
>               return;
>           }
>           break;
> @@ -286,23 +284,23 @@ static void s390_ipl_set_boot_menu(S390IPLState *ipl)
>           return;
>       }
>   
> -    *flags |= QIPL_FLAG_BM_OPTS_CMD;
> +    ipl->qipl.qipl_flags |= QIPL_FLAG_BM_OPTS_CMD;
>   
>       tmp = qemu_opt_get(opts, "splash-time");
>   
>       if (tmp && qemu_strtoul(tmp, NULL, 10, &splash_time)) {
>           error_report("splash-time is invalid, forcing it to 0");
> -        *timeout = 0;
> +        ipl->qipl.boot_menu_timeout = 0;
>           return;
>       }
>   
>       if (splash_time > 0xffffffff) {
>           error_report("splash-time is too large, forcing it to max value");
> -        *timeout = 0xffffffff;
> +        ipl->qipl.boot_menu_timeout = 0xffffffff;
>           return;
>       }
>   
> -    *timeout = cpu_to_be32(splash_time);
> +    ipl->qipl.boot_menu_timeout = cpu_to_be32(splash_time);
>   }
>   
>   static CcwDevice *s390_get_ccw_device(DeviceState *dev_st)
> 

Reviewed-by: Farhan Ali <alifm@linux.ibm.com>

Patch
diff mbox series

diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c
index 896888bf8f..51b272e190 100644
--- a/hw/s390x/ipl.c
+++ b/hw/s390x/ipl.c
@@ -252,8 +252,6 @@  static void s390_ipl_set_boot_menu(S390IPLState *ipl)
 {
     QemuOptsList *plist = qemu_find_opts("boot-opts");
     QemuOpts *opts = QTAILQ_FIRST(&plist->head);
-    uint8_t *flags = &ipl->qipl.qipl_flags;
-    uint32_t *timeout = &ipl->qipl.boot_menu_timeout;
     const char *tmp;
     unsigned long splash_time = 0;
 
@@ -269,7 +267,7 @@  static void s390_ipl_set_boot_menu(S390IPLState *ipl)
     case S390_IPL_TYPE_CCW:
         /* In the absence of -boot menu, use zipl parameters */
         if (!qemu_opt_get(opts, "menu")) {
-            *flags |= QIPL_FLAG_BM_OPTS_ZIPL;
+            ipl->qipl.qipl_flags |= QIPL_FLAG_BM_OPTS_ZIPL;
             return;
         }
         break;
@@ -286,23 +284,23 @@  static void s390_ipl_set_boot_menu(S390IPLState *ipl)
         return;
     }
 
-    *flags |= QIPL_FLAG_BM_OPTS_CMD;
+    ipl->qipl.qipl_flags |= QIPL_FLAG_BM_OPTS_CMD;
 
     tmp = qemu_opt_get(opts, "splash-time");
 
     if (tmp && qemu_strtoul(tmp, NULL, 10, &splash_time)) {
         error_report("splash-time is invalid, forcing it to 0");
-        *timeout = 0;
+        ipl->qipl.boot_menu_timeout = 0;
         return;
     }
 
     if (splash_time > 0xffffffff) {
         error_report("splash-time is too large, forcing it to max value");
-        *timeout = 0xffffffff;
+        ipl->qipl.boot_menu_timeout = 0xffffffff;
         return;
     }
 
-    *timeout = cpu_to_be32(splash_time);
+    ipl->qipl.boot_menu_timeout = cpu_to_be32(splash_time);
 }
 
 static CcwDevice *s390_get_ccw_device(DeviceState *dev_st)