Re: [PATCH v2 3/6] ACPI: RISC-V: Fix riscv_acpi_add_prt_dep() loop handling
From: Sunil V L
Date: Mon Jun 08 2026 - 13:42:14 EST
On Wed, Jun 3, 2026 at 2:18 PM Lorenzo Pieralisi <lpieralisi@xxxxxxxxxx> wrote:
>
> 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.
>
> Signed-off-by: Lorenzo Pieralisi <lpieralisi@xxxxxxxxxx>
> Cc: "Rafael J. Wysocki" <rafael@xxxxxxxxxx>
> Cc: Sunil V L <sunilvl@xxxxxxxxxxxxxxxx>
> ---
> 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);
> }
>
Reviewed-by: Sunil V L <sunilvl@xxxxxxxxxxxxxxxx>