Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1606447pxb; Wed, 2 Feb 2022 08:32:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJzu20QydydwMYKESQphL1VvWq+zb2EUNpwDT9DazR6wd+4AhdI4v62dN5Iw79pOUI3fNQuR X-Received: by 2002:a05:6a00:2183:: with SMTP id h3mr30438811pfi.12.1643819555528; Wed, 02 Feb 2022 08:32:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643819555; cv=none; d=google.com; s=arc-20160816; b=kv/JI+AYPst4eWZ6TxlvGVxg099Syy+bz8B6AafFc9TbbWx7CBSeThrCZd+pECdLkz +YCO6ESKwvkRY8Y1vCpbOIsIH4JH+yg6WF4hC4R85hPzOwyuZyR6TxNBCpKiQ+LUupGn gUzprI1Njn/Jn5unBn0GCeXC5efU7G3wodtDDHB9ghvRzx1jxVoUGI609FXQ1yEMvocs 7m4EiVoN9q+YYOlIOBH4joXGIVGTWfb+v+jvYlkeBpHiCAX5sK6JjsJllbfISlir3wPw C1pQsK5rbST+c7nDFOE7nMPCG7VHA4kIDnDW60DuVB24uXl21/aQP/rYGwpH7ZlrWChr l0AA== 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 :message-id:subject:cc:to:from:date:dkim-signature; bh=vln2sM9pCCrhBYxpSMN4Gqn23Ahcl9oF+QD0rlxzoQk=; b=LWML7HbdCLqzIubhMQHsP2WdTMRPJRmH72wDxO7VtVYoLuWfmaRPYmA4lUf0qOaTcR dqdC9U5aw4nHiHHAr/fdtnJSGvB06KpxpanJuQ/Gtn47joJk8yNlxWFgliaQ8l+TdHwz cpMnEQkYXcBdxmo37tM58+V+K3EubbHsTfOBQs5KwwnjVno/pmb+hPrmuJE3tt17IXJW SE2NVjf/rlvOnMCQffrX45GGWwM4/SYz+A+TB/M77Q62qGO/2k/kuxDgh0+RQVXRUWw7 R90C3WXAS80dJ7dcJ2I5NDgbgnWyigQIUeTIwR6Wp5zM99kPdzAd+Wj7xbSB+08h/nc9 5R+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=K73FD6+W; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m20si21016386pfk.347.2022.02.02.08.32.23; Wed, 02 Feb 2022 08:32:35 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=K73FD6+W; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345516AbiBBQ1E (ORCPT + 99 others); Wed, 2 Feb 2022 11:27:04 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:56752 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbiBBQ1D (ORCPT ); Wed, 2 Feb 2022 11:27:03 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B586FB831CC; Wed, 2 Feb 2022 16:27:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19804C004E1; Wed, 2 Feb 2022 16:27:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643819221; bh=/6AdJ151vtPtk0WKaX19Tuqhdk+nrfD5Ht+dGm+9Dfc=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=K73FD6+WqKnR1ng2l3l3P8iKdn+AvVokx159QXl92lLQgSD6fVFw+MqJ/G71E/fVH h4qlBqFBJOeN+AUrfnxjJb4dfGI32WeSe4s+6Jv8zMiIC1ywiJfTo91WqL/zNbpieW Mb8uCMouUzpd+1ebu23H4JvjMTWCzDE+Rc+OIHXiM5A+rSm2OJkiaZnGyy3guISO1u GUTvuLWT6afMOZp3gHgGrI9cLIfskR0kMsGkBNgueVBSHkGVDHabg2oIEQPpGlq0bT ZxuW4m8XzoMRpyYClZvwbbXEFkNF5QLytAUgNXQWd82CHnXkWTlPZ5orsM6n6HRZhI bHa5fbc2/3pQA== Date: Wed, 2 Feb 2022 10:26:59 -0600 From: Bjorn Helgaas To: Bean Huo Cc: songxiaowei@hisilicon.com, wangbinghui@hisilicon.com, lorenzo.pieralisi@arm.com, robh@kernel.org, kw@linux.com, bhelgaas@google.com, ffclaire1224@gmail.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, beanhuo@micron.com Subject: Re: [PATCH] PCI: kirin: Fix kirin960-pcie probe failure issue Message-ID: <20220202162659.GA12603@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220201215941.1203155-1-huobean@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [+cc Fan] If you're fixing a previous commit, please cc the author of that commit. I'd prefer the patch below because it avoids the casts of .data and the of_device_get_match_data() result, it doesn't silently default to PCIE_KIRIN_INTERNAL_PHY if a device without a .data is added, and it's the most common design pattern in drivers/pci/. What do you think? On Tue, Feb 01, 2022 at 10:59:41PM +0100, Bean Huo wrote: > From: Bean Huo > > of_device_get_match_data() will return 'enum pcie_kirin_phy_type' type > value, and most likely the return value will be PCIE_KIRIN_INTERNAL_PHY == 0. > This will cause the PCI probe to fail. And of_device_get_match_data() does not > require error checking on its return on devicetree based platform. > > So,this patch is to remove unnecessary error checking to fix kirin960-pcie > probe failure issue. > > Fixes: a622435fbe1a ("PCI: kirin: Prefer of_device_get_match_data()") > Signed-off-by: Bean Huo > --- > drivers/pci/controller/dwc/pcie-kirin.c | 7 +------ > 1 file changed, 1 insertion(+), 6 deletions(-) > > diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c > index fa6886d66488..e102aa6efb7f 100644 > --- a/drivers/pci/controller/dwc/pcie-kirin.c > +++ b/drivers/pci/controller/dwc/pcie-kirin.c > @@ -781,12 +781,7 @@ static int kirin_pcie_probe(struct platform_device *pdev) > return -EINVAL; > } > > - phy_type = (long)of_device_get_match_data(dev); > - if (!phy_type) { > - dev_err(dev, "OF data missing\n"); > - return -EINVAL; > - } > - > + phy_type = (enum pcie_kirin_phy_type)of_device_get_match_data(dev); > > kirin_pcie = devm_kzalloc(dev, sizeof(struct kirin_pcie), GFP_KERNEL); > if (!kirin_pcie) commit 3e21687be135 ("PCI: kirin: Add dev struct for of_device_get_match_data()") Author: Bjorn Helgaas Date: Wed Feb 2 09:52:41 2022 -0600 PCI: kirin: Add dev struct for of_device_get_match_data() a622435fbe1a ("PCI: kirin: Prefer of_device_get_match_data()") broke kirin_pcie_probe() because it assumed match data of 0 was a failure when in fact, it meant the match data was "(void *)PCIE_KIRIN_INTERNAL_PHY". Therefore, probing of "hisilicon,kirin960-pcie" devices failed with -EINVAL and an "OF data missing" message. Add a struct kirin_pcie_data to encode the PHY type. Then the result of of_device_get_match_data() should always be a non-NULL pointer to a struct kirin_pcie_data that contains the PHY type. Fixes: a622435fbe1a ("PCI: kirin: Prefer of_device_get_match_data()") Signed-off-by: Bjorn Helgaas diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c index fa6886d66488..0dc4e3395b37 100644 --- a/drivers/pci/controller/dwc/pcie-kirin.c +++ b/drivers/pci/controller/dwc/pcie-kirin.c @@ -756,21 +756,27 @@ static int __exit kirin_pcie_remove(struct platform_device *pdev) return 0; } +struct kirin_pcie_data { + enum pcie_kirin_phy_type phy_type; +}; + +static const struct kirin_pcie_data kirin_960_data = { + .phy_type = PCIE_KIRIN_INTERNAL_PHY; +}; + +static const struct kirin_pcie_data kirin_970_data = { + .phy_type = PCIE_KIRIN_EXTERNAL_PHY; +}; + static const struct of_device_id kirin_pcie_match[] = { - { - .compatible = "hisilicon,kirin960-pcie", - .data = (void *)PCIE_KIRIN_INTERNAL_PHY - }, - { - .compatible = "hisilicon,kirin970-pcie", - .data = (void *)PCIE_KIRIN_EXTERNAL_PHY - }, + { .compatible = "hisilicon,kirin960-pcie", .data = &kirin_960_data }, + { .compatible = "hisilicon,kirin970-pcie", .data = &kirin_970_data }, {}, }; static int kirin_pcie_probe(struct platform_device *pdev) { - enum pcie_kirin_phy_type phy_type; + struct kirin_pcie_data *data; struct device *dev = &pdev->dev; struct kirin_pcie *kirin_pcie; struct dw_pcie *pci; @@ -781,13 +787,12 @@ static int kirin_pcie_probe(struct platform_device *pdev) return -EINVAL; } - phy_type = (long)of_device_get_match_data(dev); - if (!phy_type) { + data = of_device_get_match_data(dev); + if (!data) { dev_err(dev, "OF data missing\n"); return -EINVAL; } - kirin_pcie = devm_kzalloc(dev, sizeof(struct kirin_pcie), GFP_KERNEL); if (!kirin_pcie) return -ENOMEM; @@ -800,7 +805,7 @@ static int kirin_pcie_probe(struct platform_device *pdev) pci->ops = &kirin_dw_pcie_ops; pci->pp.ops = &kirin_pcie_host_ops; kirin_pcie->pci = pci; - kirin_pcie->type = phy_type; + kirin_pcie->type = data->phy_type; ret = kirin_pcie_get_resource(kirin_pcie, pdev); if (ret)