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 3692EC433EF for ; Fri, 5 Nov 2021 16:13:03 +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 A5CDC6023B for ; Fri, 5 Nov 2021 16:13:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A5CDC6023B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.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 E0AFD8373B; Fri, 5 Nov 2021 17:12:43 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="PLngxSJa"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3049283728; Fri, 5 Nov 2021 17:12:36 +0100 (CET) Received: from mail-ua1-x92b.google.com (mail-ua1-x92b.google.com [IPv6:2607:f8b0:4864:20::92b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id AF74F83700 for ; Fri, 5 Nov 2021 17:12:31 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@google.com Received: by mail-ua1-x92b.google.com with SMTP id b3so18076121uam.1 for ; Fri, 05 Nov 2021 09:12:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=yfPzb+0PtRatBBkP1WxZLW3flVRTaDNcd2dXzlXi2TQ=; b=PLngxSJaiVluQLKbKwbTIpPzEbtkLH4qwqjL+CmkqStLkdSKLCt1w6UNbdeHwoBKcm rAdTh8XIQo8n9krnVkF4XeAI6PD750HSphkietznYWcYseILkHnGg3zdULXaq8XljaXq cgrmzhrMbAGIXWUSAyjXLEazF4Egekqdsb2sQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=yfPzb+0PtRatBBkP1WxZLW3flVRTaDNcd2dXzlXi2TQ=; b=IuDROWtsefo4ZZQqhU3R2W9/fGFqVW/uj68zNnLTfS4+OdpkAcyQVW/VNegp1MHWK+ 59qfQV2IFWSYGtNTFn7HV1oHwpWATlbz9gGKQfvtTqkUWIGnry7MRmNUcO7ufC2D+RYP p6YLhn5AY03y5QGkUE3hj9Lad++II/ABu4HiZodPJRFC4LmjiEP7QjHyesdUOU27/zBS wnwWgGL2XCPKLZAUxfe/2XPfaL4qLOh3GpGaoKITlvMW/qEgDMGrEVQaE1UQQ5IlCwlN YzDDj8c4yuS8b6EbnNejbdPlc5vwJxdlJpTwlEsV2B0vfOS6UTgHwj7Z5WRU4+D/xx5/ PsiA== X-Gm-Message-State: AOAM532Ff5oVQEveWCl5h5KeLjj0s5vHcN/kncHR7wJSB9WCmQthXotd 4LzScemxUu/JJY9ZHUHSST2r5XGCXTryWMSjt9SjoXPV9fI= X-Google-Smtp-Source: ABdhPJzLvNk1ye+tmzR9Jflw9f/7xl1SAu48hw8aHUiwrQ/di1Mjbt6D0Q1rCN4LUi4vf1R5FfYo4Q6phjeW0DrMqW0= X-Received: by 2002:a67:de88:: with SMTP id r8mr13164504vsk.15.1636128750291; Fri, 05 Nov 2021 09:12:30 -0700 (PDT) MIME-Version: 1.0 References: <20211103232332.2737-1-kabel@kernel.org> <20211103232332.2737-5-kabel@kernel.org> <20211105121916.74f24466@thinkpad> In-Reply-To: <20211105121916.74f24466@thinkpad> From: Simon Glass Date: Fri, 5 Nov 2021 10:12:17 -0600 Message-ID: Subject: Re: [PATCH v2 04/12] sysinfo: Make sysinfo_get_str() behave like snprintf() To: =?UTF-8?B?TWFyZWsgQmVow7pu?= Cc: =?UTF-8?Q?Pali_Roh=C3=A1r?= , u-boot@lists.denx.de, =?UTF-8?B?TWFyZWsgQmVow7pu?= 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 Hi Marek, On Fri, 5 Nov 2021 at 05:19, Marek Beh=C3=BAn wrote: > > On Thu, 4 Nov 2021 20:02:25 -0600 > Simon Glass wrote: > > > Hi Marek, > > > > 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(-) > > > > So how do we know if the size is too small? The string is silently trun= cated? > > 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.) 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