Skip to content

Commit

Permalink
board: phytec: check eeprom_data validity
Browse files Browse the repository at this point in the history
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: dc22188 ("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>
Reviewed-by: Teresa Remmet <t.remmet@phytec.de>
  • Loading branch information
ymoog authored and trini committed Apr 29, 2024
1 parent 8fe6e9a commit 1e5de69
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
11 changes: 7 additions & 4 deletions board/phytec/common/imx8m_som_detection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 7 additions & 3 deletions board/phytec/common/phytec_som_detection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 1e5de69

Please sign in to comment.