
Hi Marek,
On Fri, 5 Nov 2021 at 05:19, Marek Behún kabel@kernel.org wrote:
On Thu, 4 Nov 2021 20:02:25 -0600 Simon Glass sjg@chromium.org wrote:
Hi Marek,
On Wed, 3 Nov 2021 at 17:23, Marek Behún kabel@kernel.org wrote:
From: Marek Behún marek.behun@nic.cz
Currently sysinfo_get_str() returns 0 if a string is filled in the given buffer, and otherwise gives no simple mechanism to determine actual string length.
One implementation returns -ENOSPC if buffer is not large enough.
Change the behaviour of the function to that of snprintf(): i.e. the buffer is always filled in as much as possible if the string exists, and the function returns the actual length of the string (excluding the terminating NULL-byte).
Signed-off-by: Marek Behún marek.behun@nic.cz
board/google/chromebook_coral/coral.c | 13 ++++--------- common/board_info.c | 2 +- drivers/sysinfo/gpio.c | 2 +- drivers/sysinfo/rcar3.c | 2 +- drivers/sysinfo/sandbox.c | 5 +++-- include/sysinfo.h | 16 ++++++++++++---- lib/smbios.c | 2 +- test/dm/sysinfo-gpio.c | 12 ++++++------ test/dm/sysinfo.c | 12 ++++++------ 9 files changed, 35 insertions(+), 31 deletions(-)
So how do we know if the size is too small? The string is silently truncated?
The same way as in snprintf. If the return value is >= size, then size is too small. (The return value is the length of the whole string (excluding \0 at end), not just the part that was copied to buffer.)
OK, as on the other patch for where I missed this. It is in the commit message which I did not read carefully enough, but we need it in the header file / sphinx docs too.
Regards, Simon
Marek