Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2436134iog; Sun, 19 Jun 2022 18:00:39 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vmJwiKJplKoICdazHRirZAHea9vjaJnQad1ZKpod3Zcc1EOklwCRhMO562yXCdJRowsjS2 X-Received: by 2002:a17:902:d4c4:b0:16a:2a8c:c4aa with SMTP id o4-20020a170902d4c400b0016a2a8cc4aamr809469plg.138.1655686839279; Sun, 19 Jun 2022 18:00:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655686839; cv=none; d=google.com; s=arc-20160816; b=bNdzysCuTChu5uM/3EDI9KHC703Nx2GiItDA6eo6OkbY03XhKLpOvI1cAmrOBwOqA8 z6rSoVDygg6EqNvgsaDeiZCxTYAGqwV18ZSPknEE1yhtzpeGLfbKezNfkfVYC41bGZYF wUoP5Zx09UqSQua3SDSbM8q7pBA0/K3OIvRJL2K99M7Nr0UfJer4s2ycF19VCK7I/Fgx i2nAfFmWLDyISFDasqzkO4INivJWQPMLFRS3Yz+n7IqX6paTli7i7VoYWcUdPFd3upe2 qM+KzB1Ld3oSWmfv72rMqABiGxsJ0nW59grrJBUcfYVfmCMD78SDy9x2senvtRpndrXg hm0A== 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=mEyqeuvyYVFCq68f4Sk4QZALU7t6VA5DEezL7DQis8Y=; b=DfObA7haWmN3rS5ZCrSkc3twgRFkOQkx/y8tzLdrYaEH++u2b92xTVacponLbhLOQg fbf4RqAjheq5PLW/GqGziA0a7sPq9haOBg6sTcAB53dTlbP/Ts7XfQqWiM0dYOucdnJd 4lRHZWhmD/dqJlUHL7cu7Ek9EHXyB8EhouylQ84kNiezQ/3q/YPQzldUH5qdNxRcUObm yfztzVaQSp1424Q5mCzzUxySrJB+MLKe/m/G8Bt1JYDz2UiKq1NAwynq7+NK7HkvmABp OQo86AzTd25Q+22zADdAZOfdVgQWtpS9IXHXD/Tbexo2pFa3EfW+VgsSL3dLexkbv5Fl ACqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=fLu3mcba; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 19-20020a630213000000b003fcbc8b5e7dsi13004456pgc.811.2022.06.19.18.00.16; Sun, 19 Jun 2022 18:00:39 -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=@gmail.com header.s=20210112 header.b=fLu3mcba; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237783AbiFTAnJ (ORCPT + 99 others); Sun, 19 Jun 2022 20:43:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237661AbiFTAnG (ORCPT ); Sun, 19 Jun 2022 20:43:06 -0400 Received: from mail-qv1-xf33.google.com (mail-qv1-xf33.google.com [IPv6:2607:f8b0:4864:20::f33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F41331C for ; Sun, 19 Jun 2022 17:42:50 -0700 (PDT) Received: by mail-qv1-xf33.google.com with SMTP id n15so10001087qvh.12 for ; Sun, 19 Jun 2022 17:42:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mEyqeuvyYVFCq68f4Sk4QZALU7t6VA5DEezL7DQis8Y=; b=fLu3mcbah3LeFFcLd6Sx4ixRcKu0bTfXOqe3wbxf8BJ/DFjC9wL0kNwb/EUtHx+yFz 8ppi9jdAqVGLub6K7TW0N1Rw5me8QfiKIL50CH8ksgTyNpisxLe4Q/4nO2shsPeItLEw /Cr7czGYPiY9moaX2Rc+i/wFJT9AsM05eEQrpNPzBi8ZRTNFaYrgX3v2HIu/HlJ4JpU0 uYU/mgQmWRG73TeXu6m04lU1h8RaMkVD9JobbgM8IkCBpjakHTvS1J8xWo3NglcCQeM3 bdjGN0Zxo4FCJ5RnoRqUif+F4XMSg5aVyUViwoU34GrE5kWhyORUvLbgup9Vw3TrAkuG Vs8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mEyqeuvyYVFCq68f4Sk4QZALU7t6VA5DEezL7DQis8Y=; b=IyH4VP5Z23Kedf/MF0TrGYS/nul7dACcy/XyNb4Ns47VvfkDESCyFHJ4/3MnlWxuoi G3PA4+QBT+pwltIPKOXlD8RCrmBzR0X18jdyOSO8anT6PygiC9rtF6/rKfsTg7Izuh47 eWoAuunybfU7ztiDJ4oKnN7k4ir2hQ7fFRnGTNKOet5IIwmH8781mNOFAv4NkbywEoac fWXgak+tBP8LGF86yFaVUNM6gj+u0JFHhpkn5POBoeOtNvt/cAdDhfvOeqdtGulUN+Mh chz4234OmP45sdwTWXHhxVUoFvSeSPqGzJqHSSSXwHMUlCXuy31uSgyW4TGc/0CT0MzJ 66Qg== X-Gm-Message-State: AJIora9zDXDRirpRXpNdz3zfRW4j8xsLVBhLdpkisqbOWf/1AUhQLzNw FgFlEmyVVzCI2ccYzxMPCYPi0yrrDynikX4= X-Received: by 2002:a05:6214:d05:b0:464:6293:be35 with SMTP id 5-20020a0562140d0500b004646293be35mr17200317qvh.120.1655685767967; Sun, 19 Jun 2022 17:42:47 -0700 (PDT) Received: from localhost (c-73-219-103-14.hsd1.vt.comcast.net. [73.219.103.14]) by smtp.gmail.com with ESMTPSA id a2-20020ac86102000000b00307c9b5e087sm7097089qtm.3.2022.06.19.17.42.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jun 2022 17:42:46 -0700 (PDT) From: Kent Overstreet To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, pmladek@suse.com Cc: Kent Overstreet , rostedt@goodmis.org, enozhatsky@chromium.org, linux@rasmusvillemoes.dk, willy@infradead.org Subject: [PATCH v4 06/34] lib/string_helpers: string_get_size() now returns characters wrote Date: Sun, 19 Jun 2022 20:42:05 -0400 Message-Id: <20220620004233.3805-7-kent.overstreet@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220620004233.3805-1-kent.overstreet@gmail.com> References: <20220620004233.3805-1-kent.overstreet@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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 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 --- 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 67de398944..52e0f1d283 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 167c31f377..c1c8d4dfc9 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