qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] target-tricore: check return value before using it
@ 2014-10-30  2:03 zhanghailiang
  2014-10-30  6:59 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
  2014-10-30  8:14 ` [Qemu-devel] " Bastian Koppelmann
  0 siblings, 2 replies; 3+ messages in thread
From: zhanghailiang @ 2014-10-30  2:03 UTC (permalink / raw)
  To: qemu-trivial; +Cc: kbastian, zhanghailiang, qemu-devel, peter.huangpeng

We reference the return value of cpu before checking whether it is NULL,
The checking code is after that which violates code style.

It makes no difference if the cpu is NULL, qemu process will terminate.
But one will be 'Segmentation fault' and the other will report a error
which is what we want.

Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
---
 hw/tricore/tricore_testboard.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/tricore/tricore_testboard.c b/hw/tricore/tricore_testboard.c
index eeb4922..a059a20 100644
--- a/hw/tricore/tricore_testboard.c
+++ b/hw/tricore/tricore_testboard.c
@@ -71,11 +71,11 @@ static void tricore_testboard_init(MachineState *machine, int board_id)
         machine->cpu_model = "tc1796";
     }
     cpu = cpu_tricore_init(machine->cpu_model);
-    env = &cpu->env;
     if (!cpu) {
         error_report("Unable to find CPU definition");
         exit(1);
     }
+    env = &cpu->env;
     memory_region_init_ram(ext_cram, NULL, "powerlink_ext_c.ram", 2*1024*1024, &error_abort);
     vmstate_register_ram_global(ext_cram);
     memory_region_init_ram(ext_dram, NULL, "powerlink_ext_d.ram", 4*1024*1024, &error_abort);
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [Qemu-trivial] [PATCH] target-tricore: check return value before using it
  2014-10-30  2:03 [Qemu-devel] [PATCH] target-tricore: check return value before using it zhanghailiang
@ 2014-10-30  6:59 ` Michael Tokarev
  2014-10-30  8:14 ` [Qemu-devel] " Bastian Koppelmann
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Tokarev @ 2014-10-30  6:59 UTC (permalink / raw)
  To: zhanghailiang, qemu-trivial; +Cc: kbastian, qemu-devel, peter.huangpeng

30.10.2014 05:03, zhanghailiang wrote:
> We reference the return value of cpu before checking whether it is NULL,
> The checking code is after that which violates code style.

Applied, thanks!

/mjt

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] target-tricore: check return value before using it
  2014-10-30  2:03 [Qemu-devel] [PATCH] target-tricore: check return value before using it zhanghailiang
  2014-10-30  6:59 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
@ 2014-10-30  8:14 ` Bastian Koppelmann
  1 sibling, 0 replies; 3+ messages in thread
From: Bastian Koppelmann @ 2014-10-30  8:14 UTC (permalink / raw)
  To: zhanghailiang, qemu-trivial; +Cc: qemu-devel, peter.huangpeng

Geez, thanks. I wonder how I missed that.

Reviewed-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>

On 10/30/2014 02:03 AM, zhanghailiang wrote:
> We reference the return value of cpu before checking whether it is NULL,
> The checking code is after that which violates code style.
>
> It makes no difference if the cpu is NULL, qemu process will terminate.
> But one will be 'Segmentation fault' and the other will report a error
> which is what we want.
>
> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
> ---
>   hw/tricore/tricore_testboard.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/tricore/tricore_testboard.c b/hw/tricore/tricore_testboard.c
> index eeb4922..a059a20 100644
> --- a/hw/tricore/tricore_testboard.c
> +++ b/hw/tricore/tricore_testboard.c
> @@ -71,11 +71,11 @@ static void tricore_testboard_init(MachineState *machine, int board_id)
>           machine->cpu_model = "tc1796";
>       }
>       cpu = cpu_tricore_init(machine->cpu_model);
> -    env = &cpu->env;
>       if (!cpu) {
>           error_report("Unable to find CPU definition");
>           exit(1);
>       }
> +    env = &cpu->env;
>       memory_region_init_ram(ext_cram, NULL, "powerlink_ext_c.ram", 2*1024*1024, &error_abort);
>       vmstate_register_ram_global(ext_cram);
>       memory_region_init_ram(ext_dram, NULL, "powerlink_ext_d.ram", 4*1024*1024, &error_abort);

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-10-30  7:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-30  2:03 [Qemu-devel] [PATCH] target-tricore: check return value before using it zhanghailiang
2014-10-30  6:59 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2014-10-30  8:14 ` [Qemu-devel] " Bastian Koppelmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).