Skip to contentSkip to conversation

spl: NULL check variable before dereference

PATCH In review Andrew Goodbody 2 participants 2 messages Jul 18, 2025 – Jul 29, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spl: NULL check variable before dereference

In boot_from_devices the variable loader is not NULL checked after assignment and before first use but later code does check it for NULL. Add a NULL check before first use.

This issue was found by Smatch.

---
 common/spl/spl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/spl/spl.c +1 -1
index d8e26605d20..ed443c645a7 100644
@@ -634,7 +634,7 @@ static int boot_from_devices(struct spl_image_info *spl_image,
 		if (CONFIG_IS_ENABLED(SHOW_ERRORS))
 			ret = -ENXIO;
 		for (loader = drv; loader != drv + n_ents; loader++) {
-			if (bootdev != loader->boot_device)
+			if (loader && bootdev != loader->boot_device)
 				continue;
 			if (!CONFIG_IS_ENABLED(SILENT_CONSOLE)) {
 				if (loader)

---
base-commit: 0f83825802d8938fb584c12f115bde900efe71c1
change-id: 20250718-spl_loader-e93a2d246b8e

Best regards,

Signature · 1 line
Andrew Goodbody <[email protected]>
#1 lore raw
Quoted 8 lines · Andrew Goodbody

In boot_from_devices the variable loader is not NULL checked after assignment and before first use but later code does check it for NULL. Add a NULL check before first use.

This issue was found by Smatch.

[...]

Applied to u-boot/master, thanks!

[1/1] spl: NULL check variable before dereference

      commit: ae409a84e7bffb0c5a0d420d72806ac7b854f619
Signature · 1 line
Tom