devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] of: base: use of_property_read_u32()
@ 2017-07-23 16:55 Sergei Shtylyov
       [not found] ` <20170723165744.310866466-M4DtvfQ/ZS1MRgGoP+s0PdBPR1lH4CV8@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Sergei Shtylyov @ 2017-07-23 16:55 UTC (permalink / raw)
  To: Rob Herring, Frank Rowand, devicetree-u79uwXL29TY76Z2rM5mHXA
  Cc: Sergei Shtylyov

[-- Attachment #1: of-base-use-of_property_read_u32.patch --]
[-- Type: text/plain, Size: 1710 bytes --]

of_n_{addr|size}_cells(() predate of_property_read_u32(), so they have to
basically open-code it. Using the modern DT API saves several LoCs and also
adds some prop sanity checks as a bonus...

Signed-off-by: Sergei Shtylyov <sergei.shtylyov-M4DtvfQ/ZS1MRgGoP+s0PdBPR1lH4CV8@public.gmane.org>

---
 drivers/of/base.c |   14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

Index: linux/drivers/of/base.c
===================================================================
--- linux.orig/drivers/of/base.c
+++ linux/drivers/of/base.c
@@ -60,14 +60,13 @@ DEFINE_RAW_SPINLOCK(devtree_lock);
 
 int of_n_addr_cells(struct device_node *np)
 {
-	const __be32 *ip;
+	u32 cells;
 
 	do {
 		if (np->parent)
 			np = np->parent;
-		ip = of_get_property(np, "#address-cells", NULL);
-		if (ip)
-			return be32_to_cpup(ip);
+		if (!of_property_read_u32(np, "#address-cells", &cells))
+			return cells;
 	} while (np->parent);
 	/* No #address-cells property for the root node */
 	return OF_ROOT_NODE_ADDR_CELLS_DEFAULT;
@@ -76,14 +75,13 @@ EXPORT_SYMBOL(of_n_addr_cells);
 
 int of_n_size_cells(struct device_node *np)
 {
-	const __be32 *ip;
+	u32 cells;
 
 	do {
 		if (np->parent)
 			np = np->parent;
-		ip = of_get_property(np, "#size-cells", NULL);
-		if (ip)
-			return be32_to_cpup(ip);
+		if (!of_property_read_u32(np, "#size-cells", &cells))
+			return cells;
 	} while (np->parent);
 	/* No #size-cells property for the root node */
 	return OF_ROOT_NODE_SIZE_CELLS_DEFAULT;

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/2] of: base: use of_property_read_u32()
       [not found] ` <20170723165744.310866466-M4DtvfQ/ZS1MRgGoP+s0PdBPR1lH4CV8@public.gmane.org>
@ 2017-07-23 19:10   ` Sergei Shtylyov
  0 siblings, 0 replies; 2+ messages in thread
From: Sergei Shtylyov @ 2017-07-23 19:10 UTC (permalink / raw)
  To: Rob Herring, Frank Rowand, devicetree-u79uwXL29TY76Z2rM5mHXA

On 07/23/2017 07:55 PM, Sergei Shtylyov wrote:

> of_n_{addr|size}_cells(() predate of_property_read_u32(), so they have to

    Oops,. double open paren. Rob, could you please fxi while applying?

> basically open-code it. Using the modern DT API saves several LoCs and also
> adds some prop sanity checks as a bonus...
>
> Signed-off-by: Sergei Shtylyov <sergei.shtylyov-M4DtvfQ/ZS1MRgGoP+s0PdBPR1lH4CV8@public.gmane.org>
[...]

MNR, Sergei

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-07-23 19:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-23 16:55 [PATCH 1/2] of: base: use of_property_read_u32() Sergei Shtylyov
     [not found] ` <20170723165744.310866466-M4DtvfQ/ZS1MRgGoP+s0PdBPR1lH4CV8@public.gmane.org>
2017-07-23 19:10   ` Sergei Shtylyov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).