From: Michael Ferolito Date: Tue, 28 Jan 2025 03:09:45 +0000 (-0600) Subject: usb: gadget: g_dnl: Fix NULLPTR dereference when serial# is unset X-Git-Tag: v2025.04-rc3~19^2~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dcf1c627cf436191919c5a3b153d1033245b54b7;p=thirdparty%2Fu-boot.git usb: gadget: g_dnl: Fix NULLPTR dereference when serial# is unset The current behaviour of this function will dereference a null pointer if the serial# environment variable is unset. This was discovered on a board where U-Boot did not have access to the first 256MB of ram, resulting in a board crash. In the event that U-Boot has full access to memory, it will still read from address 0, which is probably not optimal. This simple check is enough to fix it Signed-off-by: Michael Ferolito Cc: Marek Vasut Cc: Heiko Schocher Cc: Kyungmin Park Reviewed-by: Heiko Schocher Reviewed-by: Mattijs Korpershoek Reviewed-by: Marek Vasut Link: https://lore.kernel.org/r/20250128030945.1219589-1-michaelsunn101@gmail.com Signed-off-by: Mattijs Korpershoek --- diff --git a/drivers/usb/gadget/g_dnl.c b/drivers/usb/gadget/g_dnl.c index 631969b3405..f2540eb6ded 100644 --- a/drivers/usb/gadget/g_dnl.c +++ b/drivers/usb/gadget/g_dnl.c @@ -207,7 +207,8 @@ void g_dnl_clear_detach(void) static int on_serialno(const char *name, const char *value, enum env_op op, int flags) { - g_dnl_set_serialnumber((char *)value); + if (value) + g_dnl_set_serialnumber((char *)value); return 0; } U_BOOT_ENV_CALLBACK(serialno, on_serialno);