Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1924151rwb; Sun, 14 Aug 2022 16:24:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR68OfRX09UNR5O3RPH3/b04WRTWOEslct6T/pVTPXpXpKB8XcrUUbLjv4+4Ct5gw3ANdrz7 X-Received: by 2002:aa7:d0d8:0:b0:441:4671:49d6 with SMTP id u24-20020aa7d0d8000000b00441467149d6mr12581114edo.252.1660519466896; Sun, 14 Aug 2022 16:24:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660519466; cv=none; d=google.com; s=arc-20160816; b=IfA+79ceqG3W8EJJad052eEX0q9jYdQGgjPVSp0tSHK6zi/672Vt8a46ST9c43gA+a s29rLbhBV31xaSWdw92F+RirqfotWekw4gPccin0kxKCJlAP76skYFZPVkkziTXc9s3S uPFKA06XJRclFEOackvR6Gt67yVDaWAQZRQ4OsYRFmY91jw8ZsmoGTlscJlFrD0D31wd 6bDDv41Hc1IokL6VVZQX1BkRv9omOxsJsPZ09mitOcfP2CkKxrkoRxCnaSLQW9S0ZgMq VtjfLagTGs+FutqghviZeWjXBoZVOHMzvmtza9PN/CoThb08uMf1bpgRl1KY4cy2JPoZ nrZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KSSfD6zQrXSxaxG/WfiMiw11chh7wGoURyPeSFWijZg=; b=WpdJJH6vB08CeZzFkGMtfCZzQwcnPNW/9kwGD9QWAwJEs/fjc9pjqBxl8lrMhlUsr+ zJ3JHYAus/aZcYpfVP5T7ze32hOgiAHyr+LSpFfj9sNdlIJwPL6Xg7r4TDRGeC/JPe5F ZVkI+rCjEVHSi9ZjUZXs8AaGvToW32/8al1h/GOEtAD4hCBkgU/S1bsi+yhIcspJpfYu EPFFfW7ODo4QGdDQtG69MHRk9fzTObmdkpupwGdBtadBE7+WHVV9TdEgVDa+bgTpIr9N 5UPlDvCjpL+gxkyxv7ql4qudk5socYNix2g9hRmhWttOTFbTpx4SaLo1B3W7gTN0MssV 6NRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=XVYuMqFh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z4-20020a056402274400b0043df391fc57si7507304edd.542.2022.08.14.16.23.55; Sun, 14 Aug 2022 16:24:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=XVYuMqFh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240478AbiHNVVI (ORCPT + 99 others); Sun, 14 Aug 2022 17:21:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240370AbiHNVUs (ORCPT ); Sun, 14 Aug 2022 17:20:48 -0400 Received: from out0.migadu.com (out0.migadu.com [IPv6:2001:41d0:2:267::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20E49B7F8 for ; Sun, 14 Aug 2022 14:20:44 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1660512042; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KSSfD6zQrXSxaxG/WfiMiw11chh7wGoURyPeSFWijZg=; b=XVYuMqFhV3ebUn9qqWjlZ3npkv+smqZxybB+OB3c8W/SD/3QIOAKil8bQGZl0CIZ8Ulu2F RPaSm5ydlv58LKfYclz4YeQ9Q/WYujcKmKhFWp7CfftePiwF5BScdQv9cWWIQaw3AWB+f+ LyBtidH3codBhcQkaCM7U1jx3Se0BRE= From: Kent Overstreet To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, Kent Overstreet , Andy Shevchenko Subject: [PATCH 05/32] lib/string_helpers: string_get_size() now returns characters wrote Date: Sun, 14 Aug 2022 17:19:44 -0400 Message-Id: <20220814212011.1727798-6-kent.overstreet@linux.dev> In-Reply-To: <20220814212011.1727798-1-kent.overstreet@linux.dev> References: <20220814212011.1727798-1-kent.overstreet@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kent Overstreet printbuf now needs to know the number of characters that would have been written if the buffer was too small, like snprintf(); this changes string_get_size() to return the return value of snprintf(). Signed-off-by: Kent Overstreet Cc: Andy Shevchenko Acked-by: Andy Shevchenko --- include/linux/string_helpers.h | 4 ++-- lib/string_helpers.c | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h index c048eaec08..ae4383f0fe 100644 --- a/include/linux/string_helpers.h +++ b/include/linux/string_helpers.h @@ -19,8 +19,8 @@ enum string_size_units { STRING_UNITS_2, /* use binary powers of 2^10 */ }; -void string_get_size(u64 size, u64 blk_size, enum string_size_units units, - char *buf, int len); +int string_get_size(u64 size, u64 blk_size, enum string_size_units units, + char *buf, int len); #define UNESCAPE_SPACE BIT(0) #define UNESCAPE_OCTAL BIT(1) diff --git a/lib/string_helpers.c b/lib/string_helpers.c index b366c660e6..a48c6a1cdd 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -33,8 +33,8 @@ * at least 9 bytes and will always be zero terminated. * */ -void string_get_size(u64 size, u64 blk_size, const enum string_size_units units, - char *buf, int len) +int string_get_size(u64 size, u64 blk_size, const enum string_size_units units, + char *buf, int len) { static const char *const units_10[] = { "B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" @@ -127,8 +127,7 @@ void string_get_size(u64 size, u64 blk_size, const enum string_size_units units, else unit = units_str[units][i]; - snprintf(buf, len, "%u%s %s", (u32)size, - tmp, unit); + return snprintf(buf, len, "%u%s %s", (u32)size, tmp, unit); } EXPORT_SYMBOL(string_get_size); -- 2.36.1