public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Marek Vasut <marek.vasut@mailbox.org>
Cc: Marek Vasut <marek.vasut+renesas@mailbox.org>,
	u-boot@lists.denx.de, Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>,
	Simon Glass <sjg@chromium.org>, Tom Rini <trini@konsulko.com>
Subject: Re: [PATCH v2 2/4] boot: fdt: Clean up env_get_bootm_size()
Date: Wed, 20 Mar 2024 23:00:15 +0200	[thread overview]
Message-ID: <20240320210015.GA2539@pendragon.ideasonboard.com> (raw)
In-Reply-To: <b13328fd-03ed-49e0-90b2-0f0697e8c415@mailbox.org>

On Wed, Mar 20, 2024 at 09:52:34PM +0100, Marek Vasut wrote:
> On 3/18/24 5:18 PM, Laurent Pinchart wrote:
> 
> >> @@ -142,7 +140,7 @@ phys_size_t env_get_bootm_size(void)
> >>   
> >>   	s = env_get("bootm_low");
> >>   	if (s)
> >> -		tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
> >> +		tmp = simple_strtoull(s, NULL, 16);
> >>   	else
> >>   		tmp = start;
> >>   
> > 
> > Maybe you could even drop the tmp variable completely by writing this
> > 
> > 	if (s)
> > 		size -= simple_strtoull(s, NULL, 16) - start;
> > 
> > 	return size;
> > 
> > I've never liked variables named tmp :-)
> 
> No, let's not do this. With this FDT part, the code should be verbose 
> and as easy to understand at first glance as possible, no subtraction 
> assignments and other shenanigans please.

How about this ?

	s = env_get("bootm_low");
	if (s) {
		phys_addr_t low_addr = simple_strtoull(s, NULL, 16);
                size -= low_addr - start;
	}

	return size;

If you're going for readability, that's clearer than

	return size - (tmp - start);

and it also interestingly points out that tmp/low_addr should be a
phys_addr_t, not a phys_size_t.

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2024-03-20 21:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-18 15:00 [PATCH v2 1/4] boot: fdt: Change type of env_get_bootm_low() to phys_addr_t Marek Vasut
2024-03-18 15:00 ` [PATCH v2 2/4] boot: fdt: Clean up env_get_bootm_size() Marek Vasut
2024-03-18 16:18   ` Laurent Pinchart
2024-03-20 20:52     ` Marek Vasut
2024-03-20 21:00       ` Laurent Pinchart [this message]
2024-03-26 22:19         ` Marek Vasut
2024-03-18 15:00 ` [PATCH v2 3/4] boot: fdt: Drop lmb_alloc*() typecasts Marek Vasut
2024-03-18 16:20   ` Laurent Pinchart
2024-03-18 15:00 ` [PATCH v2 4/4] boot: fdt: Move usable variable below updated comment Marek Vasut

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=20240320210015.GA2539@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=marek.vasut+renesas@mailbox.org \
    --cc=marek.vasut@mailbox.org \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.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