Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1051643iob; Fri, 13 May 2022 21:10:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyT2mZOf1NjMJsW6Fdqy/5eST2ZBR0lxeJESaGSvvqbvJmAqMDa/ODmbCzRc5fDDqZD0KlR X-Received: by 2002:a05:600c:3509:b0:394:84bf:96c0 with SMTP id h9-20020a05600c350900b0039484bf96c0mr7322683wmq.11.1652501439285; Fri, 13 May 2022 21:10:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652501439; cv=none; d=google.com; s=arc-20160816; b=ZLNhgtMkAzpKoU4ERGktQgO2dKQNSIE6NU4+dSFBXu51qebwEn25lhmQjVecqT6oAE 2dngNfL07U4e/4kVu8V7fwQu7ViehWCHBxBQ9aVVizXs3Y0gEBVvrD+OtbUmICATE9IF xX2y4DPMRrkGswh6Plmyurd7fgxEYoaNmuby5Lv1k+bkIxWBT6zpv+bHZRCXsArOb/uO 3MDrzB120gLNL8x8TQ4IFo30Su4PmH/CF9KIyhzIvuasv9EgGPoEDpdM3BUanNVJFN3G 46/T1BWhUdcLkWlwpT7USPkjF84vCKuDtCG8gCjqrnZzmYEJKzzUE5KAP7W4n/mTYH8/ dPmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=1nGNpikUs8vk4+aJD/NKpap25jqeBIDRUKybH2Zwqok=; b=U+OKStxZ8JJOS+C0vBkUQ2byhCNVnQT/Lp1DAdB3nGZ/WQSo1vgCLLi7s+/4kb7t4k whihDdF1FqfumIakRPxlVSFaU5jtiDzwGGuAk8XLMOm5xTQZbZGv9vc7iwgLaqJ1ahI/ GCq30nk4X14/rLPkSYO0LaSygYgDoLFPQa5q630e06gbAij3xQpI+0Hu0GkyWmBfARN8 5UjC1QlgFOeVrsnCxgwy2xxMYxV3mnMb+Ygug0CYyLcKTx36Fvd3oZabG8GT/kz//zrt ekaRb6WrCAfi88ebxTU0WTaJTRP5pqOaME50VknuXo1dL8Eqz0bwYc9Kj8BakPIA7zu2 ZJNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=E4oAmZY4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id d1-20020adf9c81000000b0020ce0f88962si3332673wre.336.2022.05.13.21.10.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 21:10:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=E4oAmZY4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3618D477B3D; Fri, 13 May 2022 17:41:59 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353762AbiELMcD (ORCPT + 99 others); Thu, 12 May 2022 08:32:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353770AbiELMbz (ORCPT ); Thu, 12 May 2022 08:31:55 -0400 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 200804AE09; Thu, 12 May 2022 05:31:51 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id m23so6342085ljc.0; Thu, 12 May 2022 05:31:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=1nGNpikUs8vk4+aJD/NKpap25jqeBIDRUKybH2Zwqok=; b=E4oAmZY4A0ZUSqx3z+F0WjMqHKJSpUkcD683dWO7uCrk1433e1ylnPkIEdJ3n8tv9d QFyQQsx72iG73vT3HWD1rKAiXNEcjQWAQxeGKXpmmFQ41loK8I74ot5D7OvPPtFyqlGb UR83VoKixoJGUjzGuNgKFTBGLcZxvJjfiDas74G9q8v3CjG/8e6UggEB9RcpvsGWLlyI 9VG7hHaswyeZt31MVo1xLcFYYIja6fxXUVMqJCCBVpRgFkbeD8E9iEWV/jMNiCnqMsxJ JLySwvfm0P0333AvGCcLm54fau8RZPwSziskG2cIOxGlQ4BCSh3ptU+vy+xKEfwcch0r tZyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=1nGNpikUs8vk4+aJD/NKpap25jqeBIDRUKybH2Zwqok=; b=DMdvVXqKOXt7itawx5J915+bXmS16EKEo/F6QUgHyPHz4TzQBbxuHFYeLz/JRdFMbE GzKP5IeFNEKglN4jkzcKWsTAqAkLRN+Cf2Gbv+WYfSXXdjce5rS8dvMRGv3njAFYVZil ZmhW/QUOCRk3p2b1VTnEK9OMXsJ26oAxK8pIO12AKuxOLsSbRf4TKuoioHloW0Yby1+7 GXnGmHV/HYh1Htv5a8HF8MIsQ27gwOCIsydiU2iDawnWnlvPAwLLWBiIlOc7vnbT7r2D bzg2WOIIp08evh0+IK0FfccoT2jQR7ifNzqQYKNjy1U9jDBVoTBcuYt9NkEfpsdHLsnj D6LA== X-Gm-Message-State: AOAM530Ex4WcvReUXlU5OVO3foMUdQSed5z9PqeNcpRmMtX0tnmX5CWV 1vnKX1Xf13uyKafsa0W1+aA= X-Received: by 2002:a2e:82c3:0:b0:250:c47e:c3ab with SMTP id n3-20020a2e82c3000000b00250c47ec3abmr13518987ljh.393.1652358709589; Thu, 12 May 2022 05:31:49 -0700 (PDT) Received: from mobilestation ([95.79.189.214]) by smtp.gmail.com with ESMTPSA id n6-20020a195506000000b0047415cd1ec3sm766340lfe.165.2022.05.12.05.31.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 05:31:48 -0700 (PDT) Date: Thu, 12 May 2022 15:31:46 +0300 From: Serge Semin To: Damien Le Moal , Hannes Reinecke Cc: Serge Semin , Hans de Goede , Jens Axboe , Alexey Malahov , Pavel Parkhomenko , Rob Herring , linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: Re: [PATCH v3 05/23] ata: libahci_platform: Explicitly set rc on devres_alloc failure Message-ID: <20220512123146.zkuftdu7fm26r6mp@mobilestation> References: <20220511231810.4928-1-Sergey.Semin@baikalelectronics.ru> <20220511231810.4928-6-Sergey.Semin@baikalelectronics.ru> <4bd4318b-a753-6453-a815-716fbfffab3f@suse.de> <9a1ad8f4-7f60-a941-940d-eca00b1f533b@opensource.wdc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9a1ad8f4-7f60-a941-940d-eca00b1f533b@opensource.wdc.com> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 12, 2022 at 12:32:42PM +0200, Damien Le Moal wrote: > On 2022/05/12 8:27, Hannes Reinecke wrote: > > On 5/12/22 01:17, Serge Semin wrote: > >> It's better for readability and maintainability to explicitly assign an > >> error number to the variable used then as a return value from the method > >> on the cleanup-on-error path. So adding new code in the method we won't > >> have to think whether the overridden rc-variable is set afterward in case > >> of an error. Saving one line of code doesn't worth it especially seeing > >> the rest of the ahci_platform_get_resources() function errors handling > >> blocks do explicitly write errno to rc. > >> > >> Signed-off-by: Serge Semin > >> > >> --- > >> > >> Changelog v2: > >> - Drop rc variable initialization (@Damien) > >> --- > >> drivers/ata/libahci_platform.c | 6 ++++-- > >> 1 file changed, 4 insertions(+), 2 deletions(-) > >> > >> diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c > >> index 32495ae96567..f7f9bfcfc164 100644 > >> --- a/drivers/ata/libahci_platform.c > >> +++ b/drivers/ata/libahci_platform.c > >> @@ -389,7 +389,7 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev, > >> struct ahci_host_priv *hpriv; > >> struct clk *clk; > >> struct device_node *child; > >> - int i, enabled_ports = 0, rc = -ENOMEM, child_nodes; > >> + int i, enabled_ports = 0, rc, child_nodes; > >> u32 mask_port_map = 0; > >> > >> if (!devres_open_group(dev, NULL, GFP_KERNEL)) > >> @@ -397,8 +397,10 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev, > >> > >> hpriv = devres_alloc(ahci_platform_put_resources, sizeof(*hpriv), > >> GFP_KERNEL); > >> - if (!hpriv) > >> + if (!hpriv) { > >> + rc = -ENOMEM; > >> goto err_out; > >> + } > >> > >> devres_add(dev, hpriv); > >> > > I disagree. > > As 'rc' is now only initialized within a conditional we're risking 'rc' > > will be left uninitialized. That's what I told to @Damien in v1. > > And in the end, it's a matter of style; this patch doesn't change the > > flow of events and the benefits are hard to see. As a first time reader of the module I've saw them. It was hard to comprehend right from the code context whether rc was properly initialized especially seeing there are so many local variables defined. Unified rc-initialization approach makes code easier to read for sure. In this case the rc variable is re-initialized in each error-case. So having it defaulted to a value which is relevant to the code block in the twenty lines below isn't the most optimized design. > > Yes. Let's drop this patch. Not improving anything. It's up to you to decide after all. Even though I disagree with your opinions the patch will be dropped in v4. -Sergey > > > > > Cheers, > > > > Hannes > > > -- > Damien Le Moal > Western Digital Research