From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ECBD8C433F5 for ; Fri, 5 Nov 2021 11:19:30 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6193F6124A for ; Fri, 5 Nov 2021 11:19:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6193F6124A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1D9648365C; Fri, 5 Nov 2021 12:19:28 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="sOuHwhPE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 97A0F834CF; Fri, 5 Nov 2021 12:19:25 +0100 (CET) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 21D3C83700 for ; Fri, 5 Nov 2021 12:19:22 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kabel@kernel.org Received: by mail.kernel.org (Postfix) with ESMTPSA id 8AA586124A; Fri, 5 Nov 2021 11:19:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636111160; bh=Talln2/vgEUDbM0+8AdmLFU0qKfu8NVtuG1Y/a20VHQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=sOuHwhPEPyCsuhTHQ47A8t8/A4h/gO88C7vR4+EfCK54mvOMmtxKs5aqL12NPx6F7 jgouiOpZCH6Z4tTytjNKHww2vqbf5i2i8o+ffsyTItflQr5cq+xS9osndMQAuclzeJ i1rNsVdtxKSESnzPwA5XqmwLxau7qbcOFq/wamTG6HkpQ2YI0TMAjVIPHEkM3xTghM al0Z7FZGQB28toHpS8d4InpUT2/Yt3FFRs3kvuts4T/6u24q7ANqRQ6T3T0CJvA1YL FPsxxumwo0tqI+0ZFlUof+LqMl3T7cr1H6CSbbyzaVyes8Kdozk+rBmUqKhglsSlTz soZjXJaOeT2xw== Date: Fri, 5 Nov 2021 12:19:16 +0100 From: Marek =?UTF-8?B?QmVow7pu?= To: Simon Glass Cc: Pali =?UTF-8?B?Um9ow6Fy?= , u-boot@lists.denx.de, Marek =?UTF-8?B?QmVow7pu?= Subject: Re: [PATCH v2 04/12] sysinfo: Make sysinfo_get_str() behave like snprintf() Message-ID: <20211105121916.74f24466@thinkpad> In-Reply-To: References: <20211103232332.2737-1-kabel@kernel.org> <20211103232332.2737-5-kabel@kernel.org> X-Mailer: Claws Mail 3.18.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean On Thu, 4 Nov 2021 20:02:25 -0600 Simon Glass wrote: > Hi Marek, >=20 > On Wed, 3 Nov 2021 at 17:23, Marek Beh=C3=BAn wrote: > > > > From: Marek Beh=C3=BAn > > > > 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=C3=BAn > > --- > > 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(-) =20 >=20 > So how do we know if the size is too small? The string is silently trunca= ted? The same way as in snprintf. If the return value is >=3D 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.) Marek