mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH v2 1/2] ARM: i.MX8M: bootrom-cmd: clean up pointer casting
Date: Thu, 12 Jan 2023 15:55:55 +0100	[thread overview]
Message-ID: <20230112145555.GW24755@pengutronix.de> (raw)
In-Reply-To: <20230111152836.1548942-1-a.fatoum@pengutronix.de>

On Wed, Jan 11, 2023 at 04:28:36PM +0100, Ahmad Fatoum wrote:
> At first glance:
> 
> 	const u32 *rom_log_addr;
> 	kstrtoul(optarg, 0, (ulong *)&rom_log_addr) with
> 
> looks like it would conflate u32/ulong. While the code is fine,
> it is better to just use the correct types and forego the case.
> 
> While at it, let's guard against the ROM log pointer being NULL
> as well.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> v1 -> v2:
>   - new patch
> ---
>  arch/arm/mach-imx/bootrom-cmd.c | 19 ++++++++++++++-----
>  1 file changed, 14 insertions(+), 5 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/arch/arm/mach-imx/bootrom-cmd.c b/arch/arm/mach-imx/bootrom-cmd.c
> index 0238d09b169f..63197e02ae2c 100644
> --- a/arch/arm/mach-imx/bootrom-cmd.c
> +++ b/arch/arm/mach-imx/bootrom-cmd.c
> @@ -51,6 +51,9 @@ static int imx8m_bootrom_decode_log(const u32 *rom_log)
>  {
>  	int i;
>  
> +	if (!rom_log)
> +		return -ENODATA;
> +
>  	for (i = 0; i < 128; i++) {
>  		u8 event_id = FIELD_GET(ROM_EVENT_FORMAT_V1_ID, rom_log[i]);
>  		u8 event_id_idx = FIELD_GET(ROM_EVENT_FORMAT_V1_ID_IDX, rom_log[i]);
> @@ -178,18 +181,19 @@ static int imx8m_bootrom_decode_log(const u32 *rom_log)
>  
>  static int do_bootrom(int argc, char *argv[])
>  {
> -	const struct imx_scratch_space *scratch = arm_mem_scratch_get();
> -	const u32 *rom_log_addr = scratch->bootrom_log;
> +	union {
> +		const u32 *ptr;
> +		ulong addr;
> +	} rom_log = { NULL };
>  	bool log = false;
>  	int ret, opt;
>  
>  	while((opt = getopt(argc, argv, "la:")) > 0) {
>  		switch(opt) {
>  		case 'a':
> -			ret = kstrtoul(optarg, 0, (ulong *)&rom_log_addr);
> +			ret = kstrtoul(optarg, 0, &rom_log.addr);
>  			if (ret)
>  				return ret;
> -			rom_log_addr = (const u32 *)rom_log_addr;
>  		case 'l':
>  			log = true;
>  			break;
> @@ -198,8 +202,13 @@ static int do_bootrom(int argc, char *argv[])
>  		}
>  	}
>  
> +	if (!rom_log.addr) {
> +		const struct imx_scratch_space *scratch = arm_mem_scratch_get();
> +		rom_log.ptr = scratch->bootrom_log;
> +	}
> +
>  	if (log)
> -		return imx8m_bootrom_decode_log(rom_log_addr);
> +		return imx8m_bootrom_decode_log(rom_log.ptr);
>  
>  	return COMMAND_ERROR_USAGE;
>  }
> -- 
> 2.30.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



      parent reply	other threads:[~2023-01-12 14:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-11 15:28 Ahmad Fatoum
2023-01-11 15:28 ` [PATCH v2 2/2] ARM: i.MX8M: bootrom: access OCRAM directly if running in EL3 Ahmad Fatoum
2023-01-12 14:55 ` Sascha Hauer [this message]

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=20230112145555.GW24755@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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