Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp5956206rwi; Tue, 18 Oct 2022 06:27:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7uYTcwtb9yyMpY10X9aKHA1HuuvYN0AKSoisWp+mpJSkLJB+cLDck4hsS3TLOIKfWv1NOD X-Received: by 2002:a17:902:c942:b0:180:3f94:2975 with SMTP id i2-20020a170902c94200b001803f942975mr3228964pla.50.1666099638872; Tue, 18 Oct 2022 06:27:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666099638; cv=none; d=google.com; s=arc-20160816; b=RqB4wdtlSXIQZuqTbX9pQF69AeaQ1ku3HNuhsn3icQDqKIcE+wJF+9cepzAHrzKCM7 ElJWty2rTaq+uW4gH38a+5gQa8XmG6Y5RZH0DsxzX5uKqd7hfkPN59nI6EGaDrhMDVuj UNTJogmyU5oHSUA1e/Y7xpLsWdYgU+pgcVJ99qw4Gbf/zZxNGFoQc13puEFkQgZBEh+4 2TYUXtYxoMX8GxAiuWhv8v31HoEbwrTK8Ng6aEn/0qbu+BQDi/qeKHAkg0MTD2hZJqiO YBO+cvYBKTp5bvSz6jhfZK2Z37d7aUm34HwBc87sh1jKXCB1wlPITOdCxpu/epZ61eqz 42Cw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f17-20020a170902ce9100b0017e90e88875si13288701plg.384.2022.10.18.06.27.03; Tue, 18 Oct 2022 06:27:18 -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 + 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 ); 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 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: 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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); -- 2.36.1.dirty