Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4275581rwb; Sun, 7 Aug 2022 20:05:53 -0700 (PDT) X-Google-Smtp-Source: AA6agR4w8gzhDTwhxJQZPDJLd7Cq5eAO8HpdRbDKXsyYXslmezuHSp6wdUQ6XKr9ZidciFTW0Syd X-Received: by 2002:a05:6402:388d:b0:43b:a17b:6212 with SMTP id fd13-20020a056402388d00b0043ba17b6212mr16271744edb.51.1659927953435; Sun, 07 Aug 2022 20:05:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659927953; cv=none; d=google.com; s=arc-20160816; b=HZIpGRZk3OUo9ehYsVeTlnS4QfIix/qjtAk5WjZSlDbm4LGvDNNGUffzyqwWmzE/yO M1JjnM123ZfQ8qfBK6Rc34/atmsjMEvktj931F58enbCgJeQOHK7GTMXW0PfVlDOq0Fg yRxVdoGDmOGzhXx5kLTDwkiDKPkXABUydXdq8OeKmn+l6OW5/XjpYmX+Ll4w3nygg8qv CYWfyV/y+wwFiSuDBnH9yQYol8y8whtLQpiLaLwb4+YH6XaeRtPVfWEUPe7kG0/PuAHs sLXmTLXYrAFLXRNy8CSYs6lEfuqhYkkbFyOxUuSZlaH77MGntp3wXSnRLQMbgvkEdDyE LIOQ== 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=iecNj4WrMIq076EGFI4G8r6T8aFWcjvbvosteNe+9mQ=; b=ufhKje/Nw3kDOeD7mLNGR6sbmjqnhxq5poLTUaz2oJWmeOpNr1h3h91LQO5dkEGMPN vUHO35hmTCxFw/GIC/U6XszIrI0/sl2LBuDxZLUohgqwn7DMWToBqXc9zVGwyge+tKqO EbEfu8NpjR0rFVlgtm6tIt+z4hAmrlIokhpV0POFfL92WHUns/NWgQgjM4aSShUeBkqz ZH8EKvcQU3NfQulfKFv5tK9JSd4sShSsLj/WvjCwLWMvNC2mxNny8Xu2OfcE53rUZLra I1NtPyQYiDWMr1GRjWEsAfToM0PFheoPooDn9W7JEY41J7zRRqYLyQgegS7W91u8hLtu cYHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Ez13KjVA; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a7-20020aa7d907000000b0043d983232acsi5408190edr.483.2022.08.07.20.05.28; Sun, 07 Aug 2022 20:05:53 -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=@infradead.org header.s=casper.20170209 header.b=Ez13KjVA; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242781AbiHHClq (ORCPT + 99 others); Sun, 7 Aug 2022 22:41:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234358AbiHHCli (ORCPT ); Sun, 7 Aug 2022 22:41:38 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08A0D2195 for ; Sun, 7 Aug 2022 19:41:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=iecNj4WrMIq076EGFI4G8r6T8aFWcjvbvosteNe+9mQ=; b=Ez13KjVAlCu0nKB9Ummsx8Cb9J ZpbWKQD3ZMlfkTWkRTHdByuUqWF3IjBQ1Y/G3rzTPzh3v2frnGV2TXnl8vzGxxOrcwNjHnlDu/G7E kSfZVPrhAH7HuZTCyV+4yzgClAu/Rs95nNPmw1+DnHsli8RQArVoV/ewIQ4FARb/XMqSHrNXrQ2Fd Q8Y15fG12X4YgNdSLGgvuvSAmZAf1jBkRIGt6yKAbOt9VNPJvEaMBHrzHXKzMx2tK8OalV89wGIdh XTB7z1zEKKsv+Bi69FbZhNAINgSjXB0jcSUEAkCVX7epTYBSpy1wPpzf2F4cjWCDccxeMzC30NmHi fG8av77Q==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oKshx-00DVRX-1J; Mon, 08 Aug 2022 02:41:33 +0000 From: "Matthew Wilcox (Oracle)" To: linux-kernel@vger.kernel.org, pmladek@suse.com, Kent Overstreet Cc: Andy Shevchenko Subject: [PATCH v5 05/32] lib/string_helpers: string_get_size() now returns characters wrote Date: Mon, 8 Aug 2022 03:41:01 +0100 Message-Id: <20220808024128.3219082-6-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220808024128.3219082-1-willy@infradead.org> References: <20220808024128.3219082-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,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 the return value of snprintf(). Signed-off-by: Kent Overstreet Cc: 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 67de398944e8..52e0f1d283b9 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 7be20bcc6137..d247bf945f16 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.35.1