From: Ovidiu Panait <ovpanait@gmail.com>
To: u-boot@lists.denx.de
Cc: Ovidiu Panait <ovpanait@gmail.com>,
Michal Simek <michal.simek@amd.com>,
Michal Simek <monstr@monstr.eu>
Subject: [PATCH v2 2/4] cpu: microblaze: add error handling in microblaze_cpu_get_desc()
Date: Mon, 29 Aug 2022 20:02:03 +0300 [thread overview]
Message-ID: <20220829170205.1274484-2-ovpanait@gmail.com> (raw)
In-Reply-To: <20220829170205.1274484-1-ovpanait@gmail.com>
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@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
next prev parent reply other threads:[~2022-08-29 17:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-29 17:02 [PATCH v2 1/4] microblaze: drop CONFIG_SYS_INIT_RAM_ADDR and CONFIG_SYS_INIT_RAM_SIZE Ovidiu Panait
2022-08-29 17:02 ` Ovidiu Panait [this message]
2022-08-29 17:02 ` [PATCH v2 3/4] cmd: bdinfo: introduce bdinfo_print_size() helper Ovidiu Panait
2022-08-30 1:50 ` Jason Liu
2022-08-29 17:02 ` [PATCH v2 4/4] microblaze: add arch_print_bdinfo() implementation Ovidiu Panait
2022-08-31 8:21 ` [PATCH v2 1/4] microblaze: drop CONFIG_SYS_INIT_RAM_ADDR and CONFIG_SYS_INIT_RAM_SIZE Michal Simek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220829170205.1274484-2-ovpanait@gmail.com \
--to=ovpanait@gmail.com \
--cc=michal.simek@amd.com \
--cc=monstr@monstr.eu \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).