From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v2 1/2] ARM: i.MX8M: bootrom-cmd: clean up pointer casting
Date: Wed, 11 Jan 2023 16:28:36 +0100 [thread overview]
Message-ID: <20230111152836.1548942-1-a.fatoum@pengutronix.de> (raw)
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(-)
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
next reply other threads:[~2023-01-11 15:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-11 15:28 Ahmad Fatoum [this message]
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 ` [PATCH v2 1/2] ARM: i.MX8M: bootrom-cmd: clean up pointer casting Sascha Hauer
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=20230111152836.1548942-1-a.fatoum@pengutronix.de \
--to=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