All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] board: dhelectronics: Check pointer before access in dh_get_value_from_eeprom_buffer()
@ 2025-09-07  1:00 Marek Vasut
  2025-09-07  1:00 ` [PATCH 2/2] board: dhelectronics: Use isascii() before isprint() in dh_read_eeprom_id_page() Marek Vasut
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Marek Vasut @ 2025-09-07  1:00 UTC (permalink / raw)
  To: u-boot; +Cc: Marek Vasut, Christoph Niedermaier, Simon Glass, Tom Rini

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>
---
Cc: Christoph Niedermaier <cniedermaier@dh-electronics.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>
---
 board/dhelectronics/common/dh_common.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/board/dhelectronics/common/dh_common.c b/board/dhelectronics/common/dh_common.c
index 9f8e5754d8c..aeabd617374 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:
-- 
2.50.1


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

end of thread, other threads:[~2025-09-17 15:09 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-07  1:00 [PATCH 1/2] board: dhelectronics: Check pointer before access in dh_get_value_from_eeprom_buffer() Marek Vasut
2025-09-07  1:00 ` [PATCH 2/2] board: dhelectronics: Use isascii() before isprint() in dh_read_eeprom_id_page() Marek Vasut
2025-09-10 13:20   ` Christoph Niedermaier
2025-09-10 13:18 ` [PATCH 1/2] board: dhelectronics: Check pointer before access in dh_get_value_from_eeprom_buffer() Christoph Niedermaier
2025-09-17 13:47 ` Tom Rini
2025-09-17 13:54   ` Marek Vasut
2025-09-17 15:07     ` Tom Rini
2025-09-17 15:08 ` Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.