From nobody Mon Jun 8 23:56:40 2026 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 294C93D34A4 for ; Mon, 25 May 2026 07:44:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779695063; cv=none; b=tfDopupm49X67zkFmXQt+Ky1Rn3+cEA2UNOW7HlmKzRGovOy8X6Fj9jeFHDr9ioi20eB7Q/IuYl15cIAnTbgTMVnOaMmtT4TDCL3qUSTvkLM4hO20k+6aw7g13USh7xCNSdALDinZPq0bFWYj35Rj0+kD3989hr0y6UU/3QhckE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779695063; c=relaxed/simple; bh=gZh0WXOkZ7TUV4i4k6DPQccuy1wCCMGgW3WktDwdS1o=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=kCFSW5IDqG9hEE7Ugi6uv+CFUts7Toeg5hsrzg9vdlinA5qUfDDtiM7EpErZoit1zzN+PENcxnMVKDJY595Xqd7LOob+ZU07NGg9n5nyzcGTpz5rf69CCbAm+7Pnnn26UZkUw6b3FnpZiGuzrW9qS1zC6IsuHkWlnWp7ybUJv2Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=pMczXFtr; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pMczXFtr" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2bd9c3b550aso65302105ad.2 for ; Mon, 25 May 2026 00:44:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779695061; x=1780299861; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Lg9TspPoq01uolM1ptMRklLuTF5lwXaabRXnRf1AltY=; b=pMczXFtrM4ROffJMXWLXsyAo6pNdTyleeEVdsH4sZDQH//tSc7H0MwWe4IQGYjpq0y Wxtw4LzhNVPnWIfKmE43VsdXqKOEw8ZkSEkX3IvKNuY2cYpPyWV54yDmRo4uG8iz7BH5 exMxxog73DI5VGBofO0RLye6WaX/H73wUG6tDwHRYZKzPHvjeBoGLnEGKdsXaQvjn1eQ CubDs5EQ3SUnNivAG5WREgbMd60+EkRvkcim42cssR1a05bF59OC/12xYRYPItZxa6om D08SHLzUBZ3ZhHQewnUYgVoG+pVT0fUDz5eXhmyTLq+FdtSPTgSI+IpwrxN7cmSq2jUE Wy9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779695061; x=1780299861; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Lg9TspPoq01uolM1ptMRklLuTF5lwXaabRXnRf1AltY=; b=jeapirQY5SIn22tGoUpbNnFkyaetIiZ9HvW45NI4nwGPa3h+ewmJ/YHnlpEQe3bbTZ cB4jCsPCtMW9iMIKKhzYuKEJicRI0RLpO8p+J2BghrWy2uEihw3TKw/WMO1NvbjAPcAJ lQwkGL5gcV8ds9499VqaP1ZKqvPZyv0/NhX8s62cr9vwM0rhV0xQ0p5+UONgwyNP+i33 gweKiQNEB0Pz0LhZ0zxgVdh9PJlGIueqlYRMOG+cF6zBC5xEwPlVay5ppRPi9Di861bf WtxncfL1zjcppoNBjNNiDNaKJnVqVq6kDLCfS0L7UPtgr6I8yyovaoX3dJ4Cnpj+pvIW jK5Q== X-Forwarded-Encrypted: i=1; AFNElJ+j4GkmZ+YzGnIhBnNtDUkRQ1EzW83frgneoEvz2dkOHgZjJaJd4PCeWJ6cSeM6qU4FbIQuAySXLBAHbaY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz1B6sw0FOAgMofrI//IlIrM6JtlxL6eUCTWKDyoGZ/TW1NZYl+ S4DQibTsPZAJl5KhUvL+s9Wp6vK7NuPI6bc3usalMaP405xQjh0PwVchutw1iA== X-Gm-Gg: Acq92OG5oco82slKrQkzNUvresg53AvlR2ctQY8SSxvLYVzr8605RfVVVx1q1DCyxd0 JNhj5/d8amO+cZksoxZoRqEjEY9L/2p2qyRI4SFCgkjPGTBL85l3prlJKtV9Cl2uWWLJzFR6PRA lnFGzEssIegQxkHpAvUazzU/8wCx0ySkXGrWH+Y0T5+2NXOoygtfHIMKf8MGAyqjN8p2TSPMsds bvg7mRqEo+LWC0gU/HrvkSWpAm5w0trvl1z57IRgOOtxasejggulpNh8DbznCyE9swRb243XQrV ZliFKiUF5Oylqh/Xy3W1wvAoahIYFQKZ5mE25MeyB+RP9kqcTNJcDfcJ9JIhbTmaiaKvUAc/oxb V76km5bH92uu5bHMEI6Q+17baEcRVYNycz0Nbh//FJQ8FwMLOjhAjJggOXSp7cL1pdd9f+mK8xG uen6mctOYHoqV0jadykSH8RdK2MTsJVoEDEslgVxKFopkah4bu X-Received: by 2002:a17:903:234e:b0:2b4:5931:bc4c with SMTP id d9443c01a7336-2beb069806dmr133606145ad.15.1779695061379; Mon, 25 May 2026 00:44:21 -0700 (PDT) Received: from csl-conti-dell7858.ntu.edu.sg ([155.69.195.57]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2beb58dde5fsm88734325ad.70.2026.05.25.00.44.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 May 2026 00:44:20 -0700 (PDT) From: Maoyi Xie To: Sunil V L Cc: "Rafael J . Wysocki" , Len Brown , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-acpi@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] acpi/riscv: use a dedicated insertion point in riscv_acpi_register_ext_intc() Date: Mon, 25 May 2026 15:44:15 +0800 Message-Id: <20260525074415.1533884-1-maoyixie.tju@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" riscv_acpi_register_ext_intc() inserts into ext_intc_list, which is sorted with the largest gsi_base first. It walks the list until it finds the first entry with a smaller gsi_base, then inserts the new entry before that entry. After the loop it also caps the predecessor's nr_irqs if that predecessor was registered as PENDING. The current code uses the loop cursor for both jobs: list_for_each_entry(node, &ext_intc_list, list) { if (node->gsi_base < ext_intc_element->gsi_base) break; } prev =3D list_prev_entry(node, list); if (!list_entry_is_head(prev, &ext_intc_list, list)) { ... } list_add_tail(&ext_intc_element->list, &node->list); If the loop falls through (no entry has a smaller gsi_base), node ends up past the end of the list. `&node->list` resolves to `&ext_intc_list` via container_of() offset cancellation. So list_prev_entry() lands on the last real entry, and list_add_tail() inserts at the tail. The code works today. It is fragile though. Any future change that reads another field of node will hit memory before the ext_intc_list global. Track the insertion point with a dedicated list_head pointer. Initialise pos to `&ext_intc_list`. Set it to `&node->list` on early break. Use pos->prev for the PENDING adjustment, and pos for list_add_tail(). The cursor is no longer touched after the loop. Behaviour is unchanged. Same shape as the Koschel cleanups from 2022 (e.g. 99d8ae4ec8a tracing, 2966a9918df clockevents, dc1acd5c946 dlm). Signed-off-by: Maoyi Xie Reviewed-by: Sunil V L --- drivers/acpi/riscv/irq.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/acpi/riscv/irq.c b/drivers/acpi/riscv/irq.c index 9b88d0993e88..49582cf4f4e2 100644 --- a/drivers/acpi/riscv/irq.c +++ b/drivers/acpi/riscv/irq.c @@ -134,7 +134,8 @@ struct fwnode_handle *riscv_acpi_get_gsi_domain_id(u32 = gsi) static int __init riscv_acpi_register_ext_intc(u32 gsi_base, u32 nr_irqs, = u32 nr_idcs, u32 id, u32 type) { - struct riscv_ext_intc_list *ext_intc_element, *node, *prev; + struct riscv_ext_intc_list *ext_intc_element, *node; + struct list_head *pos =3D &ext_intc_list; =20 ext_intc_element =3D kzalloc_obj(*ext_intc_element); if (!ext_intc_element) @@ -153,18 +154,22 @@ static int __init riscv_acpi_register_ext_intc(u32 gs= i_base, u32 nr_irqs, u32 nr ext_intc_element->nr_idcs =3D nr_idcs; ext_intc_element->id =3D id; list_for_each_entry(node, &ext_intc_list, list) { - if (node->gsi_base < ext_intc_element->gsi_base) + if (node->gsi_base < ext_intc_element->gsi_base) { + pos =3D &node->list; break; + } } =20 /* Adjust the previous node's GSI range if that has pending registration = */ - prev =3D list_prev_entry(node, list); - if (!list_entry_is_head(prev, &ext_intc_list, list)) { + if (pos->prev !=3D &ext_intc_list) { + struct riscv_ext_intc_list *prev =3D + list_entry(pos->prev, struct riscv_ext_intc_list, list); + if (prev->flag & RISCV_ACPI_INTC_FLAG_PENDING) prev->nr_irqs =3D ext_intc_element->gsi_base - prev->gsi_base; } =20 - list_add_tail(&ext_intc_element->list, &node->list); + list_add_tail(&ext_intc_element->list, pos); return 0; } =20 --=20 2.34.1