From nobody Fri Dec 19 00:01:08 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 AFD847483; Fri, 31 May 2024 01:03:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717117416; cv=none; b=JboSYGK8XXab+gm5SdEmlzg1TXdeDJEr7zTF1FWH5ZKnCDlqLU1h1Hp9O9Ne7pBfbPt3wu3j/OSC7NADTsyTyIi1MKltnuGMaTFQiwdCqxs8fI57bHfzUPbRfIxpeNaPVo/GPclYhERTFimShYsn9Ox9pXQWNTAa0Vw7Aut8/0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717117416; c=relaxed/simple; bh=MhZFv6QxVQ1ubVbKQDF07E67+FwUvci9ncljfLMfprc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XgZMWiciCJK9dGLK0xt491eOpgeQwhyYRD1BRoYBl7bEcm95rD91XJ+MCMtv/a+3L5ghEIieaRTI+c3lbUibYSopy3t9ik1ysW6l6h6S6PIYyc9Y3GIeFR311+hpAZ8HglrCRsPBJ0RLOBIeBLiT514ejI5L1mIN0YHAtjeRwHk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HNPUYaOP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HNPUYaOP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19C31C2BBFC; Fri, 31 May 2024 01:03:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717117416; bh=MhZFv6QxVQ1ubVbKQDF07E67+FwUvci9ncljfLMfprc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HNPUYaOPXEaNmxKOw0i9msGwW9I1KiIe95rvYMFVLnIcKLz0HDfZmgui6n3GuoNNO irs6OXRqyVteiTco2B0B1uKn4AuD8JXh22ScXG76/dk+t3njEUKloytgansoyzxitb CaJ5otOo4ixz7op7Pqvdi5Oq16auxhc1w10iJXEOaBmabVaVwNLRQlIlHtrNaLfBmD nPPT2xVILLc6PLEuWEBHNjTb7YwvjKDi38no6GyZXMadtr3wxQWFO3vSC/f/ivDds4 QGqn0ktcCsRNfApu8CHaEqLNjmS+YYPyNvmFCLIEq8qJaWFySDiWJE1jRSiXzrchMk 3eF07m6eVIT9Q== From: "Rob Herring (Arm)" Date: Thu, 30 May 2024 20:03:27 -0500 Subject: [PATCH 1/3] of: Add an iterator to walk up parent nodes 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: quoted-printable Message-Id: <20240530-dt-interrupt-map-fix-v1-1-2331d8732f08@kernel.org> References: <20240530-dt-interrupt-map-fix-v1-0-2331d8732f08@kernel.org> In-Reply-To: <20240530-dt-interrupt-map-fix-v1-0-2331d8732f08@kernel.org> To: Saravana Kannan Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14-dev Similar to other node iterators, add one for walking up parent nodes. The iterator starts on the current node, not the immediate parent as that seems to be the common case and starting with the parent node can be implemented like this: for_each_parent_of_node_scoped(parent, of_get_parent(node)) Signed-off-by: Rob Herring (Arm) --- include/linux/of.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/of.h b/include/linux/of.h index a0bedd038a05..c322802dfc2b 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1482,6 +1482,11 @@ static inline int of_property_read_s32(const struct = device_node *np, child !=3D NULL; \ child =3D of_get_next_available_child(parent, child)) =20 +#define for_each_parent_of_node_scoped(parent, node) \ + for (struct device_node *parent __free(device_node) =3D \ + of_node_get(node) ; \ + parent; parent =3D of_get_next_parent(parent)) + #define for_each_of_cpu_node(cpu) \ for (cpu =3D of_get_next_cpu_node(NULL); cpu !=3D NULL; \ cpu =3D of_get_next_cpu_node(cpu)) --=20 2.43.0 From nobody Fri Dec 19 00:01:08 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 274F1EEBA; Fri, 31 May 2024 01:03:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717117418; cv=none; b=JJTX/IEmBeVqEPWkIx5+uBranSUeyvhFBnJGgnorC7dAGWTcx5Hy2lZhOWeKvo4QU3r1JAhEafX9lJCST6cKTEAxQhdoIVURLEmqWSMMMhTP30uh0rJ7EhrHRTtMEJIJ966RJmipwnTBhZW+r7rXh7+vQmXc7YttX8e0ovnSH5I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717117418; c=relaxed/simple; bh=TBi8BiVNfed7a3wLohEOqAfZBAjmUXKDQITmxlZkrSQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XXCBw6XTnXkHlqaPU9J7ac3PczKUrbr3vwRzcycw/fQyEa13tGzbs203k6T35NceaoNQ7W7XktFVqwxtvGmURoBZ7zBLGQFeQ25DlToBcmERhrbswRV87lo9TleSmzh3TQwUzW9ttZdioShuwLO4MXUmTQPR3Mvccump6gi7yxc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fbZ2ocmr; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fbZ2ocmr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7B9C0C32789; Fri, 31 May 2024 01:03:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717117417; bh=TBi8BiVNfed7a3wLohEOqAfZBAjmUXKDQITmxlZkrSQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=fbZ2ocmr2pO4+9KIvoZiSh2nbnmh1KrrQTtyfraADcqRxrTVQY+321sjiJHkJsrZL lEJYXiARvf3jrS9etlJJcs1GFhMLaMmDTOUVEKSUxGalp68oymgdtuytqZ1Emrl8bv t+gOvrZhLugtX8itN0wapYNqV5RWmQXzLBwTo30UA2j55Yr0PkARUio0wiJjsrD+BD YhZujCwU+3FIJXVzIoxRPlSpNTALoGHt9sbroGr1jtUAN2NKWRnD5AULcicNKx7C81 DlHe1hEWP9aX5QHWq39mPupaj+BUJ4uDAdAUNm0hXj+DMq5Cp3PnBbSiV8REI5wcx1 rCrT4HiT5wuIg== From: "Rob Herring (Arm)" Date: Thu, 30 May 2024 20:03:28 -0500 Subject: [PATCH 2/3] of: Add missing locking to of_(bus_)?n_(size|addr)_cells() 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: quoted-printable Message-Id: <20240530-dt-interrupt-map-fix-v1-2-2331d8732f08@kernel.org> References: <20240530-dt-interrupt-map-fix-v1-0-2331d8732f08@kernel.org> In-Reply-To: <20240530-dt-interrupt-map-fix-v1-0-2331d8732f08@kernel.org> To: Saravana Kannan Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14-dev When accessing parent/child/sibling pointers the DT spinlock needs to be held. The of_(bus_)?n_(size|addr)_cells() functions are missing that when walking up the parent nodes. In reality, it rarely matters as most nodes are static. Signed-off-by: Rob Herring (Arm) --- drivers/of/base.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 20603d3c9931..61fff13bbee5 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -91,8 +91,8 @@ int of_bus_n_addr_cells(struct device_node *np) { u32 cells; =20 - for (; np; np =3D np->parent) - if (!of_property_read_u32(np, "#address-cells", &cells)) + for_each_parent_of_node_scoped(parent, np) + if (!of_property_read_u32(parent, "#address-cells", &cells)) return cells; =20 /* No #address-cells property for the root node */ @@ -101,10 +101,9 @@ int of_bus_n_addr_cells(struct device_node *np) =20 int of_n_addr_cells(struct device_node *np) { - if (np->parent) - np =3D np->parent; + struct device_node *parent __free(device_node) =3D of_get_parent(np); =20 - return of_bus_n_addr_cells(np); + return of_bus_n_addr_cells(parent); } EXPORT_SYMBOL(of_n_addr_cells); =20 @@ -112,8 +111,8 @@ int of_bus_n_size_cells(struct device_node *np) { u32 cells; =20 - for (; np; np =3D np->parent) - if (!of_property_read_u32(np, "#size-cells", &cells)) + for_each_parent_of_node_scoped(parent, np) + if (!of_property_read_u32(parent, "#size-cells", &cells)) return cells; =20 /* No #size-cells property for the root node */ @@ -122,10 +121,9 @@ int of_bus_n_size_cells(struct device_node *np) =20 int of_n_size_cells(struct device_node *np) { - if (np->parent) - np =3D np->parent; + struct device_node *parent __free(device_node) =3D of_get_parent(np); =20 - return of_bus_n_size_cells(np); + return of_bus_n_size_cells(parent); } EXPORT_SYMBOL(of_n_size_cells); =20 --=20 2.43.0 From nobody Fri Dec 19 00:01:08 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8BF9217C6D; Fri, 31 May 2024 01:03:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717117419; cv=none; b=c5Uqrt5O8wQ4jwTt/vEejbiTtU0Zjua/EEs++elnjkZOZBoosa2C2e1DFItdGFqt4r9UoyUximDTKpdxlJ6vR6HRayxNg17OIu6GpOf7s96REJPV5+TjytuYD1/vP82Vgdw3q/5N8cQTIbvuVFsiVE01EwkGv5bzAkJe/8FcVlU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717117419; c=relaxed/simple; bh=ik9ydv5c3BxcmGg8fcLt+9GYSjVnAYx1psftIjNfik4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=C9VKGLiFL6AibcI4AL7ulmmUzmx7O71BIF2E9IxhAUY2QM+U7OHcVWxp+lVyZ+YBsh7DZMy9Ei8KW9vkVanVwN4yUHpyB5cvtemxIKBaedSGtWL4kHrR6LmzEihGe3TCuuoSH1etpEAQu5xwytp6aznp3I6URHjMdDUFxWnhBoY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NI26qUWy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NI26qUWy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9C1BC32789; Fri, 31 May 2024 01:03:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717117419; bh=ik9ydv5c3BxcmGg8fcLt+9GYSjVnAYx1psftIjNfik4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=NI26qUWyeeAnslPtlkblIf6qyOrCZz0WLSxyv0JKaoHOd6GJfKyPdvVaEqIRyUoOx 7+9oeQ2u5MRwfOjLqLqAZF+LmkHLdTTpw7e7YAterUUvA9Ek4+47WqUxFsbxpecU55 gjWtZ7Mq8XOA/psurUbJZMtx2MJfiE2UVCB/eFSMRpmG94vSEaGCEsE6G2raFD1JqS OpQ4lZ9ugqeixo9tAaIn2I2eURVI8MULDvtu/4KuiAnBYWPg9ybZxdaXxX7T8jJKkh +VCgXLChoSm93ktv3R7ZsX+WuNGojejRUfzJIQZ5u/ZuIn8RiMYvAvfGPtCu0bTrqY XiDONCu5R7w3g== From: "Rob Herring (Arm)" Date: Thu, 30 May 2024 20:03:29 -0500 Subject: [PATCH 3/3] of/irq: Use of_bus_n_addr_cells() to retrieve "#address-cells" 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: quoted-printable Message-Id: <20240530-dt-interrupt-map-fix-v1-3-2331d8732f08@kernel.org> References: <20240530-dt-interrupt-map-fix-v1-0-2331d8732f08@kernel.org> In-Reply-To: <20240530-dt-interrupt-map-fix-v1-0-2331d8732f08@kernel.org> To: Saravana Kannan Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14-dev of_irq_parse_raw() is open coding what of_bus_n_addr_cells() does, so replace it with of_bus_n_addr_cells(). Note that the original code would use 2 cells if #address-cells was not found. That doesn't match the default of 1 for anything but Sparc which doesn't use this code. Signed-off-by: Rob Herring (Arm) --- drivers/of/irq.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/drivers/of/irq.c b/drivers/of/irq.c index 462375b293e4..d81ee880a553 100644 --- a/drivers/of/irq.c +++ b/drivers/of/irq.c @@ -165,10 +165,10 @@ const __be32 *of_irq_parse_imap_parent(const __be32 *= imap, int len, struct of_ph */ int of_irq_parse_raw(const __be32 *addr, struct of_phandle_args *out_irq) { - struct device_node *ipar, *tnode, *old =3D NULL; + struct device_node *ipar, *tnode; __be32 initial_match_array[MAX_PHANDLE_ARGS]; const __be32 *match_array =3D initial_match_array; - const __be32 *tmp, dummy_imask[] =3D { [0 ... MAX_PHANDLE_ARGS] =3D cpu_t= o_be32(~0) }; + const __be32 dummy_imask[] =3D { [0 ... MAX_PHANDLE_ARGS] =3D cpu_to_be32= (~0) }; u32 intsize =3D 1, addrsize; int i, rc =3D -EINVAL; =20 @@ -202,16 +202,7 @@ int of_irq_parse_raw(const __be32 *addr, struct of_pha= ndle_args *out_irq) /* Look for this #address-cells. We have to implement the old linux * trick of looking for the parent here as some device-trees rely on it */ - old =3D of_node_get(ipar); - do { - tmp =3D of_get_property(old, "#address-cells", NULL); - tnode =3D of_get_parent(old); - of_node_put(old); - old =3D tnode; - } while (old && tmp =3D=3D NULL); - of_node_put(old); - old =3D NULL; - addrsize =3D (tmp =3D=3D NULL) ? 2 : be32_to_cpu(*tmp); + addrsize =3D of_bus_n_addr_cells(ipar); =20 pr_debug(" -> addrsize=3D%d\n", addrsize); =20 --=20 2.43.0