[PATCH 01/10] of/fdt: Introduce dt_root_addr_size_cells() and dt_root_addr_size_bytes()

Yuntao Wang posted 10 patches 2 months, 4 weeks ago
There is a newer version of this series
[PATCH 01/10] of/fdt: Introduce dt_root_addr_size_cells() and dt_root_addr_size_bytes()
Posted by Yuntao Wang 2 months, 4 weeks ago
Currently, many places use the result of the expression
`(dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32)` for various
checks.

To improve code maintainability and reduce the chance of errors, extract
this expression into two helper functions.

Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
---
 include/linux/of_fdt.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h
index b8d6c0c20876..9ce2433865ae 100644
--- a/include/linux/of_fdt.h
+++ b/include/linux/of_fdt.h
@@ -30,6 +30,17 @@ extern void *of_fdt_unflatten_tree(const unsigned long *blob,
 /* TBD: Temporary export of fdt globals - remove when code fully merged */
 extern int __initdata dt_root_addr_cells;
 extern int __initdata dt_root_size_cells;
+
+static inline int dt_root_addr_size_cells(void)
+{
+	return dt_root_addr_cells + dt_root_size_cells;
+}
+
+static inline int dt_root_addr_size_bytes(void)
+{
+	return dt_root_addr_size_cells() * sizeof(__be32);
+}
+
 extern void *initial_boot_params;
 extern phys_addr_t initial_boot_params_pa;
 
-- 
2.51.0
Re: [PATCH 01/10] of/fdt: Introduce dt_root_addr_size_cells() and dt_root_addr_size_bytes()
Posted by Geert Uytterhoeven 2 months, 4 weeks ago
On Wed, 12 Nov 2025 at 15:37, Yuntao Wang <yuntao.wang@linux.dev> wrote:
> Currently, many places use the result of the expression
> `(dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32)` for various
> checks.
>
> To improve code maintainability and reduce the chance of errors, extract
> this expression into two helper functions.
>
> Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds