From: Yuntao Wang <yuntao.wang@linux.dev>
To: geert@linux-m68k.org
Cc: krzk@kernel.org, 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,
robh@kernel.org, rppt@kernel.org, saravanak@google.com,
thunder.leizhen@huawei.com, yuntao.wang@linux.dev
Subject: Re: [PATCH v3 1/8] of/fdt: Consolidate duplicate code into helper functions
Date: Mon, 17 Nov 2025 21:32:23 +0800 [thread overview]
Message-ID: <20251117133223.11242-1-yuntao.wang@linux.dev> (raw)
In-Reply-To: <CAMuHMdXYcwK5vyuqV5sDXni4zBJZptDtEZb=coz-LwuNm+OKsA@mail.gmail.com>
On Mon, 17 Nov 2025 13:34:20 +0100, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> Hi Yuntao,
>
> On Mon, 17 Nov 2025 at 12:57, Yuntao Wang <yuntao.wang@linux.dev> wrote:
> > On Mon, 17 Nov 2025 08:01:59 +0100, Krzysztof Kozlowski <krzk@kernel.org> wrote:
> > > On Sat, Nov 15, 2025 at 09:47:46PM +0800, Yuntao Wang wrote:
> > > > Currently, there are many pieces of nearly identical code scattered across
> > > > different places. Consolidate the duplicate code into helper functions to
> > > > improve maintainability and reduce the likelihood of errors.
> > >
> > > Not much improved. Please go to previous version and read the comments.
> > >
> > > Best regards,
> > > Krzysztof
> >
> > Hi Krzysztof,
> >
> > scripts/checkpatch.pl indeed still reports some warnings. I noticed them,
> > but I intentionally didn't fix them.
> >
> > Below is a list of all the warnings, along with my reasons for leaving
> > them unaddressed.
> >
> > 1. WARNING: Missing a blank line after declarations
> > #60: FILE: drivers/of/fdt.c:663:
> > + int entry_cells = dt_root_addr_cells + dt_root_size_cells;
> > + prop += entry_cells * entry_index;
> >
> > The function that triggers this warning is:
> >
> > void __init of_flat_dt_read_addr_size(const __be32 *prop, int entry_index,
> > u64 *addr, u64 *size)
> > {
> > int entry_cells = dt_root_addr_cells + dt_root_size_cells;
> > prop += entry_cells * entry_index;
> >
> > *addr = dt_mem_next_cell(dt_root_addr_cells, &prop);
> > *size = dt_mem_next_cell(dt_root_size_cells, &prop);
> > }
> >
> > The warning suggests adding a blank line before
> >
> > prop += entry_cells * entry_index;
> >
> > I didn't add it because, logically,
> >
> > int entry_cells = dt_root_addr_cells + dt_root_size_cells;
> > prop += entry_cells * entry_index;
> >
> > forms a single block, just like
> >
> > *addr = dt_mem_next_cell(dt_root_addr_cells, &prop);
> > *size = dt_mem_next_cell(dt_root_size_cells, &prop);
> >
> > I think the code is more readable without the blank line.
> >
> > In fact, I initially combined these two lines
> >
> > int entry_cells = dt_root_addr_cells + dt_root_size_cells;
> > prop += entry_cells * entry_index;
> >
> > into a single line:
> >
> > prop += (dt_root_addr_cells + dt_root_size_cells) * entry_index;
> >
> > I added the entry_cells local variable specifically to improve readability.
>
> What about:
>
> void __init of_flat_dt_read_addr_size(const __be32 *prop, int entry_index,
> u64 *addr, u64 *size)
> {
> int entry_cells = dt_root_addr_cells + dt_root_size_cells;
>
> prop += entry_cells * entry_index;
> *addr = dt_mem_next_cell(dt_root_addr_cells, &prop);
> *size = dt_mem_next_cell(dt_root_size_cells, &prop);
> }
>
> ?
>
> 1. entry_cells is an intermediate variable,
> 2. prop is prepared just before its use.
Hi Geert,
Yes, if this warning really needs to be fixed, that's exactly how it should be done.
Thanks,
Yuntao
>
> 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
next prev parent reply other threads:[~2025-11-17 13:32 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-15 13:47 [PATCH v3 0/8] of/fdt: Some bug fixes and cleanups Yuntao Wang
2025-11-15 13:47 ` [PATCH v3 1/8] of/fdt: Consolidate duplicate code into helper functions Yuntao Wang
2025-11-17 7:01 ` Krzysztof Kozlowski
2025-11-17 11:56 ` Yuntao Wang
2025-11-17 12:34 ` Geert Uytterhoeven
2025-11-17 13:32 ` Yuntao Wang [this message]
2025-11-15 13:47 ` [PATCH v3 2/8] of/fdt: Fix the len check in early_init_dt_check_for_elfcorehdr() Yuntao Wang
2025-11-15 13:47 ` [PATCH v3 3/8] of/fdt: Fix the len check in early_init_dt_check_for_usable_mem_range() Yuntao Wang
2025-11-15 13:47 ` [PATCH v3 4/8] of/fdt: Fix incorrect use of dt_root_addr_cells in early_init_dt_check_kho() Yuntao Wang
2025-11-15 13:47 ` [PATCH v3 5/8] of/fdt: Simplify the logic of early_init_dt_scan_memory() Yuntao Wang
2025-11-15 13:47 ` [PATCH v3 6/8] of/reserved_mem: Simplify the logic of __reserved_mem_reserve_reg() Yuntao Wang
2025-11-15 13:47 ` [PATCH v3 7/8] of/reserved_mem: Simplify the logic of fdt_scan_reserved_mem_reg_nodes() Yuntao Wang
2025-11-15 13:47 ` [PATCH v3 8/8] of/reserved_mem: Simplify the logic of __reserved_mem_alloc_size() Yuntao Wang
2025-11-20 14:32 ` [PATCH v3 0/8] of/fdt: Some bug fixes and cleanups Rob Herring
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=20251117133223.11242-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=geert@linux-m68k.org \
--cc=geoff@infradead.org \
--cc=graf@amazon.com \
--cc=james.morse@arm.com \
--cc=krzk@kernel.org \
--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).