mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lorenzo Pieralisi <lpieralisi@kernel.org>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
	Len Brown <lenb@kernel.org>,
	 Sunil V L <sunilvl@ventanamicro.com>,
	Marc Zyngier <maz@kernel.org>,  Thomas Gleixner <tglx@kernel.org>,
	Huacai Chen <chenhuacai@kernel.org>,
	 Anup Patel <anup@brainfault.org>,
	Hanjun Guo <guohanjun@huawei.com>,
	 Sudeep Holla <sudeep.holla@kernel.org>,
	 Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>
Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	 linux-acpi@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,  loongarch@lists.linux.dev,
	Lorenzo Pieralisi <lpieralisi@kernel.org>,
	 "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	 Sunil V L <sunilvl@oss.qualcomm.com>
Subject: [PATCH v3 4/7] ACPI: RISC-V: Fix riscv_acpi_add_prt_dep() loop handling
Date: Wed, 01 Jul 2026 16:38:52 +0200	[thread overview]
Message-ID: <20260701-gic-v5-acpi-iwb-probe-deferral-v3-4-c5562cf0fe29@kernel.org> (raw)
In-Reply-To: <20260701-gic-v5-acpi-iwb-probe-deferral-v3-0-c5562cf0fe29@kernel.org>

The loop in riscv_acpi_add_prt_dep() includes error conditions that are
handled in a dubious - if not outright wrong - way, by continuining the
loop (which skips and misses the entry pointer update to point to the next
entry).

Rewrite the loop as a for loop (that handles the continuation correctly)
and wrap the condition and update statements using helper functions to make
it cleaner.

Fixes: 1b173cc4bfcd ("ACPI: RISC-V: Implement function to add implicit dependencies")
Signed-off-by: Lorenzo Pieralisi <lpieralisi@kernel.org>
Tested-by: Sunil V L <sunilvl@oss.qualcomm.com>
Reviewed-by: Sunil V L <sunilvl@oss.qualcomm.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Sunil V L <sunilvl@ventanamicro.com>
---
 drivers/acpi/riscv/irq.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/drivers/acpi/riscv/irq.c b/drivers/acpi/riscv/irq.c
index 75170151c614..0cdec5dd575e 100644
--- a/drivers/acpi/riscv/irq.c
+++ b/drivers/acpi/riscv/irq.c
@@ -319,6 +319,20 @@ static int riscv_acpi_irq_get_dep(acpi_handle handle, unsigned int index, acpi_h
 	return ctx.rc;
 }
 
+static bool acpi_prt_entry_valid(void *prt_entry)
+{
+	struct acpi_pci_routing_table *entry = prt_entry;
+
+	return entry && entry->length > 0;
+}
+
+static void *acpi_prt_next_entry(void *prt_entry)
+{
+	struct acpi_pci_routing_table *entry = prt_entry;
+
+	return prt_entry + entry->length;
+}
+
 static u32 riscv_acpi_add_prt_dep(acpi_handle handle)
 {
 	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
@@ -337,7 +351,7 @@ static u32 riscv_acpi_add_prt_dep(acpi_handle handle)
 	}
 
 	entry = buffer.pointer;
-	while (entry && (entry->length > 0)) {
+	for (; acpi_prt_entry_valid(entry); entry = acpi_prt_next_entry(entry)) {
 		if (entry->source[0]) {
 			status = acpi_get_handle(handle, entry->source, &link_handle);
 			if (ACPI_FAILURE(status))
@@ -365,9 +379,6 @@ static u32 riscv_acpi_add_prt_dep(acpi_handle handle)
 			dep_devices.handles[0] = gsi_handle;
 			count += acpi_scan_add_dep(handle, &dep_devices);
 		}
-
-		entry = (struct acpi_pci_routing_table *)
-			((unsigned long)entry + entry->length);
 	}
 
 	kfree(buffer.pointer);

-- 
2.34.1


  parent reply	other threads:[~2026-07-01 14:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01 14:38 [PATCH v3 0/7] irqchip/ACPI: Arm GICv5 IWB ACPI IRQ probe deferral Lorenzo Pieralisi
2026-07-01 14:38 ` [PATCH v3 1/7] ACPI: Add acpi_device_clear_dep() helper function Lorenzo Pieralisi
2026-07-02 21:27   ` Marc Zyngier
2026-07-06  8:46     ` Lorenzo Pieralisi
2026-07-01 14:38 ` [PATCH v3 2/7] ACPI: RISC-V: Fix riscv_acpi_irq_get_dep() loop termination Lorenzo Pieralisi
2026-07-01 14:38 ` [PATCH v3 3/7] ACPI: RISC-V: Check acpi_get_handle() status in riscv_acpi_add_prt_dep() Lorenzo Pieralisi
2026-07-01 14:38 ` Lorenzo Pieralisi [this message]
2026-07-01 14:38 ` [PATCH v3 5/7] ACPI: irq: Move RISC-V interrupt controllers autodep to ACPI IRQ code Lorenzo Pieralisi
2026-07-01 14:38 ` [PATCH v3 6/7] ACPI/IORT: Implement ACPI infrastructure to enable GICv5 IWB probe deferral Lorenzo Pieralisi
2026-07-01 14:38 ` [PATCH v3 7/7] irqchip/gic-v5: Enable GICv5 IWB ACPI probe ordering detection Lorenzo Pieralisi
2026-07-02 21:49   ` Marc Zyngier
2026-07-02 21:55   ` Thomas Gleixner
2026-07-02 21:56     ` Thomas Gleixner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260701-gic-v5-acpi-iwb-probe-deferral-v3-4-c5562cf0fe29@kernel.org \
    --to=lpieralisi@kernel.org \
    --cc=anup@brainfault.org \
    --cc=catalin.marinas@arm.com \
    --cc=chenhuacai@kernel.org \
    --cc=guohanjun@huawei.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=loongarch@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rafael@kernel.org \
    --cc=sudeep.holla@kernel.org \
    --cc=sunilvl@oss.qualcomm.com \
    --cc=sunilvl@ventanamicro.com \
    --cc=tglx@kernel.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox