From nobody Tue Jun 23 07:07:43 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17D5DC433EF for ; Wed, 9 Mar 2022 12:01:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232597AbiCIMCO (ORCPT ); Wed, 9 Mar 2022 07:02:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231179AbiCIMCK (ORCPT ); Wed, 9 Mar 2022 07:02:10 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04C79157228; Wed, 9 Mar 2022 04:01:11 -0800 (PST) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4KD9dY6bNCz1GByS; Wed, 9 Mar 2022 19:56:17 +0800 (CST) Received: from kwepeml500003.china.huawei.com (7.221.188.182) by kwepemi500012.china.huawei.com (7.221.188.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 9 Mar 2022 20:01:06 +0800 Received: from [10.136.108.160] (10.136.108.160) by kwepeml500003.china.huawei.com (7.221.188.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.21; Wed, 9 Mar 2022 20:01:05 +0800 Subject: [PATCH v2] PCI: dwc: Fix setting error return on MSI DMA mapping failure References: To: , Bjorn Helgaas , "jingoohan1@gmail.com" , "gustavo.pimentel@synopsys.com" , "lorenzo.pieralisi@arm.com" , "kw@linux.com" , "linux-pci@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "zhangjianrong (E)" CC: caiyadong , "xuetao (kirin)" , xuhaiyang , , From: Jiantao Zhang X-Forwarded-Message-Id: Message-ID: <30170911-0e2f-98ce-9266-70465b9073e5@huawei.com> Date: Wed, 9 Mar 2022 20:01:04 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.136.108.160] X-ClientProxiedBy: dggeme712-chm.china.huawei.com (10.1.199.108) To kwepeml500003.china.huawei.com (7.221.188.182) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When dma_mapping_error() returns error because of no enough memory, but dw_pcie_host_init() returns success, which will mislead the callers. Fixes: 07940c369a6b ("PCI: dwc: Fix MSI page leakage in suspend/resume") Signed-off-by: Jianrong Zhang Signed-off-by: Jiantao Zhang Reviewed-by: Rob Herring --- =C2=A0drivers/pci/controller/dwc/pcie-designware-host.c | 3 ++- =C2=A01 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pc= i/controller/dwc/pcie-designware-host.c index f4755f3a03be..9dcb51728dd1 100644 --- a/drivers/pci/controller/dwc/pcie-designware-host.c +++ b/drivers/pci/controller/dwc/pcie-designware-host.c @@ -390,7 +390,8 @@ int dw_pcie_host_init(struct pcie_port *pp) =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2= =A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 sizeof(pp->msi_msg), =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2= =A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 DMA_FROM_DEVICE, =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2= =A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 DMA_ATTR_SKIP_CPU_SYNC); -=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 if (dma_mapping_e= rror(pci->dev, pp->msi_data)) { +=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 ret =3D dma_mappi= ng_error(pci->dev, pp->msi_data); +=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 if (ret) { =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2= =A0=C2=A0 dev_err(pci->dev, "Failed to map MSI data\n"); =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2= =A0=C2=A0 pp->msi_data =3D 0; =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2= =A0=C2=A0 goto err_free_msi; -- 2.17.1 Jiantao Zhang On Tue, Mar 8, 2022 at 9:45 AM Zhangjiantao(Kirin,Nanjing) wrote: > When dma_mapping_error() returns error because of no enough memory availa= ble, dw_pcie_host_init() will return success, which will mislead the caller= s. Again, wrap long lines. And please reword the subject as I previously=20 suggested. It should be 'PATCH v2', not 'PATCH2' in the subject. 'git send-email -v2' does that for you. > Fixes: 07940c369a6b ("PCI: dwc: Fix MSI page leakage in suspend/resume") > Drop the blank line here. > Signed-off-by: Jiantao Zhang As you are sending the patch, your S-o-b goes last. And the author name still doesn't match here: 'Jiantao Zhang' vs. 'Zhangjiantao(Kirin,Nanjing)' > Signed-off-by: Jianrong Zhang > --- > drivers/pci/controller/dwc/pcie-designware-host.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c > b/drivers/pci/controller/dwc/pcie-designware-host.c > index f4755f3a03be..9dcb51728dd1 100644 > --- a/drivers/pci/controller/dwc/pcie-designware-host.c > +++ b/drivers/pci/controller/dwc/pcie-designware-host.c > @@ -390,7 +390,8 @@ int dw_pcie_host_init(struct pcie_port *pp) > sizeof(pp->msi_msg), > DMA_FROM_DEVICE, > DMA_ATTR_SKIP_CPU_SYNC); > - if (dma_mapping_error(pci->dev, pp->msi_data)) { > + ret =3D dma_mapping_error(pci->dev, pp->msi_data); > + if (ret) { > dev_err(pci->dev, "Failed to map MSI data\n"); > pp->msi_data =3D 0; > goto err_free_msi; > -- > 2.17.1 > > Jiantao Zhang > > On 2022/3/5 5:39, Bjorn Helgaas wrote: >> On Fri, Mar 04, 2022 at 12:06:10PM +0000, Zhangjiantao(Kirin,Nanjing) wr= ote: All this should not be in new versions of patches. >>> When dma_mapping_error returns error because of no enough memory availa= ble, dw_pcie_host_init will return success, which will mislead the callers. >> Wrap to fit in 75 columns, add "()" after function names. >>> Signed-off-by: zhangjianrong >>> Signed-off-by: zhangjiantao >>> >>> --- >>> drivers/pci/controller/dwc/pcie-designware-host.c | 1 + >>> 1 file changed, 1 insertion(+) >>> >>> diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c >>> b/drivers/pci/controller/dwc/pcie-designware-host.c >>> index f4755f3a03be..ac691d733848 100644 >>> --- a/drivers/pci/controller/dwc/pcie-designware-host.c >>> +++ b/drivers/pci/controller/dwc/pcie-designware-host.c >>> @@ -393,6 +393,7 @@ int dw_pcie_host_init(struct pcie_port *pp) >>> if (dma_mapping_error(pci->dev, pp->msi_data)) { >>> dev_err(pci->dev, "Failed to map MSI data\n"); >>> pp->msi_data =3D 0; >>> + ret =3D -1; >> We should save the return value from dma_mapping_error() and return >> *that*, not -1. >> >> Whitespace error (indent with tabs, same as the surrounding code). >> >>> goto err_free_msi; >>> } >>> } >>> -- >>> 2.17.1 >>> >> .