mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 1/2] ARM: i.MX8M: bootrom-cmd: clean up pointer casting
@ 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 ` [PATCH v2 1/2] ARM: i.MX8M: bootrom-cmd: clean up pointer casting Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2023-01-11 15:28 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-12 14:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-11 15:28 [PATCH v2 1/2] ARM: i.MX8M: bootrom-cmd: clean up pointer casting 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 ` [PATCH v2 1/2] ARM: i.MX8M: bootrom-cmd: clean up pointer casting Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox