[PATCH v2 2/4] cpu: microblaze: add error handling in microblaze_cpu_get_desc()

Ovidiu Panait ovpanait at gmail.com
Mon Aug 29 19:02:03 CEST 2022


Check snprintf() return value for errors.

Make microblaze_cpu_get_desc() directly return snprintf() error code if
ret < 0. Otherwise, if the return value is greater than or equal to size,
the resulting string is truncated, so return -ENOSPC.

Fixes: 816226d27e ("cpu: add CPU driver for microblaze")
Signed-off-by: Ovidiu Panait <ovpanait at gmail.com>
---

Changes in v2:
New patch.

 drivers/cpu/microblaze_cpu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/cpu/microblaze_cpu.c b/drivers/cpu/microblaze_cpu.c
index 969a1047e5..b9d0792822 100644
--- a/drivers/cpu/microblaze_cpu.c
+++ b/drivers/cpu/microblaze_cpu.c
@@ -97,8 +97,10 @@ static int microblaze_cpu_get_desc(const struct udevice *dev, char *buf,
 	ret = snprintf(buf, size,
 		       "MicroBlaze @ %uMHz, Rev: %s, FPGA family: %s",
 		       cpu_freq_mhz, cpu_ver, fpga_family);
+	if (ret < 0)
+		return ret;
 
-	return 0;
+	return (ret >= size) ? -ENOSPC : 0;
 }
 
 static int microblaze_cpu_get_info(const struct udevice *dev,
-- 
2.25.1



More information about the U-Boot mailing list