Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B321AEB64D7 for ; Tue, 13 Jun 2023 16:40:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.548292.856166 (Exim 4.92) (envelope-from ) id 1q974E-0006cH-CH; Tue, 13 Jun 2023 16:40:26 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 548292.856166; Tue, 13 Jun 2023 16:40:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q974E-0006cA-7V; Tue, 13 Jun 2023 16:40:26 +0000 Received: by outflank-mailman (input) for mailman id 548292; Tue, 13 Jun 2023 16:40:25 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q974D-0006c4-AN for xen-devel@lists.xenproject.org; Tue, 13 Jun 2023 16:40:25 +0000 Received: from esa1.hc3370-68.iphmx.com (esa1.hc3370-68.iphmx.com [216.71.145.142]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id fd15ad36-0a08-11ee-8611-37d641c3527e; Tue, 13 Jun 2023 18:40:23 +0200 (CEST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: fd15ad36-0a08-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1686674422; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=Bi74crvnuYP9HbwVoECdXnk8P2w9Sfucs3wEkvHdVHI=; b=YOItwM41sA6EcMG3NH0MlfIvoh99UikeTJf3mvmWfG8s4BzbbIdtTRM9 9j29NZuuNow+pb0INNaVjm6R9LlzE7oCkDdD2rQAjaai5Ed/LbEJBciKe UwuFlZ83XB6Ez2IrJ0Ee5hWXQuzm9O4TL2N+Ekw+iMuz3fwD3YaRTnLJV A=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 113063634 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:QjqUuKOI2gyPprHvrR2Jl8FynXyQoLVcMsEvi/4bfWQNrUon3zJTm GpJCmuObv6KYGXyfIh3atni/UgBu5fWn981Gwto+SlhQUwRpJueD7x1DKtS0wC6dZSfER09v 63yTvGacajYm1eF/k/F3oDJ9CU6jufQAOKnUoYoAwgpLSd8UiAtlBl/rOAwh49skLCRDhiE/ Nj/uKUzAnf8s9JPGjxSs/rrRC9H5qyo42tG5wdmP5ingXeF/5UrJMNHTU2OByOQrrl8RoaSW +vFxbelyWLVlz9F5gSNy+uTnuUiG9Y+DCDW4pZkc/HKbitq/0Te5p0TJvsEAXq7vh3S9zxHJ HehgrTrIeshFvWkdO3wyHC0GQkmVUFN0OevzXRSLaV/ZqAJGpfh66wGMa04AWEX0uNrUXlvp fZGESgIdha8qqGM55eBQeY506zPLOGzVG8eknRpzDWfBvc6W5HTBa7N4Le03h9p2JoIR6yHI ZNEN3w2Nk+ojx5nYz/7DLo3mvuogX/uNSVVsluPqYI84nTJzRw327/oWDbQUoXTHp0LxRjD+ goq+Uz6HVYACNyc0wHc0TGtrMTrwGT+e5sNQejQGvlC3wTImz175ActfVmxrOS9i0W+c8lCM EFS8S0rxYAi+UruQtTjUhmQpH+fogVaS9dWC/c96gyG1uzT+QnxLncAZi5MbpohrsBeb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: E=Sophos;i="6.00,240,1681185600"; d="scan'208";a="113063634" Date: Tue, 13 Jun 2023 17:40:17 +0100 From: Anthony PERARD To: Jan Beulich CC: "xen-devel@lists.xenproject.org" , Wei Liu , Juergen Gross Subject: Re: [PATCH 3/5] libxg: drop dead assignment to "ptes" from xc_core_arch_map_p2m_list_rw() Message-ID: References: <2dc50b58-a4e4-3e32-1876-94412b14b052@suse.com> <33566692-ee42-44af-a94a-5535fdf39930@perard> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: On Tue, Jun 13, 2023 at 06:08:16PM +0200, Jan Beulich wrote: > On 13.06.2023 18:03, Anthony PERARD wrote: > > On Mon, Jun 12, 2023 at 01:46:40PM +0200, Jan Beulich wrote: > >> The function returns immediately after the enclosing if(). > >> > >> Coverity ID: 1532314 > >> Fixes: bd7a29c3d0b9 ("tools/libs/ctrl: fix xc_core_arch_map_p2m() to support linear p2m table") > >> Signed-off-by: Jan Beulich > >> > >> --- a/tools/libs/guest/xg_core_x86.c > >> +++ b/tools/libs/guest/xg_core_x86.c > >> @@ -210,7 +210,6 @@ xc_core_arch_map_p2m_list_rw(xc_interfac > >> } > >> > >> munmap(ptes, n_pages * PAGE_SIZE); > >> - ptes = NULL; > >> off = p2m_vaddr & ((mask >> shift) << shift); > >> } > > > > Do we have to remove this assignment? What if someone adds code later > > and reuse the content of the variable `ptes`? Or what if someone adds > > codes after the loop, and handle an error with `goto out`, we would have > > a double-munmap(). > > Imo it would be at that time when the assignment wants (re)adding. I I don't believe this is going to happen because I don't think a compiler will find a mistake. Maybe a run of Coverity would tell that ptes is reused after munmap(), but by the time Coverity run on the code, it would be too late. > fully agree with the tool, and I expect Misra (if it was applied to > the tool stack as well) would demand the very same change. I guess the issue here is that there's two paths out of the function, the error path via "out" and the success path. If `ptes` is check on both path, then the assignment would be needed, and it would be harder to make a mistake; which can be done by having only one way out. If only we could restrict the scope of `ptes` to the for loop, we wouldn't even need to set it to NULL. Cheers, -- Anthony PERARD