summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Vasut <marek.vasut@mailbox.org>2025-09-07 03:00:46 +0200
committerTom Rini <trini@konsulko.com>2025-09-17 09:06:37 -0600
commit5634cf1afcf17fda0136693f02a843aa6b938b2b (patch)
tree0d17b1c2504c50246009f5667b8a9d439079d9f0
parenteea731b50c6155b9ec0ccd039590b9cefdafd024 (diff)
board: dhelectronics: Check pointer before access in dh_get_value_from_eeprom_buffer()
The eip pointer in dh_get_value_from_eeprom_buffer() might be NULL. The current NULL pointer check happens too late, after the eip was accessed in variable assignment. Reorder the two, so the NULL pointer check happens first, and any access second, otherwise the access may trigger a hang or other undefined behavior. Signed-off-by: Marek Vasut <marek.vasut@mailbox.org> Reviewed-by: Christoph Niedermaier <cniedermaier@dh-electronics.com>
-rw-r--r--board/dhelectronics/common/dh_common.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/board/dhelectronics/common/dh_common.c b/board/dhelectronics/common/dh_common.c
index 8c052c45007..d3a3f0ff11f 100644
--- a/board/dhelectronics/common/dh_common.c
+++ b/board/dhelectronics/common/dh_common.c
@@ -131,14 +131,17 @@ int dh_read_eeprom_id_page(u8 *eeprom_buffer, const char *alias)
int dh_get_value_from_eeprom_buffer(enum eip_request_values request, u8 *data, int data_len,
struct eeprom_id_page *eip)
{
- const char fin_chr = (eip->pl.item_prefix & DH_ITEM_PREFIX_FIN_BIT) ?
- DH_ITEM_PREFIX_FIN_FLASHED_CHR : DH_ITEM_PREFIX_FIN_HALF_CHR;
- const u8 soc_coded = eip->pl.item_prefix & 0xf;
+ char fin_chr;
+ u8 soc_coded;
char soc_chr;
if (!eip)
return -EINVAL;
+ fin_chr = (eip->pl.item_prefix & DH_ITEM_PREFIX_FIN_BIT) ?
+ DH_ITEM_PREFIX_FIN_FLASHED_CHR : DH_ITEM_PREFIX_FIN_HALF_CHR;
+ soc_coded = eip->pl.item_prefix & 0xf;
+
/* Copy requested data */
switch (request) {
case DH_MAC0: