public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Daniel Schultz <d.schultz@phytec.de>
To: <u-boot@lists.denx.de>
Cc: Yannic Moog <y.moog@phytec.de>, Daniel Schultz <d.schultz@phytec.de>
Subject: [PATCH 3/5] board: phytec: check eeprom_data validity
Date: Fri, 19 Apr 2024 08:55:38 -0700	[thread overview]
Message-ID: <20240419155540.2447006-4-d.schultz@phytec.de> (raw)
In-Reply-To: <20240419155540.2447006-1-d.schultz@phytec.de>

From: Yannic Moog <y.moog@phytec.de>

For all of the functions that access the eeprom_data, make sure these
data are valid. Use the valid member of the phytec_eeprom_data struct.
This fixes a bug where only the API revision check guarded against
accessing rubbish. But if API revision was e.g. 6, eeprom setup failed
before, but phytec_get_imx8m_eth would still happily access the data.

Fixes: dc22188cdc8 ("board: phytec: Add common PHYTEC SoM detection")

Signed-off-by: Yannic Moog <y.moog@phytec.de>
Signed-off-by: Daniel Schultz <d.schultz@phytec.de>
---
 board/phytec/common/imx8m_som_detection.c  | 11 +++++++----
 board/phytec/common/phytec_som_detection.c | 10 +++++++---
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/board/phytec/common/imx8m_som_detection.c b/board/phytec/common/imx8m_som_detection.c
index 7571076a09e..ee34a5b9579 100644
--- a/board/phytec/common/imx8m_som_detection.c
+++ b/board/phytec/common/imx8m_som_detection.c
@@ -34,7 +34,7 @@ int __maybe_unused phytec_imx8m_detect(struct phytec_eeprom_data *data)
 		data = &eeprom_data;
 
 	/* We can not do the check for early API revisions */
-	if (data->payload.api_rev < PHYTEC_API_REV2)
+	if (!data->valid || data->payload.api_rev < PHYTEC_API_REV2)
 		return -1;
 
 	som = data->payload.data.data_api2.som_no;
@@ -75,6 +75,9 @@ u8 __maybe_unused phytec_get_imx8m_ddr_size(struct phytec_eeprom_data *data)
 	if (!data)
 		data = &eeprom_data;
 
+	if (!data->valid || data->payload.api_rev < PHYTEC_API_REV2)
+		return PHYTEC_EEPROM_INVAL;
+
 	opt = phytec_get_opt(data);
 	if (opt)
 		ddr_id = PHYTEC_GET_OPTION(opt[2]);
@@ -99,7 +102,7 @@ u8 __maybe_unused phytec_get_imx8m_spi(struct phytec_eeprom_data *data)
 	if (!data)
 		data = &eeprom_data;
 
-	if (data->payload.api_rev < PHYTEC_API_REV2)
+	if (!data->valid || data->payload.api_rev < PHYTEC_API_REV2)
 		return PHYTEC_EEPROM_INVAL;
 
 	opt = phytec_get_opt(data);
@@ -126,7 +129,7 @@ u8 __maybe_unused phytec_get_imx8m_eth(struct phytec_eeprom_data *data)
 	if (!data)
 		data = &eeprom_data;
 
-	if (data->payload.api_rev < PHYTEC_API_REV2)
+	if (!data->valid || data->payload.api_rev < PHYTEC_API_REV2)
 		return PHYTEC_EEPROM_INVAL;
 
 	opt = phytec_get_opt(data);
@@ -154,7 +157,7 @@ u8 __maybe_unused phytec_get_imx8mp_rtc(struct phytec_eeprom_data *data)
 	if (!data)
 		data = &eeprom_data;
 
-	if (data->payload.api_rev < PHYTEC_API_REV2)
+	if (!data->valid || data->payload.api_rev < PHYTEC_API_REV2)
 		return PHYTEC_EEPROM_INVAL;
 
 	opt = phytec_get_opt(data);
diff --git a/board/phytec/common/phytec_som_detection.c b/board/phytec/common/phytec_som_detection.c
index 7913764be0a..5a4cc9e8b02 100644
--- a/board/phytec/common/phytec_som_detection.c
+++ b/board/phytec/common/phytec_som_detection.c
@@ -128,7 +128,7 @@ void __maybe_unused phytec_print_som_info(struct phytec_eeprom_data *data)
 	if (!data)
 		data = &eeprom_data;
 
-	if (data->payload.api_rev < PHYTEC_API_REV2)
+	if (!data->valid || data->payload.api_rev < PHYTEC_API_REV2)
 		return;
 
 	api2 = &data->payload.data.data_api2;
@@ -190,6 +190,9 @@ char * __maybe_unused phytec_get_opt(struct phytec_eeprom_data *data)
 	if (!data)
 		data = &eeprom_data;
 
+	if (!data->valid)
+		return NULL;
+
 	if (data->payload.api_rev < PHYTEC_API_REV2)
 		opt = data->payload.data.data_api0.opt;
 	else
@@ -205,7 +208,7 @@ u8 __maybe_unused phytec_get_rev(struct phytec_eeprom_data *data)
 	if (!data)
 		data = &eeprom_data;
 
-	if (data->payload.api_rev < PHYTEC_API_REV2)
+	if (!data->valid || data->payload.api_rev < PHYTEC_API_REV2)
 		return PHYTEC_EEPROM_INVAL;
 
 	api2 = &data->payload.data.data_api2;
@@ -217,7 +220,8 @@ u8 __maybe_unused phytec_get_som_type(struct phytec_eeprom_data *data)
 {
 	if (!data)
 		data = &eeprom_data;
-	if (data->payload.api_rev < PHYTEC_API_REV2)
+
+	if (!data->valid || data->payload.api_rev < PHYTEC_API_REV2)
 		return PHYTEC_EEPROM_INVAL;
 
 	return data->payload.data.data_api2.som_type;
-- 
2.25.1


  parent reply	other threads:[~2024-04-19 16:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-19 15:55 [PATCH 0/5] Update PHYTEC SOM Detection Daniel Schultz
2024-04-19 15:55 ` [PATCH 1/5] board: phytec: common: Generic "add extension" function Daniel Schultz
2024-04-23  7:30   ` Teresa Remmet
2024-04-19 15:55 ` [PATCH 2/5] board: phytec: introduce eeprom struct member 'valid' Daniel Schultz
2024-04-23  7:26   ` Teresa Remmet
2024-04-19 15:55 ` Daniel Schultz [this message]
2024-04-23  7:27   ` [PATCH 3/5] board: phytec: check eeprom_data validity Teresa Remmet
2024-04-19 15:55 ` [PATCH 4/5] board: phytec: common: Fix eepom is empty check Daniel Schultz
2024-04-23  7:26   ` Teresa Remmet
2024-04-19 15:55 ` [PATCH 5/5] board: phytec: Add SOM detection for AM6x Daniel Schultz
2024-04-29 23:04 ` [PATCH 0/5] Update PHYTEC SOM Detection 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=20240419155540.2447006-4-d.schultz@phytec.de \
    --to=d.schultz@phytec.de \
    --cc=u-boot@lists.denx.de \
    --cc=y.moog@phytec.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