From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBB8334C141; Wed, 1 Jul 2026 14:39:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782916763; cv=none; b=mrDqB10AJch4GHx0ypxZJ872n1ZhagJFh+/9FT5csWckU2at8cpxan6C+smxEHP9ku+iacZXrEbprOdhN7u33YHIoIFiuy+ARrARC2EsgKZGe6rexzR1ZH61Qti1EGLgMdDd64FJPdaWcE89MHEY8gp5CxZeJ1H8xCbUvEhtWoc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782916763; c=relaxed/simple; bh=haHz293myOIVZPv24e5lIUUw2/7UyWrs24CniPmdRLI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=r678S1nW6iJAoGmrinlsZqzFFk1UErzerIBN+ELk9rFBv/RmZin7nqg/gB/0a2ueJ3wWj39xnaxOK7APUUweKFQW4B8swLFDEWVgV3JH8TGMmXM12j2fFHanrekzyPYv75Auv9tBJ6x6cFGqAmxZLxaAwGbOo3I+wC/hH7h9a6o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NXKCMLey; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NXKCMLey" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 350861F000E9; Wed, 1 Jul 2026 14:39:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1782916762; bh=PU2apTxk26tSxVAvU49sTh6nblByGp9XmHnEaO91aJ0=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=NXKCMLeysOnqQtNxOPaTYyadwU/3QaiIim0jZhjmG58/4muR+KPw1lTvXMtx8qjz+ B01ecEW2hVp5z8TmlxQOG436EEbAMA4ORePYrV7NZdWNIojaJ0xOoeUX8rOgjNVoBK YBj/eRVDa61BqcngS562bdVrnuFvtaQf9SfYy7Iz54CTVKR7sOMJub167/h0ID2MbB 7GjzDDERSqY1mujvE8TdsY1uV0/S8BN0Xh1XGrBdLen8cu1EQcOsWG4W7BdlCRneCX GdB6REDEBD0wr+teI0M9zC7C9mAdc7184f2tQOIaCA72XHg3wC4Ct3saYZS5NLlA3c 8Khce/G6QNWGg== From: Lorenzo Pieralisi Date: Wed, 01 Jul 2026 16:38:52 +0200 Subject: [PATCH v3 4/7] ACPI: RISC-V: Fix riscv_acpi_add_prt_dep() loop handling Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260701-gic-v5-acpi-iwb-probe-deferral-v3-4-c5562cf0fe29@kernel.org> References: <20260701-gic-v5-acpi-iwb-probe-deferral-v3-0-c5562cf0fe29@kernel.org> In-Reply-To: <20260701-gic-v5-acpi-iwb-probe-deferral-v3-0-c5562cf0fe29@kernel.org> To: "Rafael J. Wysocki" , Len Brown , Sunil V L , Marc Zyngier , Thomas Gleixner , Huacai Chen , Anup Patel , Hanjun Guo , Sudeep Holla , Catalin Marinas , Will Deacon 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 , "Rafael J. Wysocki" , Sunil V L X-Mailer: b4 0.15.2 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 Tested-by: Sunil V L Reviewed-by: Sunil V L Cc: "Rafael J. Wysocki" Cc: Sunil V L --- 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