Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 383C4C48BCF for ; Thu, 10 Jun 2021 01:48:29 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7EBDE61407 for ; Thu, 10 Jun 2021 01:48:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7EBDE61407 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:49790 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lr9o3-00057M-IB for qemu-devel@archiver.kernel.org; Wed, 09 Jun 2021 21:48:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35194) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lr9nK-0004Sr-4R for qemu-devel@nongnu.org; Wed, 09 Jun 2021 21:47:42 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2490) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lr9nH-0000MP-NG for qemu-devel@nongnu.org; Wed, 09 Jun 2021 21:47:41 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4G0mty5Mg6zWscJ; Thu, 10 Jun 2021 09:42:34 +0800 (CST) Received: from dggema765-chm.china.huawei.com (10.1.198.207) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Thu, 10 Jun 2021 09:47:27 +0800 Received: from [10.174.185.187] (10.174.185.187) by dggema765-chm.china.huawei.com (10.1.198.207) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Thu, 10 Jun 2021 09:47:27 +0800 Subject: Re: [PATCH] vl: Fix an assert failure in error path To: =?UTF-8?Q?Daniel_P=2e_Berrang=c3=a9?= , "Markus Armbruster" References: <20210610084741.456260-1-zhenzhong.duan@intel.com> <048a18be-0d1c-7fd0-7031-51e64c5432f3@redhat.com> <87fsxrnss4.fsf@dusky.pond.sub.org> From: Peng Liang Message-ID: <2a094460-5549-4a64-8df0-c376e046b012@huawei.com> Date: Thu, 10 Jun 2021 09:47:26 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.2.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.185.187] X-ClientProxiedBy: dggeme709-chm.china.huawei.com (10.1.199.105) To dggema765-chm.china.huawei.com (10.1.198.207) X-CFilter-Loop: Reflected Received-SPF: pass client-ip=45.249.212.187; envelope-from=liangpeng10@huawei.com; helo=szxga01-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Zhenzhong Duan , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 6/9/2021 8:15 PM, Daniel P. Berrangé wrote: > On Wed, Jun 09, 2021 at 02:09:47PM +0200, Markus Armbruster wrote: >> Paolo Bonzini writes: >> >>> On 10/06/21 10:47, Zhenzhong Duan wrote: >>>> Based on the description of error_setg(), the local variable err in >>>> qemu_maybe_daemonize() should be initialized to NULL. >>>> Without fix, the uninitialized *errp triggers assert failure which >>>> doesn't show much valuable information. >>>> Before the fix: >>>> qemu-system-x86_64: ../util/error.c:59: error_setv: Assertion `*errp == NULL' failed. >>>> After fix: >>>> qemu-system-x86_64: cannot create PID file: Cannot open pid file: Permission denied >>>> Signed-off-by: Zhenzhong Duan >>>> --- >>>> softmmu/vl.c | 2 +- >>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>> diff --git a/softmmu/vl.c b/softmmu/vl.c >>>> index 326c1e9080..feb4d201f3 100644 >>>> --- a/softmmu/vl.c >>>> +++ b/softmmu/vl.c >>>> @@ -2522,7 +2522,7 @@ static void qemu_process_help_options(void) >>>> static void qemu_maybe_daemonize(const char *pid_file) >>>> { >>>> - Error *err; >>>> + Error *err = NULL; >> >> Common mistake, I'm afraid. > > Initializing isn't likely to be a performance impact, so I'd think > we should make 'checkpatch.pl' complain about any 'Error *' variable > that is not initialized to NULL, as a safety net, even if not technically > required in some cases. > > Regards, > Daniel > Hi, Could we add a coccinelle script to check (and fix) these problems? e.g.: @ r @ identifier id; @@ Error *id + = NULL ; Using this script, I found that local variable err in qemu_init_subsystems is not initialized to NULL too. The script is not prefect though, it will initialize all global/static 'Error *' variables and all local 'Error *' variables in util/error.c to NULL, which is unnecessary. Thanks, Peng