Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6096880rwr; Tue, 9 May 2023 10:08:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5MjT5bmcRy/nBLG4xN+WIpDylmXLewNudFeh3DImeDm5jgRMuRQSITbeSibtV2HgaXmQ3/ X-Received: by 2002:a17:903:1247:b0:1ac:3605:97ec with SMTP id u7-20020a170903124700b001ac360597ecmr18856297plh.62.1683652103674; Tue, 09 May 2023 10:08:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683652103; cv=none; d=google.com; s=arc-20160816; b=f9qiySgMBRcvnRMcoqfgQrRMgeZ4R6o2io4tGixyyR1pCsP5EhwAA5Ax8lycnZ9BDT e8MqHBCFK0dTHC1liWFe3HN6yRVPX910vnIflW3WS59HIQjnWy2gaWBlQVmRuOXhbXxU t/yhibvXjclkJUAl7jH7DrkuRvM9/oc5jBnsOSS9uPBzvW6eAeqiybRtOZ41/ejFqaQe Po9sjvx8lDdaemLvsLzjMQ6pC2hv1k/XMiojfZ07KCkDYy0MYWpQ8Fxvkgx798evK3Ct 3uaGNKx7gOfnlE6H2v+GafOh5p56MJLZpx6tUzIMr2jCBxTmGRQbD3F0oFeKQ77OPnYY 1JSQ== 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=LbLEE4jIbrZpJwXBO7eCGOTCJ14bvYB1GBwSVBBfWTo=; b=w+I56aid/HK6cQWoqNHjSZO8e3eDvGKjLtdh2c71kw0ck0XGv69msJozqHmx9roeAo ok+GkhApDDpzqPWqX4ctPGk59sJYioGb347NFl82ga74N04ba7o2u4emeL9cDP9vtQBd 5xliWtADSFfBp91+kj80RpTGLRl8dF3cQ7gQTvlekNCNC+T+kg651XIGsWLpGxA6idNU 4kqj4HWoO5N86zYWEYTd/b0MmeWBuUysKvxMLEDwMQqC7JE1KFtdFrJjeFeQeQ1/Keal Jc+rt2ycG4vBGDfw6vqwyisxqwyQD7GXjjLxEgCIepiNb+WMrVp/YwnUhOkQFks1GJCz di7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Ema++DBy; 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 n7-20020a170903110700b001a97daf438esi1969148plh.607.2023.05.09.10.08.11; Tue, 09 May 2023 10:08:23 -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=Ema++DBy; 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 S235239AbjEIRA3 (ORCPT + 99 others); Tue, 9 May 2023 13:00:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234983AbjEIQ7T (ORCPT ); Tue, 9 May 2023 12:59:19 -0400 Received: from out-33.mta1.migadu.com (out-33.mta1.migadu.com [IPv6:2001:41d0:203:375::21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CCBB65A4 for ; Tue, 9 May 2023 09:57: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=1683651459; 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=LbLEE4jIbrZpJwXBO7eCGOTCJ14bvYB1GBwSVBBfWTo=; b=Ema++DByNMG9DiB+n947beAEq7g/Q71m9KoPfjHSpli1UraJyM8iCLpH2dVD7dGmlPZham POXN8Vj6rrwc/2I6l2HTF1fjTiqvONuKx/tIEtEaCgCG3vT3KEZtJaEGlgxgJ8gxdR7Ezw AkgHuGvv7tkdEsQ6O1IeMS4LPLXMVs0= From: Kent Overstreet To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-bcachefs@vger.kernel.org Cc: Kent Overstreet , Kent Overstreet Subject: [PATCH 29/32] lib/string_helpers: string_get_size() now returns characters wrote Date: Tue, 9 May 2023 12:56:54 -0400 Message-Id: <20230509165657.1735798-30-kent.overstreet@linux.dev> In-Reply-To: <20230509165657.1735798-1-kent.overstreet@linux.dev> References: <20230509165657.1735798-1-kent.overstreet@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 the return value of snprintf(). Signed-off-by: Kent Overstreet Signed-off-by: Kent Overstreet --- include/linux/string_helpers.h | 4 ++-- lib/string_helpers.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h index fae6beaaa2..44148f8feb 100644 --- a/include/linux/string_helpers.h +++ b/include/linux/string_helpers.h @@ -23,8 +23,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); int parse_int_array_user(const char __user *from, size_t count, int **array); diff --git a/lib/string_helpers.c b/lib/string_helpers.c index 230020a2e0..ca36ceba0e 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -32,8 +32,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" @@ -126,8 +126,8 @@ 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.40.1