From bfae2744dd136198a97b480bc0cc1814663fe33b Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Fri, 22 Apr 2022 14:50:23 -0400 Subject: [PATCH] serial: smh: Check return value of strndup strndup can fail. Check for it. Fixes: 4855b39be ("serial: smh: Implement puts for DM") Signed-off-by: Sean Anderson --- 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.39.5