From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 DBE75C43217 for ; Mon, 31 Jan 2022 23:11:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:References: List-Owner; bh=IRMyPoEpvnELsznvf3clJO2IQf5Vp+cQL534oLgJv/w=; b=MINgTj6wMw3xSP B4m3AIkVK2kH6YX4satsWxV1OAnGFsIDXwoeUbKnwPIEBjdHmJqol/qhCCgrnTPlLIaOTk4OUaBIU 0aKW7unifbPkSqXvbu6SDBqXnShUsVhCa6nxam2JvaVgbgt2wZM0LF0wu77t0Rd+BCNlx9ooKt3Dh h+GqqMzLSy6kaqlhxgkW0szUo1X2u6vWQ6nW0mwNugR9GHyMqGqtRd+PsYpc1OanYGX9IJDRmU6Px gbscWXtRMKVVgWTBuTlfFU/rqzPuRcmXAsq1IT9REY39z6062uSUycTuKEG09mHll2TRL+AK5uHVf /IjXVgZ/JdZqey5Xi5fA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nEfog-00AmIE-Bw; Mon, 31 Jan 2022 23:10:34 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nEfoc-00AmHO-25 for linux-arm-kernel@lists.infradead.org; Mon, 31 Jan 2022 23:10:32 +0000 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 7D4D2B82B29; Mon, 31 Jan 2022 23:10:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC6E3C340E8; Mon, 31 Jan 2022 23:10:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643670627; bh=Hkjw6+MAcCgqVnvifUYtv2EIGwOteYf/ehOvmNFrF8o=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=iygtNL1+vX1CeRgtp2DWx5gyjnV+/FtYS2FTwBemH+FnH6PSZF+C9at4UuMgL59wl lz9dimQJDnbin5MWq4xSqgPzuzRQ+PPg5XD1mtIn4ld6R2O9hYfGnn7r+fPe/wiGYJ q/DdnP8k49bATixK3Ef/JTZqp42W5H/CdKlaVpPZ4EX7/Dhraz8SyaSyNUTHfMmE3h rQuBCSS9lSOT043Wj66mzvgziF+/HJdGSgEi/cSUX39R+GtREtxljY6I1qrdYYjQ7h BdbbD649yXB7F/aPlZzegoPbaBJMjTmofn9DQHB/AAv6v7rw7yM8eJKc1OA5yIjAFG IOLuDHTikBj6A== Date: Mon, 31 Jan 2022 17:10:25 -0600 From: Bjorn Helgaas To: Christian Gmeiner Cc: LKML , Kishon Vijay Abraham I , Tom Joseph , Lorenzo Pieralisi , Rob Herring , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Bjorn Helgaas , linux-omap@vger.kernel.org, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH] Revert "PCI: j721e: Drop redundant struct device *" Message-ID: <20220131231025.GA516499@bhelgaas> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220131_151030_447165_5581C164 X-CRM114-Status: GOOD ( 28.48 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Jan 31, 2022 at 12:06:21PM +0100, Christian Gmeiner wrote: > Am Do., 27. Jan. 2022 um 23:29 Uhr schrieb Bjorn Helgaas : > > > > On Mon, Jan 24, 2022 at 01:21:22PM +0100, Christian Gmeiner wrote: > > > This reverts commit 19e863828acf6d8ac8475ba1fd93c0fe17fdc4ef. > > > > > > Fixes the following oops: > > > Unable to handle kernel NULL pointer dereference at virtual address 0000000000000010 > > > > Hi Christian, > > > > Would you mind trying this patch? > > > > Works - thanks. You can add my Tested-by. Thanks, applied to for-linus for v5.17. > > > commit 9d36a93af8fe ("PCI: j721e: Initialize pcie->cdns_pcie before using it") > > Author: Bjorn Helgaas > > Date: Thu Jan 27 15:49:49 2022 -0600 > > > > PCI: j721e: Initialize pcie->cdns_pcie before using it > > > > Christian reported a NULL pointer dereference in j721e_pcie_probe() caused > > by 19e863828acf ("PCI: j721e: Drop redundant struct device *"), which > > removed struct j721e_pcie.dev since there's another copy in struct > > cdns_pcie.dev reachable via j721e_pcie->cdns_pcie->dev. > > > > The problem is that j721e_pcie->cdns_pcie was dereferenced before being > > initialized: > > > > j721e_pcie_probe > > pcie = devm_kzalloc() # struct j721e_pcie > > j721e_pcie_ctrl_init(pcie) > > dev = pcie->cdns_pcie->dev <-- dereference cdns_pcie > > switch (mode) { > > case PCI_MODE_RC: > > cdns_pcie = ... # alloc as part of pci_host_bridge > > pcie->cdns_pcie = cdns_pcie <-- initialize pcie->cdns_pcie > > > > Initialize pcie->cdns_pcie before it is used. > > > > Fixes: 19e863828acf ("PCI: j721e: Drop redundant struct device *") > > Reported-by: Christian Gmeiner > > Link: https://lore.kernel.org/r/20220124122132.435743-1-christian.gmeiner@gmail.com > > Signed-off-by: Bjorn Helgaas > > > > diff --git a/drivers/pci/controller/cadence/pci-j721e.c b/drivers/pci/controller/cadence/pci-j721e.c > > index 489586a4cdc7..5d950c1d9fd0 100644 > > --- a/drivers/pci/controller/cadence/pci-j721e.c > > +++ b/drivers/pci/controller/cadence/pci-j721e.c > > @@ -372,10 +372,48 @@ static int j721e_pcie_probe(struct platform_device *pdev) > > > > mode = (u32)data->mode; > > > > + switch (mode) { > > + case PCI_MODE_RC: > > + if (!IS_ENABLED(CONFIG_PCIE_CADENCE_HOST)) > > + return -ENODEV; > > + > > + bridge = devm_pci_alloc_host_bridge(dev, sizeof(*rc)); > > + if (!bridge) > > + return -ENOMEM; > > + > > + if (!data->byte_access_allowed) > > + bridge->ops = &cdns_ti_pcie_host_ops; > > + rc = pci_host_bridge_priv(bridge); > > + rc->quirk_retrain_flag = data->quirk_retrain_flag; > > + rc->quirk_detect_quiet_flag = data->quirk_detect_quiet_flag; > > + > > + cdns_pcie = &rc->pcie; > > + break; > > + case PCI_MODE_EP: > > + if (!IS_ENABLED(CONFIG_PCIE_CADENCE_EP)) > > + return -ENODEV; > > + > > + ep = devm_kzalloc(dev, sizeof(*ep), GFP_KERNEL); > > + if (!ep) > > + return -ENOMEM; > > + > > + ep->quirk_detect_quiet_flag = data->quirk_detect_quiet_flag; > > + > > + cdns_pcie = &ep->pcie; > > + break; > > + default: > > + dev_err(dev, "INVALID device type %d\n", mode); > > + return 0; > > + } > > + > > + cdns_pcie->dev = dev; > > + cdns_pcie->ops = &j721e_pcie_ops; > > + > > pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); > > if (!pcie) > > return -ENOMEM; > > > > + pcie->cdns_pcie = cdns_pcie; > > pcie->mode = mode; > > pcie->linkdown_irq_regfield = data->linkdown_irq_regfield; > > > > @@ -426,28 +464,6 @@ static int j721e_pcie_probe(struct platform_device *pdev) > > > > switch (mode) { > > case PCI_MODE_RC: > > - if (!IS_ENABLED(CONFIG_PCIE_CADENCE_HOST)) { > > - ret = -ENODEV; > > - goto err_get_sync; > > - } > > - > > - bridge = devm_pci_alloc_host_bridge(dev, sizeof(*rc)); > > - if (!bridge) { > > - ret = -ENOMEM; > > - goto err_get_sync; > > - } > > - > > - if (!data->byte_access_allowed) > > - bridge->ops = &cdns_ti_pcie_host_ops; > > - rc = pci_host_bridge_priv(bridge); > > - rc->quirk_retrain_flag = data->quirk_retrain_flag; > > - rc->quirk_detect_quiet_flag = data->quirk_detect_quiet_flag; > > - > > - cdns_pcie = &rc->pcie; > > - cdns_pcie->dev = dev; > > - cdns_pcie->ops = &j721e_pcie_ops; > > - pcie->cdns_pcie = cdns_pcie; > > - > > gpiod = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); > > if (IS_ERR(gpiod)) { > > ret = PTR_ERR(gpiod); > > @@ -497,23 +513,6 @@ static int j721e_pcie_probe(struct platform_device *pdev) > > > > break; > > case PCI_MODE_EP: > > - if (!IS_ENABLED(CONFIG_PCIE_CADENCE_EP)) { > > - ret = -ENODEV; > > - goto err_get_sync; > > - } > > - > > - ep = devm_kzalloc(dev, sizeof(*ep), GFP_KERNEL); > > - if (!ep) { > > - ret = -ENOMEM; > > - goto err_get_sync; > > - } > > - ep->quirk_detect_quiet_flag = data->quirk_detect_quiet_flag; > > - > > - cdns_pcie = &ep->pcie; > > - cdns_pcie->dev = dev; > > - cdns_pcie->ops = &j721e_pcie_ops; > > - pcie->cdns_pcie = cdns_pcie; > > - > > ret = cdns_pcie_init_phy(dev, cdns_pcie); > > if (ret) { > > dev_err(dev, "Failed to init phy\n"); > > @@ -525,8 +524,6 @@ static int j721e_pcie_probe(struct platform_device *pdev) > > goto err_pcie_setup; > > > > break; > > - default: > > - dev_err(dev, "INVALID device type %d\n", mode); > > } > > > > return 0; > > > > -- > greets > -- > Christian Gmeiner, MSc > > https://christian-gmeiner.info/privacypolicy _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel