devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/10] of/fdt: Some bug fixes and cleanups
@ 2025-11-12 14:35 Yuntao Wang
  2025-11-12 14:35 ` [PATCH 01/10] of/fdt: Introduce dt_root_addr_size_cells() and dt_root_addr_size_bytes() Yuntao Wang
                   ` (10 more replies)
  0 siblings, 11 replies; 26+ messages in thread
From: Yuntao Wang @ 2025-11-12 14:35 UTC (permalink / raw)
  To: Rob Herring, Saravana Kannan
  Cc: Geert Uytterhoeven, Catalin Marinas, AKASHI Takahiro, James Morse,
	Chen Zhou, Baoquan He, Zhen Lei, Andrew Morton, Changyuan Lyu,
	Alexander Graf, Mike Rapoport (Microsoft), devicetree,
	linux-kernel, 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/

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(-)

-- 
2.51.0

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

* [PATCH 01/10] of/fdt: Introduce dt_root_addr_size_cells() and dt_root_addr_size_bytes()
  2025-11-12 14:35 [PATCH 00/10] of/fdt: Some bug fixes and cleanups Yuntao Wang
@ 2025-11-12 14:35 ` Yuntao Wang
  2025-11-12 16:25   ` Geert Uytterhoeven
  2025-11-12 14:35 ` [PATCH 02/10] of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding it Yuntao Wang
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 26+ messages in thread
From: Yuntao Wang @ 2025-11-12 14:35 UTC (permalink / raw)
  To: Rob Herring, Saravana Kannan
  Cc: Geert Uytterhoeven, Catalin Marinas, AKASHI Takahiro, James Morse,
	Chen Zhou, Baoquan He, Zhen Lei, Andrew Morton, Changyuan Lyu,
	Alexander Graf, Mike Rapoport (Microsoft), devicetree,
	linux-kernel, 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.

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


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

* [PATCH 02/10] of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding it
  2025-11-12 14:35 [PATCH 00/10] of/fdt: Some bug fixes and cleanups Yuntao Wang
  2025-11-12 14:35 ` [PATCH 01/10] of/fdt: Introduce dt_root_addr_size_cells() and dt_root_addr_size_bytes() Yuntao Wang
@ 2025-11-12 14:35 ` Yuntao Wang
  2025-11-12 16:28   ` Geert Uytterhoeven
  2025-11-12 14:35 ` [PATCH 03/10] " Yuntao Wang
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 26+ messages in thread
From: Yuntao Wang @ 2025-11-12 14:35 UTC (permalink / raw)
  To: Rob Herring, Saravana Kannan
  Cc: Geert Uytterhoeven, Catalin Marinas, AKASHI Takahiro, James Morse,
	Chen Zhou, Baoquan He, Zhen Lei, Andrew Morton, Changyuan Lyu,
	Alexander Graf, Mike Rapoport (Microsoft), devicetree,
	linux-kernel, Yuntao Wang

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

Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
---
 drivers/of/of_reserved_mem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index 2e9ea751ed2d..67c0ccd373c2 100644
--- a/drivers/of/of_reserved_mem.c
+++ b/drivers/of/of_reserved_mem.c
@@ -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;
-- 
2.51.0


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

* [PATCH 03/10] of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding it
  2025-11-12 14:35 [PATCH 00/10] of/fdt: Some bug fixes and cleanups Yuntao Wang
  2025-11-12 14:35 ` [PATCH 01/10] of/fdt: Introduce dt_root_addr_size_cells() and dt_root_addr_size_bytes() Yuntao Wang
  2025-11-12 14:35 ` [PATCH 02/10] of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding it Yuntao Wang
@ 2025-11-12 14:35 ` Yuntao Wang
  2025-11-12 16:29   ` Geert Uytterhoeven
  2025-11-12 14:35 ` [PATCH 04/10] " Yuntao Wang
                   ` (7 subsequent siblings)
  10 siblings, 1 reply; 26+ messages in thread
From: Yuntao Wang @ 2025-11-12 14:35 UTC (permalink / raw)
  To: Rob Herring, Saravana Kannan
  Cc: Geert Uytterhoeven, Catalin Marinas, AKASHI Takahiro, James Morse,
	Chen Zhou, Baoquan He, Zhen Lei, Andrew Morton, Changyuan Lyu,
	Alexander Graf, Mike Rapoport (Microsoft), devicetree,
	linux-kernel, Yuntao Wang

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

Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
---
 drivers/of/of_reserved_mem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index 67c0ccd373c2..0e6b0e7968a9 100644
--- a/drivers/of/of_reserved_mem.c
+++ b/drivers/of/of_reserved_mem.c
@@ -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;
-- 
2.51.0


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

* [PATCH 04/10] of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding it
  2025-11-12 14:35 [PATCH 00/10] of/fdt: Some bug fixes and cleanups Yuntao Wang
                   ` (2 preceding siblings ...)
  2025-11-12 14:35 ` [PATCH 03/10] " Yuntao Wang
@ 2025-11-12 14:35 ` Yuntao Wang
  2025-11-12 16:30   ` Geert Uytterhoeven
                     ` (2 more replies)
  2025-11-12 14:35 ` [PATCH 05/10] of/fdt: " Yuntao Wang
                   ` (6 subsequent siblings)
  10 siblings, 3 replies; 26+ messages in thread
From: Yuntao Wang @ 2025-11-12 14:35 UTC (permalink / raw)
  To: Rob Herring, Saravana Kannan
  Cc: Geert Uytterhoeven, Catalin Marinas, AKASHI Takahiro, James Morse,
	Chen Zhou, Baoquan He, Zhen Lei, Andrew Morton, Changyuan Lyu,
	Alexander Graf, Mike Rapoport (Microsoft), devicetree,
	linux-kernel, Yuntao Wang

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

Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
---
 drivers/of/of_reserved_mem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index 0e6b0e7968a9..8d9139f4297f 100644
--- a/drivers/of/of_reserved_mem.c
+++ b/drivers/of/of_reserved_mem.c
@@ -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;
-- 
2.51.0


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

* [PATCH 05/10] of/fdt: Use dt_root_addr_size_bytes() instead of open-coding it
  2025-11-12 14:35 [PATCH 00/10] of/fdt: Some bug fixes and cleanups Yuntao Wang
                   ` (3 preceding siblings ...)
  2025-11-12 14:35 ` [PATCH 04/10] " Yuntao Wang
@ 2025-11-12 14:35 ` Yuntao Wang
  2025-11-12 16:32   ` Geert Uytterhoeven
  2025-11-12 14:35 ` [PATCH 06/10] of/fdt: Fix the len check in early_init_dt_check_for_elfcorehdr() Yuntao Wang
                   ` (5 subsequent siblings)
  10 siblings, 1 reply; 26+ messages in thread
From: Yuntao Wang @ 2025-11-12 14:35 UTC (permalink / raw)
  To: Rob Herring, Saravana Kannan
  Cc: Geert Uytterhoeven, Catalin Marinas, AKASHI Takahiro, James Morse,
	Chen Zhou, Baoquan He, Zhen Lei, Andrew Morton, Changyuan Lyu,
	Alexander Graf, Mike Rapoport (Microsoft), devicetree,
	linux-kernel, Yuntao Wang

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

Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
---
 drivers/of/fdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 0edd639898a6..a1db3c9ac981 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -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) {
-- 
2.51.0


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

* [PATCH 06/10] of/fdt: Fix the len check in early_init_dt_check_for_elfcorehdr()
  2025-11-12 14:35 [PATCH 00/10] of/fdt: Some bug fixes and cleanups Yuntao Wang
                   ` (4 preceding siblings ...)
  2025-11-12 14:35 ` [PATCH 05/10] of/fdt: " Yuntao Wang
@ 2025-11-12 14:35 ` Yuntao Wang
  2025-11-12 14:35 ` [PATCH 07/10] of/fdt: Fix the len check in early_init_dt_check_for_usable_mem_range() Yuntao Wang
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 26+ messages in thread
From: Yuntao Wang @ 2025-11-12 14:35 UTC (permalink / raw)
  To: Rob Herring, Saravana Kannan
  Cc: Geert Uytterhoeven, Catalin Marinas, AKASHI Takahiro, James Morse,
	Chen Zhou, Baoquan He, Zhen Lei, Andrew Morton, Changyuan Lyu,
	Alexander Graf, Mike Rapoport (Microsoft), devicetree,
	linux-kernel, 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")
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
---
 drivers/of/fdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index a1db3c9ac981..716ebe8c23d3 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -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);
-- 
2.51.0


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

* [PATCH 07/10] of/fdt: Fix the len check in early_init_dt_check_for_usable_mem_range()
  2025-11-12 14:35 [PATCH 00/10] of/fdt: Some bug fixes and cleanups Yuntao Wang
                   ` (5 preceding siblings ...)
  2025-11-12 14:35 ` [PATCH 06/10] of/fdt: Fix the len check in early_init_dt_check_for_elfcorehdr() Yuntao Wang
@ 2025-11-12 14:35 ` Yuntao Wang
  2025-11-12 16:47   ` Geert Uytterhoeven
  2025-11-12 14:35 ` [PATCH 08/10] of/fdt: Use dt_root_addr_size_bytes() instead of open-coding it Yuntao Wang
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 26+ messages in thread
From: Yuntao Wang @ 2025-11-12 14:35 UTC (permalink / raw)
  To: Rob Herring, Saravana Kannan
  Cc: Geert Uytterhoeven, Catalin Marinas, AKASHI Takahiro, James Morse,
	Chen Zhou, Baoquan He, Zhen Lei, Andrew Morton, Changyuan Lyu,
	Alexander Graf, Mike Rapoport (Microsoft), devicetree,
	linux-kernel, 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"")
Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
---
 drivers/of/fdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 716ebe8c23d3..0f95f3b356ea 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -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));
-- 
2.51.0


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

* [PATCH 08/10] of/fdt: Use dt_root_addr_size_bytes() instead of open-coding it
  2025-11-12 14:35 [PATCH 00/10] of/fdt: Some bug fixes and cleanups Yuntao Wang
                   ` (6 preceding siblings ...)
  2025-11-12 14:35 ` [PATCH 07/10] of/fdt: Fix the len check in early_init_dt_check_for_usable_mem_range() Yuntao Wang
@ 2025-11-12 14:35 ` Yuntao Wang
  2025-11-12 16:33   ` Geert Uytterhoeven
  2025-11-12 14:35 ` [PATCH 09/10] of/fdt: Fix incorrect use of dt_root_addr_cells in early_init_dt_check_kho() Yuntao Wang
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 26+ messages in thread
From: Yuntao Wang @ 2025-11-12 14:35 UTC (permalink / raw)
  To: Rob Herring, Saravana Kannan
  Cc: Geert Uytterhoeven, Catalin Marinas, AKASHI Takahiro, James Morse,
	Chen Zhou, Baoquan He, Zhen Lei, Andrew Morton, Changyuan Lyu,
	Alexander Graf, Mike Rapoport (Microsoft), devicetree,
	linux-kernel, Yuntao Wang

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

Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
---
 drivers/of/fdt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 0f95f3b356ea..fa1703612530 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -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);
-- 
2.51.0


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

* [PATCH 09/10] of/fdt: Fix incorrect use of dt_root_addr_cells in early_init_dt_check_kho()
  2025-11-12 14:35 [PATCH 00/10] of/fdt: Some bug fixes and cleanups Yuntao Wang
                   ` (7 preceding siblings ...)
  2025-11-12 14:35 ` [PATCH 08/10] of/fdt: Use dt_root_addr_size_bytes() instead of open-coding it Yuntao Wang
@ 2025-11-12 14:35 ` Yuntao Wang
  2025-11-12 16:54   ` Geert Uytterhoeven
  2025-11-12 14:35 ` [PATCH 10/10] of/address: Remove the incorrect and misleading comment Yuntao Wang
  2025-11-12 20:55 ` [PATCH 00/10] of/fdt: Some bug fixes and cleanups Rob Herring
  10 siblings, 1 reply; 26+ messages in thread
From: Yuntao Wang @ 2025-11-12 14:35 UTC (permalink / raw)
  To: Rob Herring, Saravana Kannan
  Cc: Geert Uytterhoeven, Catalin Marinas, AKASHI Takahiro, James Morse,
	Chen Zhou, Baoquan He, Zhen Lei, Andrew Morton, Changyuan Lyu,
	Alexander Graf, Mike Rapoport (Microsoft), devicetree,
	linux-kernel, 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")
Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
---
 drivers/of/fdt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index fa1703612530..3b34c7e71ebc 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -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);
 }
-- 
2.51.0


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

* [PATCH 10/10] of/address: Remove the incorrect and misleading comment
  2025-11-12 14:35 [PATCH 00/10] of/fdt: Some bug fixes and cleanups Yuntao Wang
                   ` (8 preceding siblings ...)
  2025-11-12 14:35 ` [PATCH 09/10] of/fdt: Fix incorrect use of dt_root_addr_cells in early_init_dt_check_kho() Yuntao Wang
@ 2025-11-12 14:35 ` Yuntao Wang
  2025-11-12 16:56   ` Geert Uytterhoeven
                     ` (2 more replies)
  2025-11-12 20:55 ` [PATCH 00/10] of/fdt: Some bug fixes and cleanups Rob Herring
  10 siblings, 3 replies; 26+ messages in thread
From: Yuntao Wang @ 2025-11-12 14:35 UTC (permalink / raw)
  To: Rob Herring, Saravana Kannan
  Cc: Geert Uytterhoeven, Catalin Marinas, AKASHI Takahiro, James Morse,
	Chen Zhou, Baoquan He, Zhen Lei, Andrew Morton, Changyuan Lyu,
	Alexander Graf, Mike Rapoport (Microsoft), devicetree,
	linux-kernel, 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.

Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
---
 drivers/of/address.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/of/address.c b/drivers/of/address.c
index f0f8f0dd191c..4034d798c55a 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -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");
 }
 
-- 
2.51.0


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

* Re: [PATCH 01/10] of/fdt: Introduce dt_root_addr_size_cells() and dt_root_addr_size_bytes()
  2025-11-12 14:35 ` [PATCH 01/10] of/fdt: Introduce dt_root_addr_size_cells() and dt_root_addr_size_bytes() Yuntao Wang
@ 2025-11-12 16:25   ` Geert Uytterhoeven
  0 siblings, 0 replies; 26+ messages in thread
From: Geert Uytterhoeven @ 2025-11-12 16:25 UTC (permalink / raw)
  To: Yuntao Wang
  Cc: Rob Herring, Saravana Kannan, Catalin Marinas, AKASHI Takahiro,
	James Morse, Chen Zhou, Baoquan He, Zhen Lei, Andrew Morton,
	Changyuan Lyu, Alexander Graf, Mike Rapoport (Microsoft),
	devicetree, linux-kernel

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

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

* Re: [PATCH 02/10] of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding it
  2025-11-12 14:35 ` [PATCH 02/10] of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding it Yuntao Wang
@ 2025-11-12 16:28   ` Geert Uytterhoeven
  0 siblings, 0 replies; 26+ messages in thread
From: Geert Uytterhoeven @ 2025-11-12 16:28 UTC (permalink / raw)
  To: Yuntao Wang
  Cc: Rob Herring, Saravana Kannan, Catalin Marinas, AKASHI Takahiro,
	James Morse, Chen Zhou, Baoquan He, Zhen Lei, Andrew Morton,
	Changyuan Lyu, Alexander Graf, Mike Rapoport (Microsoft),
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	Linux Kernel Mailing List

On Wed, 12 Nov 2025 at 15:37, Yuntao Wang <yuntao.wang@linux.dev> wrote:
> Use dt_root_addr_size_bytes() instead of open-coding it in
> __reserved_mem_reserve_reg() to improve code maintainability.
>
> 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

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

* Re: [PATCH 03/10] of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding it
  2025-11-12 14:35 ` [PATCH 03/10] " Yuntao Wang
@ 2025-11-12 16:29   ` Geert Uytterhoeven
  0 siblings, 0 replies; 26+ messages in thread
From: Geert Uytterhoeven @ 2025-11-12 16:29 UTC (permalink / raw)
  To: Yuntao Wang
  Cc: Rob Herring, Saravana Kannan, Catalin Marinas, AKASHI Takahiro,
	James Morse, Chen Zhou, Baoquan He, Zhen Lei, Andrew Morton,
	Changyuan Lyu, Alexander Graf, Mike Rapoport (Microsoft),
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	Linux Kernel Mailing List

On Wed, 12 Nov 2025 at 15:37, Yuntao Wang <yuntao.wang@linux.dev> wrote:
> Use dt_root_addr_size_bytes() instead of open-coding it in
> fdt_scan_reserved_mem_reg_nodes() to improve code maintainability.
>
> Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>

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

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

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

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

* Re: [PATCH 04/10] of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding it
  2025-11-12 14:35 ` [PATCH 04/10] " Yuntao Wang
@ 2025-11-12 16:30   ` Geert Uytterhoeven
  2025-11-13 14:21   ` kernel test robot
  2025-11-13 23:46   ` kernel test robot
  2 siblings, 0 replies; 26+ messages in thread
From: Geert Uytterhoeven @ 2025-11-12 16:30 UTC (permalink / raw)
  To: Yuntao Wang
  Cc: Rob Herring, Saravana Kannan, Catalin Marinas, AKASHI Takahiro,
	James Morse, Chen Zhou, Baoquan He, Zhen Lei, Andrew Morton,
	Changyuan Lyu, Alexander Graf, Mike Rapoport (Microsoft),
	devicetree, linux-kernel

On Wed, 12 Nov 2025 at 15:37, Yuntao Wang <yuntao.wang@linux.dev> wrote:
> Use dt_root_addr_size_bytes() instead of open-coding it in
> __reserved_mem_alloc_size() to improve code maintainability.
>
> Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>

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

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

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

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

* Re: [PATCH 05/10] of/fdt: Use dt_root_addr_size_bytes() instead of open-coding it
  2025-11-12 14:35 ` [PATCH 05/10] of/fdt: " Yuntao Wang
@ 2025-11-12 16:32   ` Geert Uytterhoeven
  0 siblings, 0 replies; 26+ messages in thread
From: Geert Uytterhoeven @ 2025-11-12 16:32 UTC (permalink / raw)
  To: Yuntao Wang
  Cc: Rob Herring, Saravana Kannan, Catalin Marinas, AKASHI Takahiro,
	James Morse, Chen Zhou, Baoquan He, Zhen Lei, Andrew Morton,
	Changyuan Lyu, Alexander Graf, Mike Rapoport (Microsoft),
	devicetree, linux-kernel

On Wed, 12 Nov 2025 at 15:37, Yuntao Wang <yuntao.wang@linux.dev> wrote:
> Use dt_root_addr_size_bytes() instead of open-coding it in
> of_fdt_limit_memory() to improve code maintainability.
>
> 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

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

* Re: [PATCH 08/10] of/fdt: Use dt_root_addr_size_bytes() instead of open-coding it
  2025-11-12 14:35 ` [PATCH 08/10] of/fdt: Use dt_root_addr_size_bytes() instead of open-coding it Yuntao Wang
@ 2025-11-12 16:33   ` Geert Uytterhoeven
  0 siblings, 0 replies; 26+ messages in thread
From: Geert Uytterhoeven @ 2025-11-12 16:33 UTC (permalink / raw)
  To: Yuntao Wang
  Cc: Rob Herring, Saravana Kannan, Catalin Marinas, James Morse,
	Baoquan He, Zhen Lei, Andrew Morton, Changyuan Lyu,
	Alexander Graf, Mike Rapoport (Microsoft), devicetree,
	linux-kernel

On Wed, 12 Nov 2025 at 15:38, Yuntao Wang <yuntao.wang@linux.dev> wrote:
> Use dt_root_addr_size_bytes() instead of open-coding it in
> early_init_dt_check_kho() to improve code maintainability.
>
> Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>

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

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

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

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

* Re: [PATCH 07/10] of/fdt: Fix the len check in early_init_dt_check_for_usable_mem_range()
  2025-11-12 14:35 ` [PATCH 07/10] of/fdt: Fix the len check in early_init_dt_check_for_usable_mem_range() Yuntao Wang
@ 2025-11-12 16:47   ` Geert Uytterhoeven
  0 siblings, 0 replies; 26+ messages in thread
From: Geert Uytterhoeven @ 2025-11-12 16:47 UTC (permalink / raw)
  To: Yuntao Wang
  Cc: Rob Herring, Saravana Kannan, Catalin Marinas, James Morse,
	Baoquan He, Zhen Lei, Andrew Morton, Changyuan Lyu,
	Alexander Graf, Mike Rapoport (Microsoft), devicetree,
	linux-kernel

Hi Yuntao,

On Wed, 12 Nov 2025 at 15:38, Yuntao Wang <yuntao.wang@linux.dev> wrote:
> 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!

> 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.

> Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>

For the actual change:
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

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

* Re: [PATCH 09/10] of/fdt: Fix incorrect use of dt_root_addr_cells in early_init_dt_check_kho()
  2025-11-12 14:35 ` [PATCH 09/10] of/fdt: Fix incorrect use of dt_root_addr_cells in early_init_dt_check_kho() Yuntao Wang
@ 2025-11-12 16:54   ` Geert Uytterhoeven
  0 siblings, 0 replies; 26+ messages in thread
From: Geert Uytterhoeven @ 2025-11-12 16:54 UTC (permalink / raw)
  To: Yuntao Wang
  Cc: Rob Herring, Saravana Kannan, Catalin Marinas, James Morse,
	Baoquan He, Zhen Lei, Andrew Morton, Changyuan Lyu,
	Alexander Graf, Mike Rapoport (Microsoft), devicetree,
	linux-kernel

Hi Yuntao,

On Wed, 12 Nov 2025 at 15:38, Yuntao Wang <yuntao.wang@linux.dev> wrote:
> 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")
> Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>

Thanks for your patch!

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

> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -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;

>
>         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

-- 
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

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

* Re: [PATCH 10/10] of/address: Remove the incorrect and misleading comment
  2025-11-12 14:35 ` [PATCH 10/10] of/address: Remove the incorrect and misleading comment Yuntao Wang
@ 2025-11-12 16:56   ` Geert Uytterhoeven
  2025-11-12 20:07   ` Rob Herring
  2025-11-12 20:08   ` Rob Herring
  2 siblings, 0 replies; 26+ messages in thread
From: Geert Uytterhoeven @ 2025-11-12 16:56 UTC (permalink / raw)
  To: Yuntao Wang
  Cc: Rob Herring, Saravana Kannan, Catalin Marinas, James Morse,
	Baoquan He, Zhen Lei, Andrew Morton, Changyuan Lyu,
	Alexander Graf, Mike Rapoport (Microsoft), devicetree,
	linux-kernel

On Wed, 12 Nov 2025 at 15:38, Yuntao Wang <yuntao.wang@linux.dev> wrote:
> 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.
>
> Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>

Fixes: 6e5773d52f4a2d9c ("of/address: Fix WARN when attempting
translating non-translatable addresses")
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

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

* Re: [PATCH 10/10] of/address: Remove the incorrect and misleading comment
  2025-11-12 14:35 ` [PATCH 10/10] of/address: Remove the incorrect and misleading comment Yuntao Wang
  2025-11-12 16:56   ` Geert Uytterhoeven
@ 2025-11-12 20:07   ` Rob Herring
  2025-11-12 20:08   ` Rob Herring
  2 siblings, 0 replies; 26+ messages in thread
From: Rob Herring @ 2025-11-12 20:07 UTC (permalink / raw)
  To: Yuntao Wang
  Cc: Saravana Kannan, Geert Uytterhoeven, Catalin Marinas,
	AKASHI Takahiro, James Morse, Chen Zhou, Baoquan He, Zhen Lei,
	Andrew Morton, Changyuan Lyu, Alexander Graf,
	Mike Rapoport (Microsoft), devicetree, linux-kernel

On Wed, Nov 12, 2025 at 10:35:20PM +0800, Yuntao Wang wrote:
> 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.

> 
> Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
> ---
>  drivers/of/address.c | 4 ----
>  1 file changed, 4 deletions(-)
> 
> diff --git a/drivers/of/address.c b/drivers/of/address.c
> index f0f8f0dd191c..4034d798c55a 100644
> --- a/drivers/of/address.c
> +++ b/drivers/of/address.c
> @@ -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");
>  }
>  
> -- 
> 2.51.0
> 

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

* Re: [PATCH 10/10] of/address: Remove the incorrect and misleading comment
  2025-11-12 14:35 ` [PATCH 10/10] of/address: Remove the incorrect and misleading comment Yuntao Wang
  2025-11-12 16:56   ` Geert Uytterhoeven
  2025-11-12 20:07   ` Rob Herring
@ 2025-11-12 20:08   ` Rob Herring
  2 siblings, 0 replies; 26+ messages in thread
From: Rob Herring @ 2025-11-12 20:08 UTC (permalink / raw)
  To: Yuntao Wang
  Cc: Saravana Kannan, Geert Uytterhoeven, Catalin Marinas,
	AKASHI Takahiro, James Morse, Chen Zhou, Baoquan He, Zhen Lei,
	Andrew Morton, Changyuan Lyu, Alexander Graf,
	Mike Rapoport (Microsoft), devicetree, linux-kernel

On Wed, Nov 12, 2025 at 10:35:20PM +0800, Yuntao Wang wrote:
> 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.
> 
> Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
> ---
>  drivers/of/address.c | 4 ----
>  1 file changed, 4 deletions(-)

Applied, thanks!

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

* Re: [PATCH 00/10] of/fdt: Some bug fixes and cleanups
  2025-11-12 14:35 [PATCH 00/10] of/fdt: Some bug fixes and cleanups Yuntao Wang
                   ` (9 preceding siblings ...)
  2025-11-12 14:35 ` [PATCH 10/10] of/address: Remove the incorrect and misleading comment Yuntao Wang
@ 2025-11-12 20:55 ` Rob Herring
  2025-11-13 16:00   ` Yuntao Wang
  10 siblings, 1 reply; 26+ messages in thread
From: Rob Herring @ 2025-11-12 20:55 UTC (permalink / raw)
  To: Yuntao Wang
  Cc: Saravana Kannan, Geert Uytterhoeven, Catalin Marinas,
	AKASHI Takahiro, James Morse, Chen Zhou, Baoquan He, Zhen Lei,
	Andrew Morton, Changyuan Lyu, Alexander Graf,
	Mike Rapoport (Microsoft), devicetree, linux-kernel

On Wed, Nov 12, 2025 at 10:35:10PM +0800, Yuntao Wang wrote:
> 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

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.

>   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

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

* Re: [PATCH 04/10] of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding it
  2025-11-12 14:35 ` [PATCH 04/10] " Yuntao Wang
  2025-11-12 16:30   ` Geert Uytterhoeven
@ 2025-11-13 14:21   ` kernel test robot
  2025-11-13 23:46   ` kernel test robot
  2 siblings, 0 replies; 26+ messages in thread
From: kernel test robot @ 2025-11-13 14:21 UTC (permalink / raw)
  To: Yuntao Wang, Rob Herring, Saravana Kannan
  Cc: oe-kbuild-all, Geert Uytterhoeven, Catalin Marinas,
	AKASHI Takahiro, James Morse, Chen Zhou, Baoquan He, Zhen Lei,
	Andrew Morton, Linux Memory Management List, Changyuan Lyu,
	Alexander Graf, Mike Rapoport (Microsoft), devicetree,
	linux-kernel, Yuntao Wang

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/202511132259.fWi45yHp-lkp@intel.com/config)
compiler: nios2-linux-gcc (GCC) 11.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251113/202511132259.fWi45yHp-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202511132259.fWi45yHp-lkp@intel.com/

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!

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [PATCH 00/10] of/fdt: Some bug fixes and cleanups
  2025-11-12 20:55 ` [PATCH 00/10] of/fdt: Some bug fixes and cleanups Rob Herring
@ 2025-11-13 16:00   ` Yuntao Wang
  0 siblings, 0 replies; 26+ messages in thread
From: Yuntao Wang @ 2025-11-13 16:00 UTC (permalink / raw)
  To: robh
  Cc: akpm, bhe, catalin.marinas, changyuanl, chenzhou10, devicetree,
	geert+renesas, graf, james.morse, linux-kernel, rppt, saravanak,
	takahiro.akashi, thunder.leizhen, yuntao.wang

On Wed, 12 Nov 2025 14:55:51 -0600, Rob Herring <robh@kernel.org> wrote:

> On Wed, Nov 12, 2025 at 10:35:10PM +0800, Yuntao Wang wrote:
> > 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
> 
> 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.
> 
> >   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

Hi Rob,

The link to the new patch series:

https://lore.kernel.org/linux-devicetree/20251113155104.226617-1-yuntao.wang@linux.dev/t/

Thanks,
Yuntao

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

* Re: [PATCH 04/10] of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding it
  2025-11-12 14:35 ` [PATCH 04/10] " Yuntao Wang
  2025-11-12 16:30   ` Geert Uytterhoeven
  2025-11-13 14:21   ` kernel test robot
@ 2025-11-13 23:46   ` kernel test robot
  2 siblings, 0 replies; 26+ messages in thread
From: kernel test robot @ 2025-11-13 23:46 UTC (permalink / raw)
  To: Yuntao Wang, Rob Herring, Saravana Kannan
  Cc: oe-kbuild-all, Geert Uytterhoeven, Catalin Marinas,
	AKASHI Takahiro, James Morse, Chen Zhou, Baoquan He, Zhen Lei,
	Andrew Morton, Linux Memory Management List, Changyuan Lyu,
	Alexander Graf, Mike Rapoport (Microsoft), devicetree,
	linux-kernel, Yuntao Wang

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/202511140700.auD70FDr-lkp@intel.com/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/202511140700.auD70FDr-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202511140700.auD70FDr-lkp@intel.com/

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)

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

end of thread, other threads:[~2025-11-13 23:47 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-12 14:35 [PATCH 00/10] of/fdt: Some bug fixes and cleanups Yuntao Wang
2025-11-12 14:35 ` [PATCH 01/10] of/fdt: Introduce dt_root_addr_size_cells() and dt_root_addr_size_bytes() Yuntao Wang
2025-11-12 16:25   ` Geert Uytterhoeven
2025-11-12 14:35 ` [PATCH 02/10] of/reserved_mem: Use dt_root_addr_size_bytes() instead of open-coding it Yuntao Wang
2025-11-12 16:28   ` Geert Uytterhoeven
2025-11-12 14:35 ` [PATCH 03/10] " Yuntao Wang
2025-11-12 16:29   ` Geert Uytterhoeven
2025-11-12 14:35 ` [PATCH 04/10] " Yuntao Wang
2025-11-12 16:30   ` Geert Uytterhoeven
2025-11-13 14:21   ` kernel test robot
2025-11-13 23:46   ` kernel test robot
2025-11-12 14:35 ` [PATCH 05/10] of/fdt: " Yuntao Wang
2025-11-12 16:32   ` Geert Uytterhoeven
2025-11-12 14:35 ` [PATCH 06/10] of/fdt: Fix the len check in early_init_dt_check_for_elfcorehdr() Yuntao Wang
2025-11-12 14:35 ` [PATCH 07/10] of/fdt: Fix the len check in early_init_dt_check_for_usable_mem_range() Yuntao Wang
2025-11-12 16:47   ` Geert Uytterhoeven
2025-11-12 14:35 ` [PATCH 08/10] of/fdt: Use dt_root_addr_size_bytes() instead of open-coding it Yuntao Wang
2025-11-12 16:33   ` Geert Uytterhoeven
2025-11-12 14:35 ` [PATCH 09/10] of/fdt: Fix incorrect use of dt_root_addr_cells in early_init_dt_check_kho() Yuntao Wang
2025-11-12 16:54   ` Geert Uytterhoeven
2025-11-12 14:35 ` [PATCH 10/10] of/address: Remove the incorrect and misleading comment Yuntao Wang
2025-11-12 16:56   ` Geert Uytterhoeven
2025-11-12 20:07   ` Rob Herring
2025-11-12 20:08   ` Rob Herring
2025-11-12 20:55 ` [PATCH 00/10] of/fdt: Some bug fixes and cleanups Rob Herring
2025-11-13 16:00   ` Yuntao Wang

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).