devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yuntao Wang <yuntao.wang@linux.dev>
To: robh@kernel.org
Cc: akpm@linux-foundation.org, ardb@kernel.org, bhe@redhat.com,
	catalin.marinas@arm.com, changyuanl@google.com,
	devicetree@vger.kernel.org, geert+renesas@glider.be,
	geoff@infradead.org, graf@amazon.com, james.morse@arm.com,
	linux-kernel@vger.kernel.org, mark.rutland@arm.com,
	rppt@kernel.org, saravanak@google.com,
	thunder.leizhen@huawei.com, yuntao.wang@linux.dev
Subject: Re: [PATCH v2 5/7] of/fdt: Simplify the logic of early_init_dt_scan_memory()
Date: Fri, 14 Nov 2025 11:55:58 +0800	[thread overview]
Message-ID: <20251114035600.13453-1-yuntao.wang@linux.dev> (raw)
In-Reply-To: <20251113220356.GA800052-robh@kernel.org>

On Thu, 13 Nov 2025 16:03:56 -0600, Rob Herring <robh@kernel.org> wrote:

> On Thu, Nov 13, 2025 at 11:51:02PM +0800, Yuntao Wang wrote:
> > Use the existing helper functions to simplify the logic of
> > early_init_dt_scan_memory()
> > 
> > Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
> > ---
> >  drivers/of/fdt.c | 14 ++++++--------
> >  1 file changed, 6 insertions(+), 8 deletions(-)
> > 
> > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> > index 4c45a97d6652..b6b059960fc2 100644
> > --- a/drivers/of/fdt.c
> > +++ b/drivers/of/fdt.c
> > @@ -1027,7 +1027,7 @@ int __init early_init_dt_scan_memory(void)
> >  
> >  	fdt_for_each_subnode(node, fdt, 0) {
> >  		const char *type = of_get_flat_dt_prop(node, "device_type", NULL);
> > -		const __be32 *reg, *endp;
> > +		const __be32 *reg;
> >  		int l;
> >  		bool hotpluggable;
> >  
> > @@ -1038,23 +1038,21 @@ int __init early_init_dt_scan_memory(void)
> >  		if (!of_fdt_device_is_available(fdt, node))
> >  			continue;
> >  
> > -		reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l);
> > +		reg = of_fdt_get_addr_size_prop(node, "linux,usable-memory", &l);
> >  		if (reg == NULL)
> > -			reg = of_get_flat_dt_prop(node, "reg", &l);
> > +			reg = of_fdt_get_addr_size_prop(node, "reg", &l);
> >  		if (reg == NULL)
> >  			continue;
> >  
> > -		endp = reg + (l / sizeof(__be32));
> >  		hotpluggable = of_get_flat_dt_prop(node, "hotpluggable", NULL);
> >  
> > -		pr_debug("memory scan node %s, reg size %d,\n",
> > +		pr_debug("memory scan node %s, reg {addr,size} entries %d,\n",
> >  			 fdt_get_name(fdt, node, NULL), l);
> >  
> > -		while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) {
> > +		while (l-- > 0) {
> >  			u64 base, size;
> >  
> > -			base = dt_mem_next_cell(dt_root_addr_cells, &reg);
> > -			size = dt_mem_next_cell(dt_root_size_cells, &reg);
> > +			of_fdt_read_addr_size(reg, &base, &size);
> 
> This doesn't work. of_fdt_read_addr_size() needs to take an entry index 
> to read each entry.
> 
> Rob

Hi Rob,

This was entirely my mistake. I intended to pass &reg rather than reg,
just like how dt_mem_next_cell() works.

So the correct definition of of_fdt_read_addr_size() should be:

void __init of_fdt_read_addr_size(const __be32 **prop, u64 *addr, u64 *size);

And the correct usage should be:

of_fdt_read_addr_size(&reg, &base, &size);

This bug was caused by my oversight — apologies for that.

I didn’t choose an interface like `of_fdt_read_addr_size(reg, i, &base, &size)`
because in normal cases the data in prop is consumed sequentially, and I felt
there was no need to introduce an entry index parameter, which would increase
the API’s complexity.

There is another issue reported by kernel test robot:

drivers/of/fdt.c:903:31: error: incompatible pointer types passing 'phys_addr_t *' (aka 'unsigned int *') to parameter of type 'u64 *' (aka 'unsigned long long *') [-Wincompatible-pointer-types]

Given this, the problem exists regardless of which implementation we choose.

I’m considering two possible solutions:

1. Convert of_fdt_read_addr_size() into a macro.
2. Split it into two functions: of_fdt_read_addr() and of_fdt_read_size().

I’m leaning toward the second option.

What do you think? Or do you have a better approach?

Thanks,
Yuntao

  reply	other threads:[~2025-11-14  3:56 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-13 15:50 [PATCH v2 0/7] of/fdt: Some bug fixes and cleanups Yuntao Wang
2025-11-13 15:50 ` [PATCH v2 1/7] of/fdt: Consolidate duplicate code into helper functions Yuntao Wang
2025-11-13 22:38   ` Rob Herring
2025-11-14  3:09     ` Yuntao Wang
2025-11-14 14:55       ` Rob Herring
2025-11-13 15:50 ` [PATCH v2 2/7] of/fdt: Fix the len check in early_init_dt_check_for_elfcorehdr() Yuntao Wang
2025-11-13 15:51 ` [PATCH v2 3/7] of/fdt: Fix the len check in early_init_dt_check_for_usable_mem_range() Yuntao Wang
2025-11-13 18:43   ` kernel test robot
2025-11-13 19:26   ` kernel test robot
2025-11-13 15:51 ` [PATCH v2 4/7] of/fdt: Fix incorrect use of dt_root_addr_cells in early_init_dt_check_kho() Yuntao Wang
2025-11-13 15:51 ` [PATCH v2 5/7] of/fdt: Simplify the logic of early_init_dt_scan_memory() Yuntao Wang
2025-11-13 22:03   ` Rob Herring
2025-11-14  3:55     ` Yuntao Wang [this message]
2025-11-14 15:11       ` Rob Herring
2025-11-15 14:00         ` Yuntao Wang
2025-11-17 12:44         ` Geert Uytterhoeven
2025-11-13 15:51 ` [PATCH v2 6/7] of/reserved_mem: Simplify the logic of __reserved_mem_reserve_reg() Yuntao Wang
2025-11-13 19:37   ` kernel test robot
2025-11-13 15:51 ` [PATCH v2 7/7] of/reserved_mem: Simplify the logic of fdt_scan_reserved_mem_reg_nodes() Yuntao Wang
2025-11-14  8:04 ` [PATCH v2 0/7] of/fdt: Some bug fixes and cleanups Krzysztof Kozlowski
2025-11-15 14:07   ` Yuntao Wang
2025-11-17  7:02     ` Krzysztof Kozlowski

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=20251114035600.13453-1-yuntao.wang@linux.dev \
    --to=yuntao.wang@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=ardb@kernel.org \
    --cc=bhe@redhat.com \
    --cc=catalin.marinas@arm.com \
    --cc=changyuanl@google.com \
    --cc=devicetree@vger.kernel.org \
    --cc=geert+renesas@glider.be \
    --cc=geoff@infradead.org \
    --cc=graf@amazon.com \
    --cc=james.morse@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=robh@kernel.org \
    --cc=rppt@kernel.org \
    --cc=saravanak@google.com \
    --cc=thunder.leizhen@huawei.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;
as well as URLs for NNTP newsgroup(s).