Message ID | e94f99cfe09a64c590f009d21c566339117394e2.1666098844.git.robin.murphy@arm.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1954115wrs; Tue, 18 Oct 2022 06:16:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7/QaHimQHCyEZNImmnErFjPzoWaxopACW+2FuinuD++DlH099vCKyVXFi0MoFQfl/KMqRp X-Received: by 2002:a17:90a:582:b0:20a:97f6:f52e with SMTP id i2-20020a17090a058200b0020a97f6f52emr3587749pji.126.1666098974347; Tue, 18 Oct 2022 06:16:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666098974; cv=none; d=google.com; s=arc-20160816; b=fyg3LCd8006Q8ksNx34L8VZgO9l9QyElm+9XY/1TDnERlMDRMaqbnZHoWQbMLQhTm1 UaTwmiimyXirjuQg/FC5PDlkeCHI13IE9zgptrr0Wx21/tPwoRC7SdC/QmS94VB1DJ10 tjc6dP1nJ1RjDPXgslblZ+BTi+POy9KzLkGKBN75ENEcCO2U9FohKMngZptdb3mVzAZQ ualYQs/SmvWKRzXOTV6nfNX/TfoEvujichTbQsRLROFJz7azz8mmADzjRstRCBgT8sBb QBcSel6Lbcv7ky65c+Qvn9GA8i9raEQ9j019/RAaSed5DFAtHC57iXiZcQ4E+SwPQZ3E wTbA== 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 :message-id:date:subject:cc:to:from; bh=7h7UqOojYD8RvdtSAbeuxl3QhW5dKBpfcGwN18nhPFw=; b=HZLnc+AEbRRNRSqOg+HWSvW8FstDirFxNVG/emm4+d710kaIjcQtUKibU4GIIS76KC lHMrBMnLl0biQtdX1fGJN4zcPmJpR9w9in20GNaAMIpfqe9EL27L+jIzW4DKM3oyFXkf hka/XlR7BO/esWBfWDBL8WYnyMqOJDy8GRDFrM0OM4pzsVsPedTv50Okm9SomVdGAyKt 4cFSMqLvLTRj2mwB21WY5wKA/ZuAvYOSdgT9xScOJQPXK3/FGsJthUecUeaa2fdvepty NMecpDM3MhB6WiwMKjpqy0BbW1MdmmVbSFsXXV3GNtarnu0VqCG33Ezb8K3E01IoUzgG 7G2w== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l1-20020a056a00140100b0056191854bb4si16172409pfu.291.2022.10.18.06.16.00; Tue, 18 Oct 2022 06:16:14 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229574AbiJRNOR (ORCPT <rfc822;carlos.wei.hk@gmail.com> + 99 others); Tue, 18 Oct 2022 09:14:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbiJRNOQ (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 18 Oct 2022 09:14:16 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7C949C7070; Tue, 18 Oct 2022 06:14:15 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 79216113E; Tue, 18 Oct 2022 06:14:21 -0700 (PDT) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0A0383F792; Tue, 18 Oct 2022 06:14:13 -0700 (PDT) From: Robin Murphy <robin.murphy@arm.com> To: rafael@kernel.org Cc: lvjianmin@loongson.cn, yangyicong@huawei.com, lpieralisi@kernel.org, chenhuacai@loongson.cn, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, lenb@kernel.org, jeremy.linton@arm.com Subject: [PATCH] ACPI: scan: Fix DMA range assignment Date: Tue, 18 Oct 2022 14:14:04 +0100 Message-Id: <e94f99cfe09a64c590f009d21c566339117394e2.1666098844.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.36.1.dirty MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747031398258397596?= X-GMAIL-MSGID: =?utf-8?q?1747031398258397596?= |
Series |
ACPI: scan: Fix DMA range assignment
|
|
Commit Message
Robin Murphy
Oct. 18, 2022, 1:14 p.m. UTC
Assigning the device's dma_range_map from the iterator variable after
the loop means it always points to the empty terminator at the end of
the map, which is not what we want. Similarly, freeing the iterator on
error when it points to somwhere in the middle of the allocated array
won't work either. Fix this.
Fixes: bf2ee8d0c385 ("ACPI: scan: Support multiple DMA windows with different offsets")
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---
drivers/acpi/scan.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
Comments
Seems good. Thanks very much. Reviewed-by: Jianmin Lv <lvjianmin@loongson.cn> On 2022/10/18 下午9:14, Robin Murphy wrote: > Assigning the device's dma_range_map from the iterator variable after > the loop means it always points to the empty terminator at the end of > the map, which is not what we want. Similarly, freeing the iterator on > error when it points to somwhere in the middle of the allocated array > won't work either. Fix this. > > Fixes: bf2ee8d0c385 ("ACPI: scan: Support multiple DMA windows with different offsets") > Signed-off-by: Robin Murphy <robin.murphy@arm.com> > --- > drivers/acpi/scan.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c > index 558664d169fc..024cc373a197 100644 > --- a/drivers/acpi/scan.c > +++ b/drivers/acpi/scan.c > @@ -1509,9 +1509,12 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map) > goto out; > } > > + *map = r; > + > list_for_each_entry(rentry, &list, node) { > if (rentry->res->start >= rentry->res->end) { > - kfree(r); > + kfree(*map); > + *map = NULL; > ret = -EINVAL; > dev_dbg(dma_dev, "Invalid DMA regions configuration\n"); > goto out; > @@ -1523,8 +1526,6 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map) > r->offset = rentry->offset; > r++; > } > - > - *map = r; > } > out: > acpi_dev_free_resource_list(&list); >
Hi, On 10/18/22 08:14, Robin Murphy wrote: > Assigning the device's dma_range_map from the iterator variable after > the loop means it always points to the empty terminator at the end of > the map, which is not what we want. Similarly, freeing the iterator on > error when it points to somwhere in the middle of the allocated array > won't work either. Fix this. This fixes the boot problem on both SoC generations of the rpi4+ACPI, Thanks, Tested-by: Jeremy Linton <jeremy.linton@arm.com> > > Fixes: bf2ee8d0c385 ("ACPI: scan: Support multiple DMA windows with different offsets") > Signed-off-by: Robin Murphy <robin.murphy@arm.com> > --- > drivers/acpi/scan.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c > index 558664d169fc..024cc373a197 100644 > --- a/drivers/acpi/scan.c > +++ b/drivers/acpi/scan.c > @@ -1509,9 +1509,12 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map) > goto out; > } > > + *map = r; > + > list_for_each_entry(rentry, &list, node) { > if (rentry->res->start >= rentry->res->end) { > - kfree(r); > + kfree(*map); > + *map = NULL; > ret = -EINVAL; > dev_dbg(dma_dev, "Invalid DMA regions configuration\n"); > goto out; > @@ -1523,8 +1526,6 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map) > r->offset = rentry->offset; > r++; > } > - > - *map = r; > } > out: > acpi_dev_free_resource_list(&list);
On 2022/10/18 21:14, Robin Murphy wrote: > Assigning the device's dma_range_map from the iterator variable after > the loop means it always points to the empty terminator at the end of > the map, which is not what we want. Similarly, freeing the iterator on > error when it points to somwhere in the middle of the allocated array > won't work either. Fix this. > > Fixes: bf2ee8d0c385 ("ACPI: scan: Support multiple DMA windows with different offsets") Thanks for fixing this. Works on my platform. Tested-by: Yicong Yang <yangyicong@hisilicon.com> > Signed-off-by: Robin Murphy <robin.murphy@arm.com> > --- > drivers/acpi/scan.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c > index 558664d169fc..024cc373a197 100644 > --- a/drivers/acpi/scan.c > +++ b/drivers/acpi/scan.c > @@ -1509,9 +1509,12 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map) > goto out; > } > > + *map = r; > + > list_for_each_entry(rentry, &list, node) { > if (rentry->res->start >= rentry->res->end) { > - kfree(r); > + kfree(*map); > + *map = NULL; > ret = -EINVAL; > dev_dbg(dma_dev, "Invalid DMA regions configuration\n"); > goto out; > @@ -1523,8 +1526,6 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map) > r->offset = rentry->offset; > r++; > } > - > - *map = r; > } > out: > acpi_dev_free_resource_list(&list); >
On Tue, Oct 18, 2022 at 02:14:04PM +0100, Robin Murphy wrote: > Assigning the device's dma_range_map from the iterator variable after > the loop means it always points to the empty terminator at the end of > the map, which is not what we want. Similarly, freeing the iterator on > error when it points to somwhere in the middle of the allocated array > won't work either. Fix this. > > Fixes: bf2ee8d0c385 ("ACPI: scan: Support multiple DMA windows with different offsets") > Signed-off-by: Robin Murphy <robin.murphy@arm.com> > --- > drivers/acpi/scan.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) A quick comment below, otherwise: Reviewed-by: Lorenzo Pieralisi <lpieralisi@kernel.org> > diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c > index 558664d169fc..024cc373a197 100644 > --- a/drivers/acpi/scan.c > +++ b/drivers/acpi/scan.c > @@ -1509,9 +1509,12 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map) > goto out; > } > > + *map = r; I wonder whether having a local variable to stash the base pointer would make code easier to read (so that we avoid using *map for that purpose and also to return the array to the caller). Thanks for fixing it so promptly. Lorenzo > + > list_for_each_entry(rentry, &list, node) { > if (rentry->res->start >= rentry->res->end) { > - kfree(r); > + kfree(*map); > + *map = NULL; > ret = -EINVAL; > dev_dbg(dma_dev, "Invalid DMA regions configuration\n"); > goto out; > @@ -1523,8 +1526,6 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map) > r->offset = rentry->offset; > r++; > } > - > - *map = r; > } > out: > acpi_dev_free_resource_list(&list); > -- > 2.36.1.dirty >
On Wed, Oct 19, 2022 at 10:13 AM Lorenzo Pieralisi <lpieralisi@kernel.org> wrote: > > On Tue, Oct 18, 2022 at 02:14:04PM +0100, Robin Murphy wrote: > > Assigning the device's dma_range_map from the iterator variable after > > the loop means it always points to the empty terminator at the end of > > the map, which is not what we want. Similarly, freeing the iterator on > > error when it points to somwhere in the middle of the allocated array > > won't work either. Fix this. > > > > Fixes: bf2ee8d0c385 ("ACPI: scan: Support multiple DMA windows with different offsets") > > Signed-off-by: Robin Murphy <robin.murphy@arm.com> > > --- > > drivers/acpi/scan.c | 7 ++++--- > > 1 file changed, 4 insertions(+), 3 deletions(-) > > A quick comment below, otherwise: > > Reviewed-by: Lorenzo Pieralisi <lpieralisi@kernel.org> Applied as is and the code may be cleaned up later. Thanks! > > diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c > > index 558664d169fc..024cc373a197 100644 > > --- a/drivers/acpi/scan.c > > +++ b/drivers/acpi/scan.c > > @@ -1509,9 +1509,12 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map) > > goto out; > > } > > > > + *map = r; > > I wonder whether having a local variable to stash the base pointer > would make code easier to read (so that we avoid using *map for that > purpose and also to return the array to the caller). > > Thanks for fixing it so promptly. > > Lorenzo > > > + > > list_for_each_entry(rentry, &list, node) { > > if (rentry->res->start >= rentry->res->end) { > > - kfree(r); > > + kfree(*map); > > + *map = NULL; > > ret = -EINVAL; > > dev_dbg(dma_dev, "Invalid DMA regions configuration\n"); > > goto out; > > @@ -1523,8 +1526,6 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map) > > r->offset = rentry->offset; > > r++; > > } > > - > > - *map = r; > > } > > out: > > acpi_dev_free_resource_list(&list); > > -- > > 2.36.1.dirty > >
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 558664d169fc..024cc373a197 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -1509,9 +1509,12 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map) goto out; } + *map = r; + list_for_each_entry(rentry, &list, node) { if (rentry->res->start >= rentry->res->end) { - kfree(r); + kfree(*map); + *map = NULL; ret = -EINVAL; dev_dbg(dma_dev, "Invalid DMA regions configuration\n"); goto out; @@ -1523,8 +1526,6 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map) r->offset = rentry->offset; r++; } - - *map = r; } out: acpi_dev_free_resource_list(&list);