Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6269929rwn; Tue, 13 Sep 2022 01:20:22 -0700 (PDT) X-Google-Smtp-Source: AA6agR6nA4R5ULg82X/sORT14JwS1aD4WWmh3INvO1hJbgaRGcThnsyyAXxAEiOEcfe76eaivP6x X-Received: by 2002:a17:90a:be0a:b0:200:5dda:910a with SMTP id a10-20020a17090abe0a00b002005dda910amr2814914pjs.114.1663057222557; Tue, 13 Sep 2022 01:20:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663057222; cv=none; d=google.com; s=arc-20160816; b=v08Ay6v4uEU3X4ctLtGPhX6rKjiHkZStCBMJNepvTF+pkl/zge1E8N8z8I1LSCkp8X WecX/q/jmWanGrBsVHdnwsiOmKgqBvrGsCe7XRMacpNoxIA/kSC8G4FZIJb/xUDi7X9o zeVRD/Mu/xiRiX9VxiR6tR/2Dl6QOMqNy6K49WCKf7MfpheVpO6RL5xrHx9cFS0+ln4H N/HHU4cSUnnEUbRVkxEntlwXgM2U3zpEomOXJGNIXD95IksIhtOOKlEPy2ZiS/bKQ6k4 Q5hsguzrUbH80TD9pd/YwhnaAWJL3QuW8kEUg8CtZGvoHnJ4lZxI6083i3eskYkZKQBe UEoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=yCXZ9Dt+l0jW0In/qIcAmkWaXPLVlr/wK7RKpfxZjCQ=; b=cFdHdLS6tkiWv+zfectZfKNNvq7ByqMm3znzYySl6nerINAB9C3enEWrSx0KnNfOOp XJnSBo4Q4sy8CNNAng8w9UhQ/9wWGGxp215lr54OCeAc5c7DN5LNIVNdiSHkgVKwWVNg cc5J6G02vzVfspJOHeyyZtwrIOBEemt6xQ4zswNP4SfuepJD5YIDRHkfNqbk74x7AR8w Ts+N48Tg/uLqOUJpnxRXN4/Gken2ZPIXNHBimgyotcia2WTTWlBHlmQIvid3yeYpfMym clO7+kgxW7+z0FpouYStFB1usN5GLHqm0UTCbr8HUtUeJVMXhnU5uvNkodSgQ0PMqlFQ OhMg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v17-20020a170902d09100b00176b4e9985esi10671878plv.439.2022.09.13.01.20.09; Tue, 13 Sep 2022 01:20:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230132AbiIMHje (ORCPT + 99 others); Tue, 13 Sep 2022 03:39:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229743AbiIMHja (ORCPT ); Tue, 13 Sep 2022 03:39:30 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1DBA246 for ; Tue, 13 Sep 2022 00:39:28 -0700 (PDT) Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] helo=[IPv6:::1]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oY0Vc-00046v-Sy; Tue, 13 Sep 2022 09:39:04 +0200 Message-ID: <0660fff6d29c5f8251ac4f28d4badcfea91e6833.camel@pengutronix.de> Subject: Re: [PATCH] PCI: imx6: Fix wrong check in imx6_pcie_attach_pd() From: Lucas Stach To: Tang Bin , hongxing.zhu@nxp.com, lorenzo.pieralisi@arm.com, robh@kernel.org, kw@linux.com, shawnguo@kernel.org, bhelgaas@google.com, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Date: Tue, 13 Sep 2022 09:39:03 +0200 In-Reply-To: <20220913065910.15348-1-tangbin@cmss.chinamobile.com> References: <20220913065910.15348-1-tangbin@cmss.chinamobile.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.4 (3.40.4-1.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 2001:67c:670:201:5054:ff:fe8d:eefb X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Am Dienstag, dem 13.09.2022 um 14:59 +0800 schrieb Tang Bin: > In the function imx6_pcie_attach_pd(), > dev_pm_domain_attach_by_name() may return NULL in some cases, > so IS_ERR() doesn't meet the requirements. Thus fix it. > I don't like this added complexity in the driver. IHMO if there is a real issue, dev_pm_domain_attach_by_name() should just return a error code, instead of NULL. The fact that you need to pull a error code out of thin air in the driver is a big hint that this should be fixed in the called function, not in the return handling in the driver. A bit down the callstack genpd_dev_pm_attach_by_id() is called, which is documented like this "Returns the created virtual device if successfully attached PM domain, NULL when the device don't need a PM domain [...]". NULL is a valid return code, where the driver should _not_ stop probing, as the device should work without the power domain attached. Regards, Lucas > Fixes: 3f7cceeab895 ("PCI: imx: Add multi-pd support") > Signed-off-by: Tang Bin > --- > drivers/pci/controller/dwc/pci-imx6.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c > index 6619e3caf..65d6ebbba 100644 > --- a/drivers/pci/controller/dwc/pci-imx6.c > +++ b/drivers/pci/controller/dwc/pci-imx6.c > @@ -337,8 +337,8 @@ static int imx6_pcie_attach_pd(struct device *dev) > return 0; > > imx6_pcie->pd_pcie = dev_pm_domain_attach_by_name(dev, "pcie"); > - if (IS_ERR(imx6_pcie->pd_pcie)) > - return PTR_ERR(imx6_pcie->pd_pcie); > + if (IS_ERR_OR_NULL(imx6_pcie->pd_pcie)) > + return PTR_ERR(imx6_pcie->pd_pcie) ? : -ENODATA; > /* Do nothing when power domain missing */ > if (!imx6_pcie->pd_pcie) > return 0; > @@ -352,8 +352,8 @@ static int imx6_pcie_attach_pd(struct device *dev) > } > > imx6_pcie->pd_pcie_phy = dev_pm_domain_attach_by_name(dev, "pcie_phy"); > - if (IS_ERR(imx6_pcie->pd_pcie_phy)) > - return PTR_ERR(imx6_pcie->pd_pcie_phy); > + if (IS_ERR_OR_NULL(imx6_pcie->pd_pcie_phy)) > + return PTR_ERR(imx6_pcie->pd_pcie_phy) ? : -ENODATA; > > link = device_link_add(dev, imx6_pcie->pd_pcie_phy, > DL_FLAG_STATELESS |