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=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 ED80EC4724C for ; Thu, 30 Apr 2020 15:00:11 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id BEEF420775 for ; Thu, 30 Apr 2020 15:00:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BEEF420775 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jUAfM-0005da-Um; Thu, 30 Apr 2020 14:59:56 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jUAfL-0005dV-U0 for xen-devel@lists.xenproject.org; Thu, 30 Apr 2020 14:59:55 +0000 X-Inumbo-ID: 403b78ce-8af3-11ea-9a63-12813bfff9fa Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 403b78ce-8af3-11ea-9a63-12813bfff9fa; Thu, 30 Apr 2020 14:59:55 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 69801AC6C; Thu, 30 Apr 2020 14:59:53 +0000 (UTC) Subject: Re: [PATCH v6 11/15] x86/smpboot: clone_mapping should have one exit path To: Hongyan Xia References: <7c84de54ad0ae7a2e7c0c36ac7fa43860f8de995.1587735799.git.hongyxia@amazon.com> From: Jan Beulich Message-ID: Date: Thu, 30 Apr 2020 16:59:52 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <7c84de54ad0ae7a2e7c0c36ac7fa43860f8de995.1587735799.git.hongyxia@amazon.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: xen-devel@lists.xenproject.org, =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= , julien@xen.org, Wei Liu , Andrew Cooper Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" On 24.04.2020 16:09, Hongyan Xia wrote: > From: Wei Liu Like for patches 1 and 2 in this series, and as iirc mentioned already long ago for those, "should" or alike are misleading here: It's not a mistake that they don't, i.e. this is not a bug fix. You _want_ these functions to have a single (main) exit path, for subsequent changes of yours ending up easier. > --- a/xen/arch/x86/smpboot.c > +++ b/xen/arch/x86/smpboot.c > @@ -675,6 +675,7 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt) > l3_pgentry_t *pl3e; > l2_pgentry_t *pl2e; > l1_pgentry_t *pl1e; > + int rc = -ENOMEM; Would you mind starting out with 0 here, ... > @@ -715,7 +716,10 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt) > pl1e = l2e_to_l1e(*pl2e) + l1_table_offset(linear); > flags = l1e_get_flags(*pl1e); > if ( !(flags & _PAGE_PRESENT) ) > - return 0; > + { > + rc = 0; > + goto out; > + } ... dropping assignment and braces here, and ... > @@ -724,7 +728,7 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt) > { > pl3e = alloc_xen_pagetable(); > if ( !pl3e ) > - return -ENOMEM; > + goto out; ... setting rc to -ENOMEM ahead of the if() up from here? This imo makes things then not only minimally shorter, but also fights slightly better with the nevertheless still existing (after this patch) separate early exit paths. Jan