[PATCH] serial: smh: Check return value of strndup
Sean Anderson
sean.anderson at seco.com
Fri Apr 22 20:50:23 CEST 2022
strndup can fail. Check for it.
Fixes: 4855b39be ("serial: smh: Implement puts for DM")
Signed-off-by: Sean Anderson <sean.anderson at seco.com>
---
drivers/serial/serial_semihosting.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/serial/serial_semihosting.c b/drivers/serial/serial_semihosting.c
index 4328b3dac5..2561414e40 100644
--- a/drivers/serial/serial_semihosting.c
+++ b/drivers/serial/serial_semihosting.c
@@ -54,6 +54,9 @@ static ssize_t smh_serial_puts(struct udevice *dev, const char *s, size_t len)
}
buf = strndup(s, len);
+ if (!buf)
+ return -ENOMEM;
+
smh_puts(buf);
free(buf);
return len;
--
2.35.1.1320.gc452695387.dirty
More information about the U-Boot
mailing list