From patchwork Mon Jun 20 00:42:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 12886897 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB4DDCCA47A for ; Mon, 20 Jun 2022 00:42:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 49EFE6B007D; Sun, 19 Jun 2022 20:42:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 44D9B6B007E; Sun, 19 Jun 2022 20:42:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C7156B0080; Sun, 19 Jun 2022 20:42:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 1E3D46B007D for ; Sun, 19 Jun 2022 20:42:49 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id EDF8D80206 for ; Mon, 20 Jun 2022 00:42:48 +0000 (UTC) X-FDA: 79596764016.17.AB115C0 Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) by imf15.hostedemail.com (Postfix) with ESMTP id 9DE7DA0016 for ; Mon, 20 Jun 2022 00:42:48 +0000 (UTC) Received: by mail-qv1-f52.google.com with SMTP id cu16so13426119qvb.7 for ; Sun, 19 Jun 2022 17:42:48 -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=06BnKCXlbAAvDSJgeimDB1EJfZVAaI3J9Z4uzAWD0CJ3q81VK+Jt9FGhpXHIicSy9p FHhx1hByxsiZ+R4IIL+kbRpinWLJyWy8jfzyuREj7boXkmQh6WLsmnNMjTemq6c+6GFM qzkuyxIV9ERGPuqWYop2Jq9XQRyCdFZrTJeaEoRRijKu6SmBDk7B3Bosj9vx4uJwPLHw BaJeY5+ckoh5mWxJMOFlJjZlVtYOCSbHedWgt+Ph/NKBk9d9JDpGuM8Tht7HvpHgaadR T0EZGjfQccKqVxVxOM4E62w5rGdCv2Dq3xnzQNdeqR21nhSQYDwOy0WsOUey9tzkyUqy UttQ== X-Gm-Message-State: AJIora/H3CsVI788w81bmlMxSVG2UUMa6cZg7xeQP7pbAh07dU6daMMv CIaHEVRucVX9ueIXwIiDUA== X-Google-Smtp-Source: AGRyM1vqcEN8zqRw3lIFKIxZcvzXrdHxzPNSGUo0ecIByl4eOVuaZ3nH1CAHTH2mUn4bKReF7j7P5A== 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655685768; a=rsa-sha256; cv=none; b=7RNOMdUQ+amz/Cccz/eIMfYZ+lHG5ZrKUXWJftoZnNXxXwZMjY1Bsqv6RNWjpUvJcKrb6w 376hVLLjinpTUSStKJXnVoTbW0kHuhLzy5mLXS36V7rzFkC8CtzUmS9ZrPT8xjJafJFDfu dTFX4juoX1bvbtDpR3N7N6DcDsDqqQE= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=fLu3mcba; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf15.hostedemail.com: domain of kent.overstreet@gmail.com designates 209.85.219.52 as permitted sender) smtp.mailfrom=kent.overstreet@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655685768; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mEyqeuvyYVFCq68f4Sk4QZALU7t6VA5DEezL7DQis8Y=; b=siO4yc5R5iKJddMrkxa972ktjHOC/B1nt4VhmmVwQcXBuAKnxIEv1zYCKgjyd5RMuBP09B KgqVrHGh6RH6n+7oKIfoLDqmxNhz+IsH4bXKlPRMuAvFBZ+cQCHNbRM1Rq2Y3BPSF5Njr4 qiTvmpAewrz1WaQnU/zDFKlAr0rkqsQ= Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=fLu3mcba; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf15.hostedemail.com: domain of kent.overstreet@gmail.com designates 209.85.219.52 as permitted sender) smtp.mailfrom=kent.overstreet@gmail.com X-Rspam-User: X-Stat-Signature: cfzsux1dxb56ca77gn8qyimuoh3drmga X-Rspamd-Queue-Id: 9DE7DA0016 X-Rspamd-Server: rspam08 X-HE-Tag: 1655685768-121505 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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);