From: Tom Rini <trini@konsulko.com>
To: Simon Glass <sjg@chromium.org>
Cc: u-boot@lists.denx.de, James Hilliard <james.hilliard1@gmail.com>,
Marek Vasut <marek.vasut+renesas@mailbox.org>,
Quentin Schulz <quentin.schulz@cherry.de>
Subject: Re: [PATCH 01/13] boot: Split out the first part of fit_image_load()
Date: Mon, 13 Apr 2026 14:18:53 -0600 [thread overview]
Message-ID: <20260413201853.GG41863@bill-the-cat> (raw)
In-Reply-To: <CAFLszTjKBrUu9zFHyHXmSUMCrZjLB05ri9jdSaaTBOuJndKE0g@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2235 bytes --]
On Sat, Apr 11, 2026 at 07:03:35AM -0600, Simon Glass wrote:
> Hi Tom,
>
> On Wed, 8 Apr 2026 at 10:25, Tom Rini <trini@konsulko.com> wrote:
> >
> > On Wed, Mar 25, 2026 at 10:54:10AM -0600, Simon Glass wrote:
> >
> > > This function is over 250 lines long. Split out the image-selection
> > > part into a new select_image() function which handles format checking,
> > > configuration selection and image-node lookup.
> > >
> > > Take care to only call fit_get_name() when a valid node is found, since
> > > libfdt does not handle negative offsets gracefully.
> > >
> > > Signed-off-by: Simon Glass <sjg@chromium.org>
> >
> > Function length isn't a problem in and of itself, especially when we
> > aren't pulling out some 4 or 5 level deep nested logic to improve
> > readability.
>
> In my view the current code is very hard to maintain and change. I
> know this because I have tried to do it:
>
> 1. By my count, fit_image_load() declares 20 locals. Even without deep
> nesting, tracking which variables are live at which point in a
> function of ~270 lines is extremely hard (see [1] for someone else
> that had this problem). Just to take one example, pulling
> select_image() out makes it explicit that cfg_noffset (for example) is
> only relevant during image selection and doesn't leak into the
> load/decompress path.
>
> 2. The function has distinct phases: format checking, configuration
> selection, hash verification, and image-node lookup. So we have 'find
> what to load' vs. 'load it'. These are much easier to understand with
> clean function boundaries, rather than an arbitrary split at a line
> count.
>
> 3. Reviewability - when someone adds a feature to the loading path,
> they currently have to read past 90 lines of selection logic to find
> where their change fits. Smaller functions with clear contracts make
> it easier to see where new code belongs.
Or, splitting things up makes it harder to review because now what
you're reading through is over *there* instead of the next line. I find
myself having to "un-inline" function calls sometimes because we've
thrown around so many abstractions. So I stand by what I said in the
cover letter.
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2026-04-13 20:19 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-25 16:54 [PATCH 00/13] boot: Make fit_image_load() easier to maintain Simon Glass
2026-03-25 16:54 ` [PATCH 01/13] boot: Split out the first part of fit_image_load() Simon Glass
2026-04-08 16:25 ` Tom Rini
2026-04-11 13:03 ` Simon Glass
2026-04-13 20:18 ` Tom Rini [this message]
2026-04-16 17:43 ` Simon Glass
2026-03-25 16:54 ` [PATCH 02/13] boot: Move call to fit_image_select() and rename it Simon Glass
2026-04-08 16:25 ` Tom Rini
2026-03-25 16:54 ` [PATCH 03/13] boot: Tidy up setting of the OS arch on host builds Simon Glass
2026-04-08 16:25 ` Tom Rini
2026-03-25 16:54 ` [PATCH 04/13] boot: Move type and OS checking into a new function Simon Glass
2026-04-08 16:26 ` Tom Rini
2026-03-25 16:54 ` [PATCH 05/13] boot: Move handling of the load_op into a separate function Simon Glass
2026-04-08 16:26 ` Tom Rini
2026-03-25 16:54 ` [PATCH 06/13] boot: Move obtaining data from a FIT image into a function Simon Glass
2026-03-25 16:54 ` [PATCH 07/13] boot: Check the image is allowed before setting os.arch Simon Glass
2026-03-25 16:54 ` [PATCH 08/13] boot: Move the architecture check into check_allowed() Simon Glass
2026-03-25 16:54 ` [PATCH 09/13] boot: Move image-decompression into a separate function Simon Glass
2026-03-25 16:54 ` [PATCH 10/13] boot: Move decomp_image() into handle_load_op() Simon Glass
2026-03-25 16:54 ` [PATCH 11/13] boot: Move setting the OS arch into check_allowed() Simon Glass
2026-03-25 16:54 ` [PATCH 12/13] boot: Drop unnecessary data variable Simon Glass
2026-03-25 16:54 ` [PATCH 13/13] boot: Tidy local variables in fit_image_load() Simon Glass
2026-04-08 16:26 ` [PATCH 00/13] boot: Make fit_image_load() easier to maintain Tom Rini
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=20260413201853.GG41863@bill-the-cat \
--to=trini@konsulko.com \
--cc=james.hilliard1@gmail.com \
--cc=marek.vasut+renesas@mailbox.org \
--cc=quentin.schulz@cherry.de \
--cc=sjg@chromium.org \
--cc=u-boot@lists.denx.de \
/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