diff mbox

ppce500_spin: Replace assert by hw_error (fixes compiler warning)

Message ID 1335628351-28941-1-git-send-email-sw@weilnetz.de
State Accepted
Headers show

Commit Message

Stefan Weil April 28, 2012, 3:52 p.m. UTC
The default case in function spin_read should never be reached,
therefore the old code used assert(0) to abort QEMU.

This does not work when QEMU is compiled with macro NDEBUG defined.
In this case (and also when the compiler does not know that assert
never returns), there is a compiler warning because of the missing
return value.

Using hw_error allows an improved error message and aborts always.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
 hw/ppce500_spin.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Comments

Andreas Färber April 28, 2012, 4:09 p.m. UTC | #1
Am 28.04.2012 17:52, schrieb Stefan Weil:
> The default case in function spin_read should never be reached,
> therefore the old code used assert(0) to abort QEMU.
> 
> This does not work when QEMU is compiled with macro NDEBUG defined.
> In this case (and also when the compiler does not know that assert
> never returns), there is a compiler warning because of the missing
> return value.
> 
> Using hw_error allows an improved error message and aborts always.
> 
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
>  hw/ppce500_spin.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/hw/ppce500_spin.c b/hw/ppce500_spin.c
> index 960b7b0..57dc995 100644
> --- a/hw/ppce500_spin.c
> +++ b/hw/ppce500_spin.c
> @@ -178,7 +178,7 @@ static uint64_t spin_read(void *opaque, target_phys_addr_t addr, unsigned len)
>      case 4:
>          return ldl_p(spin_p);
>      default:
> -        assert(0);
> +        hw_error("ppce500: unexpected spin_read with len = %u", len);

Thanks. Bonus points for using __func__. :)

Andreas

>      }
>  }
>
Alexander Graf April 30, 2012, 8:54 a.m. UTC | #2
On 28.04.2012, at 17:52, Stefan Weil wrote:

> The default case in function spin_read should never be reached,
> therefore the old code used assert(0) to abort QEMU.
> 
> This does not work when QEMU is compiled with macro NDEBUG defined.
> In this case (and also when the compiler does not know that assert
> never returns), there is a compiler warning because of the missing
> return value.
> 
> Using hw_error allows an improved error message and aborts always.
> 
> Signed-off-by: Stefan Weil <sw@weilnetz.de>

Thanks, applied to ppc-next. The patch didn't show up on patchworks btw, not sure what went wrong there.


Alex
Stefan Weil April 30, 2012, 2:55 p.m. UTC | #3
Am 30.04.2012 10:54, schrieb Alexander Graf:
> On 28.04.2012, at 17:52, Stefan Weil wrote:
>> The default case in function spin_read should never be reached, 
>> therefore the old code used assert(0) to abort QEMU. This does not 
>> work when QEMU is compiled with macro NDEBUG defined. In this case 
>> (and also when the compiler does not know that assert never returns), 
>> there is a compiler warning because of the missing return value. 
>> Using hw_error allows an improved error message and aborts always. 
>> Signed-off-by: Stefan Weil <sw@weilnetz.de> 
> Thanks, applied to ppc-next. The patch didn't show up on patchworks 
> btw, not sure what went wrong there. Alex

http://patchwork.ozlabs.org/patch/155666/
Did you filter on state "new"? I update the state for my patches.

Are you planning to send a pull request for QEMU 1.1?
I'd like to have this compiler warning fixed in the new version.

Regards,
Stefan
diff mbox

Patch

diff --git a/hw/ppce500_spin.c b/hw/ppce500_spin.c
index 960b7b0..57dc995 100644
--- a/hw/ppce500_spin.c
+++ b/hw/ppce500_spin.c
@@ -178,7 +178,7 @@  static uint64_t spin_read(void *opaque, target_phys_addr_t addr, unsigned len)
     case 4:
         return ldl_p(spin_p);
     default:
-        assert(0);
+        hw_error("ppce500: unexpected spin_read with len = %u", len);
     }
 }