Skip to contentSkip to conversation

of/fdt: Some bug fixes and cleanups

PATCH Applied Yuntao Wang 4 participants 26 messages Nov 12, 2025 – Nov 13, 2025

Subsystems (2)

v1 of 3 Applied Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover of/fdt: Some bug fixes and cleanups

This patch series fixes several bugs related to dt_root_addr_cells and dt_root_size_cells, and performs some cleanup.

Links to the previous related patches:

https://lore.kernel.org/lkml/CAL_JsqJxar7z+VcBXwPTw5-Et2oC9bQmH_CtMtKhoo_-=zN2XQ@mail.gmail.com/

Yuntao Wang (10):
of/fdt: Introduce dt_root_addr_size_cells() and
dt_root_addr_size_bytes()
of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding
it
of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding
it
of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding
it
of/fdt: Use dt_root_addr_size_bytes() instead of open-coding it of/fdt: Fix the len check in early_init_dt_check_for_elfcorehdr() of/fdt: Fix the len check in
early_init_dt_check_for_usable_mem_range()
of/fdt: Use dt_root_addr_size_bytes() instead of open-coding it of/fdt: Fix incorrect use of dt_root_addr_cells in
early_init_dt_check_kho()
of/address: Remove the incorrect and misleading comment

 drivers/of/address.c         |  4 ----
 drivers/of/fdt.c             | 14 +++++++-------
 drivers/of/of_reserved_mem.c |  6 +++---
 include/linux/of_fdt.h       | 11 +++++++++++
 4 files changed, 21 insertions(+), 14 deletions(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH 1/10 of/fdt: Introduce dt_root_addr_size_cells() and dt_root_addr_size_bytes()

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.

---
 include/linux/of_fdt.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
include/linux/of_fdt.h +11 -0
index b8d6c0c20876..9ce2433865ae 100644
@@ -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;
 
Signature · 1 line
2.51.0
Reviewed-by on v1 1/10
#2 lore raw

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

Quoted 8 lines · Yuntao Wang

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.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#3 lore raw

PATCH 2/10 of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding it

In reply to Yuntao Wang

Use dt_root_addr_size_bytes() instead of open-coding it in __reserved_mem_reserve_reg() to improve code maintainability.

---
 drivers/of/of_reserved_mem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/of_reserved_mem.c +1 -1
index 2e9ea751ed2d..67c0ccd373c2 100644
@@ -154,7 +154,7 @@ static int __init early_init_dt_reserve_memory(phys_addr_t base,
 static int __init __reserved_mem_reserve_reg(unsigned long node,
 					     const char *uname)
 {
-	int t_len = (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32);
+	int t_len = dt_root_addr_size_bytes();
 	phys_addr_t base, size;
 	int len;
 	const __be32 *prop;
Signature · 1 line
2.51.0
Reviewed-by on v1 2/10
#4 lore raw

Re: [PATCH 02/10] of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding it

Quoted 4 lines · Yuntao Wang

Use dt_root_addr_size_bytes() instead of open-coding it in __reserved_mem_reserve_reg() to improve code maintainability.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#5 lore raw

PATCH 3/10 of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding it

In reply to Yuntao Wang

Use dt_root_addr_size_bytes() instead of open-coding it in fdt_scan_reserved_mem_reg_nodes() to improve code maintainability.

---
 drivers/of/of_reserved_mem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/of_reserved_mem.c +1 -1
index 67c0ccd373c2..0e6b0e7968a9 100644
@@ -230,7 +230,7 @@ static void __init __rmem_check_for_overlap(void);
  */
 void __init fdt_scan_reserved_mem_reg_nodes(void)
 {
-	int t_len = (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32);
+	int t_len = dt_root_addr_size_bytes();
 	const void *fdt = initial_boot_params;
 	phys_addr_t base, size;
 	const __be32 *prop;
Signature · 1 line
2.51.0
Reviewed-by on v1 3/10
#6 lore raw

Re: [PATCH 03/10] of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding it

Quoted 4 lines · Yuntao Wang

Use dt_root_addr_size_bytes() instead of open-coding it in fdt_scan_reserved_mem_reg_nodes() to improve code maintainability.

But please combine with the previous patch with the same subject.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#7 lore raw

PATCH 4/10 of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding it

In reply to Yuntao Wang

Use dt_root_addr_size_bytes() instead of open-coding it in __reserved_mem_alloc_size() to improve code maintainability.

---
 drivers/of/of_reserved_mem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/of_reserved_mem.c +1 -1
index 0e6b0e7968a9..8d9139f4297f 100644
@@ -401,7 +401,7 @@ static int __init __reserved_mem_alloc_in_range(phys_addr_t size,
  */
 static int __init __reserved_mem_alloc_size(unsigned long node, const char *uname)
 {
-	int t_len = (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32);
+	int t_len = dt_root_addr_size_bytes();
 	phys_addr_t start = 0, end = 0;
 	phys_addr_t base = 0, align = 0, size;
 	int len;
Signature · 1 line
2.51.0
Reviewed-by on v1 4/10
#8 lore raw

Re: [PATCH 04/10] of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding it

Quoted 4 lines · Yuntao Wang

Use dt_root_addr_size_bytes() instead of open-coding it in __reserved_mem_alloc_size() to improve code maintainability.

But please combine with the previous patch with the same subject.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#9 lore raw

Re: [PATCH 04/10] of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding it

In reply to Yuntao Wang
kernel test robot noticed the following build warnings:

Hi Yuntao,

kernel test robot noticed the following build warnings:

[auto build test WARNING on robh/for-next]
[also build test WARNING on linus/master v6.18-rc5 next-20251113] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Yuntao-Wang/of-fdt-Introduce-dt_root_addr_size_cells-and-dt_root_addr_size_bytes/20251112-232000
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link:    https://lore.kernel.org/r/20251112143520.233870-5-yuntao.wang%40linux.dev
patch subject: [PATCH 04/10] of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding it
config: nios2-randconfig-002-20251113 (https://download.01.org/0day-ci/archive/20251113/[email protected]/config)
compiler: nios2-linux-gcc (GCC) 11.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251113/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>, old ones prefixed by <<):

>> WARNING: modpost: vmlinux: section mismatch in reference: dt_root_addr_size_bytes+0x0 (section: .text.unlikely) -> dt_root_addr_cells (section: .init.data)
>> WARNING: modpost: vmlinux: section mismatch in reference: dt_root_addr_size_bytes+0x4 (section: .text.unlikely) -> dt_root_size_cells (section: .init.data)

WARNING: modpost: vmlinux: section mismatch in reference: dt_root_addr_size_bytes+0x8 (section: .text.unlikely) -> dt_root_addr_cells (section: .init.data)
WARNING: modpost: vmlinux: section mismatch in reference: dt_root_addr_size_bytes+0xc (section: .text.unlikely) -> dt_root_size_cells (section: .init.data)
ERROR: modpost: "__divsi3_table" [lib/lz4/lz4_compress.ko] undefined!

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#10 lore raw

Re: [PATCH 04/10] of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding it

In reply to Yuntao Wang
kernel test robot noticed the following build warnings:

Hi Yuntao,

kernel test robot noticed the following build warnings:

[auto build test WARNING on robh/for-next]
[also build test WARNING on linus/master v6.18-rc5 next-20251113] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Yuntao-Wang/of-fdt-Introduce-dt_root_addr_size_cells-and-dt_root_addr_size_bytes/20251112-232000
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link:    https://lore.kernel.org/r/20251112143520.233870-5-yuntao.wang%40linux.dev
patch subject: [PATCH 04/10] of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding it
config: i386-randconfig-011-20251114 (https://download.01.org/0day-ci/archive/20251114/[email protected]/config)
compiler: gcc-12 (Debian 12.4.0-5) 12.4.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251114/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>, old ones prefixed by <<):

>> WARNING: modpost: vmlinux: section mismatch in reference: dt_root_addr_size_bytes+0x1 (section: .text) -> dt_root_size_cells (section: .init.data)
>> WARNING: modpost: vmlinux: section mismatch in reference: dt_root_addr_size_bytes+0x7 (section: .text) -> dt_root_addr_cells (section: .init.data)
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#11 lore raw

PATCH 5/10 of/fdt: Use dt_root_addr_size_bytes() instead of open-coding it

In reply to Yuntao Wang

Use dt_root_addr_size_bytes() instead of open-coding it in of_fdt_limit_memory() to improve code maintainability.

---
 drivers/of/fdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/fdt.c +1 -1
index 0edd639898a6..a1db3c9ac981 100644
@@ -52,7 +52,7 @@ void __init of_fdt_limit_memory(int limit)
 	int memory;
 	int len;
 	const void *val;
-	int cell_size = sizeof(uint32_t)*(dt_root_addr_cells + dt_root_size_cells);
+	int cell_size = dt_root_addr_size_bytes();
 
 	memory = fdt_path_offset(initial_boot_params, "/memory");
 	if (memory > 0) {
Signature · 1 line
2.51.0
Reviewed-by on v1 5/10
#12 lore raw

Re: [PATCH 05/10] of/fdt: Use dt_root_addr_size_bytes() instead of open-coding it

Quoted 4 lines · Yuntao Wang

Use dt_root_addr_size_bytes() instead of open-coding it in of_fdt_limit_memory() to improve code maintainability.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#13 lore raw

PATCH 6/10 of/fdt: Fix the len check in early_init_dt_check_for_elfcorehdr()

In reply to Yuntao Wang

The len value is in bytes, while dt_root_addr_cells + dt_root_size_cells is in cells (4 bytes per cell).

Comparing them directly is incorrect. Convert units before comparison.

Fixes f7e7ce93aac1 ("of: fdt: Add generic support for handling elf core headers property")
Fixes e62aaeac426ab1dd ("arm64: kdump: provide /proc/vmcore file")
---
 drivers/of/fdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/fdt.c +1 -1
index a1db3c9ac981..716ebe8c23d3 100644
@@ -821,7 +821,7 @@ static void __init early_init_dt_check_for_elfcorehdr(unsigned long node)
 	pr_debug("Looking for elfcorehdr property... ");
 
 	prop = of_get_flat_dt_prop(node, "linux,elfcorehdr", &len);
-	if (!prop || (len < (dt_root_addr_cells + dt_root_size_cells)))
+	if (!prop || len < dt_root_addr_size_bytes())
 		return;
 
 	elfcorehdr_addr = dt_mem_next_cell(dt_root_addr_cells, &prop);
Signature · 1 line
2.51.0
#14 lore raw

PATCH 7/10 of/fdt: Fix the len check in early_init_dt_check_for_usable_mem_range()

In reply to Yuntao Wang

The len value is in bytes, while dt_root_addr_cells + dt_root_size_cells is in cells (4 bytes per cell).

The modulo calculation between them is incorrect, the units must be converted first.

Fixes fb319e77a0e7 ("of: fdt: Add memory for devices by DT property "linux,usable-memory-range"")
---
 drivers/of/fdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/fdt.c +1 -1
index 716ebe8c23d3..0f95f3b356ea 100644
@@ -859,7 +859,7 @@ void __init early_init_dt_check_for_usable_mem_range(void)
 	pr_debug("Looking for usable-memory-range property... ");
 
 	prop = of_get_flat_dt_prop(node, "linux,usable-memory-range", &len);
-	if (!prop || (len % (dt_root_addr_cells + dt_root_size_cells)))
+	if (!prop || len % dt_root_addr_size_bytes())
 		return;
 
 	endp = prop + (len / sizeof(__be32));
Signature · 1 line
2.51.0
Reviewed-by on v1 7/10
#15 lore raw

Re: [PATCH 07/10] of/fdt: Fix the len check in early_init_dt_check_for_usable_mem_range()

Hi Yuntao,

Quoted 5 lines · Yuntao Wang

The len value is in bytes, while dt_root_addr_cells + dt_root_size_cells is in cells (4 bytes per cell).

The modulo calculation between them is incorrect, the units must be converted first.

Thanks for your patch!

Quoted 1 line
Fixes fb319e77a0e7 ("of: fdt: Add memory for devices by DT property "linux,usable-memory-range"")

That commit merely changed "<" to "%".

The code that added the bad expression was:

Fixes 2af2b50acf9b9c38 ("of: fdt: Add generic support for handling

usable memory range property")
However, that code was copied from:

Fixes 8f579b1c4e347b23 ("arm64: limit memory regions based on DT

property, usable-memory-range")

So I think you want to list these two Fixes-tags instead.

Quoted 1 line

For the actual change:

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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

#16 lore raw

PATCH 8/10 of/fdt: Use dt_root_addr_size_bytes() instead of open-coding it

In reply to Yuntao Wang

Use dt_root_addr_size_bytes() instead of open-coding it in early_init_dt_check_kho() to improve code maintainability.

---
 drivers/of/fdt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/of/fdt.c +2 -2
index 0f95f3b356ea..fa1703612530 100644
@@ -890,14 +890,14 @@ static void __init early_init_dt_check_kho(void)
 		return;
 
 	p = of_get_flat_dt_prop(node, "linux,kho-fdt", &l);
-	if (l != (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32))
+	if (l != dt_root_addr_size_bytes())
 		return;
 
 	fdt_start = dt_mem_next_cell(dt_root_addr_cells, &p);
 	fdt_size = dt_mem_next_cell(dt_root_addr_cells, &p);
 
 	p = of_get_flat_dt_prop(node, "linux,kho-scratch", &l);
-	if (l != (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32))
+	if (l != dt_root_addr_size_bytes())
 		return;
 
 	scratch_start = dt_mem_next_cell(dt_root_addr_cells, &p);
Signature · 1 line
2.51.0
Reviewed-by on v1 8/10
#17 lore raw

Re: [PATCH 08/10] of/fdt: Use dt_root_addr_size_bytes() instead of open-coding it

Quoted 4 lines · Yuntao Wang

Use dt_root_addr_size_bytes() instead of open-coding it in early_init_dt_check_kho() to improve code maintainability.

But please combine with the other patch with the same subject.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#18 lore raw

PATCH 9/10 of/fdt: Fix incorrect use of dt_root_addr_cells in early_init_dt_check_kho()

In reply to Yuntao Wang

When reading the fdt_size value, the argument passed to dt_mem_next_cell() is dt_root_addr_cells, but it should be dt_root_size_cells.

The same issue occurs when reading the scratch_size value.

Fix these issues.

Fixes 274cdcb1c004 ("arm64: add KHO support")
---
 drivers/of/fdt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/of/fdt.c +2 -2
index fa1703612530..3b34c7e71ebc 100644
@@ -894,14 +894,14 @@ static void __init early_init_dt_check_kho(void)
 		return;
 
 	fdt_start = dt_mem_next_cell(dt_root_addr_cells, &p);
-	fdt_size = dt_mem_next_cell(dt_root_addr_cells, &p);
+	fdt_size = dt_mem_next_cell(dt_root_size_cells, &p);
 
 	p = of_get_flat_dt_prop(node, "linux,kho-scratch", &l);
 	if (l != dt_root_addr_size_bytes())
 		return;
 
 	scratch_start = dt_mem_next_cell(dt_root_addr_cells, &p);
-	scratch_size = dt_mem_next_cell(dt_root_addr_cells, &p);
+	scratch_size = dt_mem_next_cell(dt_root_size_cells, &p);
 
 	kho_populate(fdt_start, fdt_size, scratch_start, scratch_size);
 }
Signature · 1 line
2.51.0
Reviewed-by on v1 9/10
#19 lore raw

Re: [PATCH 09/10] of/fdt: Fix incorrect use of dt_root_addr_cells in early_init_dt_check_kho()

Hi Yuntao,

Quoted 9 lines · Yuntao Wang

When reading the fdt_size value, the argument passed to dt_mem_next_cell() is dt_root_addr_cells, but it should be dt_root_size_cells.

The same issue occurs when reading the scratch_size value.

Fix these issues.

Fixes 274cdcb1c004 ("arm64: add KHO support")

Thanks for your patch!

drivers/of/fdt.c static void __init early_init_dt_check_kho(void) · line 897

Quoted 8 lines
drivers/of/fdt.c +1 -1
@@ -894,14 +894,14 @@ static void __init early_init_dt_check_kho(void)
                return;
 
        fdt_start = dt_mem_next_cell(dt_root_addr_cells, &p);
-       fdt_size = dt_mem_next_cell(dt_root_addr_cells, &p);
+       fdt_size = dt_mem_next_cell(dt_root_size_cells, &p);

I think it would be worthwhile to have separate dt_mem_next_addr_cell() and dt_mem_next_size_cell() helpers. That would us bring a few steps closer to the following goal stated in <linux/of_fdt.h>:

    /* 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;

drivers/of/fdt.c static void __init early_init_dt_check_kho(void) · line 907

Quoted 11 lines
drivers/of/fdt.c +1 -1
        p = of_get_flat_dt_prop(node, "linux,kho-scratch", &l);
        if (l != dt_root_addr_size_bytes())
                return;
 
        scratch_start = dt_mem_next_cell(dt_root_addr_cells, &p);
-       scratch_size = dt_mem_next_cell(dt_root_addr_cells, &p);
+       scratch_size = dt_mem_next_cell(dt_root_size_cells, &p);
 
        kho_populate(fdt_start, fdt_size, scratch_start, scratch_size);
 }

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#20 lore raw

PATCH 10/10 of/address: Remove the incorrect and misleading comment

In reply to Yuntao Wang

The of_bus_default_match() function appears to have been copied from of_bus_default_flags_match() with some modifications.

However, the comment was left unchanged and still describes the behavior of of_bus_default_flags_match(), it is incorrect and misleading, remove it.

---
 drivers/of/address.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/of/address.c +0 -4
index f0f8f0dd191c..4034d798c55a 100644
@@ -328,10 +328,6 @@ static int of_bus_default_flags_match(struct device_node *np)
 
 static int of_bus_default_match(struct device_node *np)
 {
-	/*
-	 * Check for presence first since of_bus_n_addr_cells() will warn when
-	 * walking parent nodes.
-	 */
 	return of_property_present(np, "#address-cells");
 }
 
Signature · 1 line
2.51.0
Reviewed-by on v1 10/10
#21 lore raw

Re: [PATCH 10/10] of/address: Remove the incorrect and misleading comment

Quoted 7 lines · Yuntao Wang

The of_bus_default_match() function appears to have been copied from of_bus_default_flags_match() with some modifications.

However, the comment was left unchanged and still describes the behavior of of_bus_default_flags_match(), it is incorrect and misleading, remove it.

Fixes 6e5773d52f4a2d9c ("of/address: Fix WARN when attempting

translating non-translatable addresses")

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
maintainer
#22 lore raw

Re: [PATCH 10/10] of/address: Remove the incorrect and misleading comment

In reply to Yuntao Wang
Quoted 5 lines · Yuntao Wang

The of_bus_default_match() function appears to have been copied from of_bus_default_flags_match() with some modifications.

However, the comment was left unchanged and still describes the behavior of of_bus_default_flags_match(), it is incorrect and misleading, remove it.

There is no reason to put this patch in this series. It is completely unrelated.

Quoted 24 lines
---
 drivers/of/address.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/of/address.c +0 -4
index f0f8f0dd191c..4034d798c55a 100644
@@ -328,10 +328,6 @@ static int of_bus_default_flags_match(struct device_node *np)
 
 static int of_bus_default_match(struct device_node *np)
 {
-	/*
-	 * Check for presence first since of_bus_n_addr_cells() will warn when
-	 * walking parent nodes.
-	 */
 	return of_property_present(np, "#address-cells");
 }
 
Signature · 1 line
2.51.0
maintainer Applied
#23 lore raw

Re: [PATCH 10/10] of/address: Remove the incorrect and misleading comment

In reply to Yuntao Wang
Quoted 10 lines · Yuntao Wang

The of_bus_default_match() function appears to have been copied from of_bus_default_flags_match() with some modifications.

However, the comment was left unchanged and still describes the behavior of of_bus_default_flags_match(), it is incorrect and misleading, remove it.

---
 drivers/of/address.c | 4 ----
 1 file changed, 4 deletions(-)

Applied, thanks!

maintainer
#24 lore raw
In reply to Yuntao Wang
Quoted 7 lines · Yuntao Wang

This patch series fixes several bugs related to dt_root_addr_cells and dt_root_size_cells, and performs some cleanup.

Links to the previous related patches:

https://lore.kernel.org/lkml/CAL_JsqJxar7z+VcBXwPTw5-Et2oC9bQmH_CtMtKhoo_-=zN2XQ@mail.gmail.com/

Quoted 9 lines

Yuntao Wang (10):
of/fdt: Introduce dt_root_addr_size_cells() and
dt_root_addr_size_bytes()
of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding
it
of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding
it
of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding
it

Your aim in writing subjects should be to write something that is unique for every commit in the past or future. Because you can never make the same change twice, right? (I'm excluding 'fix typos/spelling' type commits). Certainly the same subject in one series is never right.

Quoted 5 lines

of/fdt: Use dt_root_addr_size_bytes() instead of open-coding it of/fdt: Fix the len check in early_init_dt_check_for_elfcorehdr() of/fdt: Fix the len check in
early_init_dt_check_for_usable_mem_range()
of/fdt: Use dt_root_addr_size_bytes() instead of open-coding it

This is not what I meant. We have multiple copies of this where only the property name changes:

	prop = of_get_flat_dt_prop(node, "linux,elfcorehdr", &len);
	if (!prop || (len < (dt_root_addr_cells + dt_root_size_cells)))
		return;

	elfcorehdr_addr = dt_mem_next_cell(dt_root_addr_cells, &prop);
	elfcorehdr_size = dt_mem_next_cell(dt_root_size_cells, &prop);

Instead, add a function something like this:

static void early_init_dt_read_address(unsigned long node, const char *prop, u64 *addr, u64*size)

{
        prop = of_get_flat_dt_prop(node, prop, &len);
        if (!prop || (len < (dt_root_addr_cells + dt_root_size_cells)))
                return;

        *addr = dt_mem_next_cell(dt_root_addr_cells, &prop);
        *size = dt_mem_next_cell(dt_root_size_cells, &prop);
}

Then we only have the length checks in one place.

That still leaves the cases with more than 1 entry open coded. So instead, to cover that case to something like this:

const __be32 *of_get_flat_dt_address_prop(unsigned long node, const char *propname, int *len)

{
	prop = of_get_flat_dt_prop(node, propname, &len);
	if (!prop || (*len % (dt_root_addr_cells + dt_root_size_cells))) {
		*len = 0;
		return NULL;
	}

	*len /= (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32);
	return prop;
}

And then a user would look something like this:

prop = of_get_flat_dt_address(node, "linux,usable-memory-range", &len);

for (i = 0; i < len; i++) {
	of_read_address_idx(prop, i, &addr, &size);
	...
}

Here 'len' is number of addr+size entries.

And the simple case of reading 1 entry could be just:

of_read_address_idx(of_get_flat_dt_address(node, "linux,elfcorehdr", NULL), 0, &addr, &size);

Rob

#25 lore raw
Quoted 79 lines · Rob Herring
Quoted 7 lines · Yuntao Wang

This patch series fixes several bugs related to dt_root_addr_cells and dt_root_size_cells, and performs some cleanup.

Links to the previous related patches:

https://lore.kernel.org/lkml/CAL_JsqJxar7z+VcBXwPTw5-Et2oC9bQmH_CtMtKhoo_-=zN2XQ@mail.gmail.com/

Quoted 9 lines

Yuntao Wang (10):
of/fdt: Introduce dt_root_addr_size_cells() and
dt_root_addr_size_bytes()
of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding
it
of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding
it
of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding
it

Your aim in writing subjects should be to write something that is unique for every commit in the past or future. Because you can never make the same change twice, right? (I'm excluding 'fix typos/spelling' type commits). Certainly the same subject in one series is never right.

Quoted 5 lines

of/fdt: Use dt_root_addr_size_bytes() instead of open-coding it of/fdt: Fix the len check in early_init_dt_check_for_elfcorehdr() of/fdt: Fix the len check in
early_init_dt_check_for_usable_mem_range()
of/fdt: Use dt_root_addr_size_bytes() instead of open-coding it

This is not what I meant. We have multiple copies of this where only the property name changes:

	prop = of_get_flat_dt_prop(node, "linux,elfcorehdr", &len);
	if (!prop || (len < (dt_root_addr_cells + dt_root_size_cells)))
		return;

	elfcorehdr_addr = dt_mem_next_cell(dt_root_addr_cells, &prop);
	elfcorehdr_size = dt_mem_next_cell(dt_root_size_cells, &prop);

Instead, add a function something like this:

static void early_init_dt_read_address(unsigned long node, const char *prop, u64 *addr, u64*size)

{
        prop = of_get_flat_dt_prop(node, prop, &len);
        if (!prop || (len < (dt_root_addr_cells + dt_root_size_cells)))
                return;

        *addr = dt_mem_next_cell(dt_root_addr_cells, &prop);
        *size = dt_mem_next_cell(dt_root_size_cells, &prop);
}

Then we only have the length checks in one place.

That still leaves the cases with more than 1 entry open coded. So instead, to cover that case to something like this:

const __be32 *of_get_flat_dt_address_prop(unsigned long node, const char *propname, int *len)

{
	prop = of_get_flat_dt_prop(node, propname, &len);
	if (!prop || (*len % (dt_root_addr_cells + dt_root_size_cells))) {
		*len = 0;
		return NULL;
	}

	*len /= (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32);
	return prop;
}

And then a user would look something like this:

prop = of_get_flat_dt_address(node, "linux,usable-memory-range", &len);

for (i = 0; i < len; i++) {
	of_read_address_idx(prop, i, &addr, &size);
	...
}
Quoted 7 lines

Here 'len' is number of addr+size entries.

And the simple case of reading 1 entry could be just:

of_read_address_idx(of_get_flat_dt_address(node, "linux,elfcorehdr", NULL), 0, &addr, &size);

Rob

Hi Rob,

The link to the new patch series:

https://lore.kernel.org/linux-devicetree/[email protected]/t/

Thanks,
Yuntao