From: "Rob Herring (Arm)" <robh@kernel.org>
To: Saravana Kannan <saravanak@google.com>
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/3] of: Add missing locking to of_(bus_)?n_(size|addr)_cells()
Date: Thu, 30 May 2024 20:03:28 -0500 [thread overview]
Message-ID: <20240530-dt-interrupt-map-fix-v1-2-2331d8732f08@kernel.org> (raw)
In-Reply-To: <20240530-dt-interrupt-map-fix-v1-0-2331d8732f08@kernel.org>
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) <robh@kernel.org>
---
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;
- for (; np; np = 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;
/* No #address-cells property for the root node */
@@ -101,10 +101,9 @@ int of_bus_n_addr_cells(struct device_node *np)
int of_n_addr_cells(struct device_node *np)
{
- if (np->parent)
- np = np->parent;
+ struct device_node *parent __free(device_node) = of_get_parent(np);
- return of_bus_n_addr_cells(np);
+ return of_bus_n_addr_cells(parent);
}
EXPORT_SYMBOL(of_n_addr_cells);
@@ -112,8 +111,8 @@ int of_bus_n_size_cells(struct device_node *np)
{
u32 cells;
- for (; np; np = 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;
/* No #size-cells property for the root node */
@@ -122,10 +121,9 @@ int of_bus_n_size_cells(struct device_node *np)
int of_n_size_cells(struct device_node *np)
{
- if (np->parent)
- np = np->parent;
+ struct device_node *parent __free(device_node) = of_get_parent(np);
- return of_bus_n_size_cells(np);
+ return of_bus_n_size_cells(parent);
}
EXPORT_SYMBOL(of_n_size_cells);
--
2.43.0
next prev parent reply other threads:[~2024-05-31 1:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-31 1:03 [PATCH 0/3] of: Reimplement of_(bus_)?n_(size|addr)_cells() Rob Herring (Arm)
2024-05-31 1:03 ` [PATCH 1/3] of: Add an iterator to walk up parent nodes Rob Herring (Arm)
2024-05-31 1:03 ` Rob Herring (Arm) [this message]
2024-06-04 16:08 ` [PATCH 2/3] of: Add missing locking to of_(bus_)?n_(size|addr)_cells() Rob Herring
2024-05-31 1:03 ` [PATCH 3/3] of/irq: Use of_bus_n_addr_cells() to retrieve "#address-cells" Rob Herring (Arm)
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=20240530-dt-interrupt-map-fix-v1-2-2331d8732f08@kernel.org \
--to=robh@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=saravanak@google.com \
/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
all inboxes | Powered by JetHome®