From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58916) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xjf6T-0004T3-8O for qemu-devel@nongnu.org; Wed, 29 Oct 2014 22:04:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xjf6O-0001fM-5S for qemu-devel@nongnu.org; Wed, 29 Oct 2014 22:04:45 -0400 From: zhanghailiang Date: Thu, 30 Oct 2014 10:03:28 +0800 Message-ID: <1414634608-31292-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH] target-tricore: check return value before using it List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-trivial@nongnu.org Cc: kbastian@mail.uni-paderborn.de, zhanghailiang , qemu-devel@nongnu.org, peter.huangpeng@huawei.com 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 --- 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