From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/3] lib: string_get_size: Remove redundant prefixes
Date: Fri, 12 Dec 2014 15:43:46 +0100 [thread overview]
Message-ID: <1418395428-25980-1-git-send-email-linux@rasmusvillemoes.dk> (raw)
While 3c9f3681d0b4 says that Z and Y are included in preparation for
128 bit computers, they just waste .text currently. If and when we get
u128, string_get_size needs updating anyway (and ISO needs to come up
with four more prefixes).
Also there's no need to include and test for the NULL sentinel; once
we reach "E" size is at most 18. [The test is also wrong; it should be
units_str[units][i+1]; if we've reached NULL we're already doomed.]
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
lib/string_helpers.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/lib/string_helpers.c b/lib/string_helpers.c
index 58b78ba57439..0d25f7aa732c 100644
--- a/lib/string_helpers.c
+++ b/lib/string_helpers.c
@@ -28,11 +28,10 @@ int string_get_size(u64 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", NULL
+ "B", "kB", "MB", "GB", "TB", "PB", "EB"
};
static const char *const units_2[] = {
- "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB",
- NULL
+ "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"
};
static const char *const *const units_str[] = {
[STRING_UNITS_10] = units_10,
@@ -49,7 +48,7 @@ int string_get_size(u64 size, const enum string_size_units units,
tmp[0] = '\0';
i = 0;
if (size >= divisor[units]) {
- while (size >= divisor[units] && units_str[units][i]) {
+ while (size >= divisor[units]) {
remainder = do_div(size, divisor[units]);
i++;
}
--
2.1.3
next reply other threads:[~2014-12-12 14:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-12 14:43 Rasmus Villemoes [this message]
2014-12-12 14:43 ` [PATCH 2/3] lib: string_get_size: Use 32 bit arithmetic when possible Rasmus Villemoes
2014-12-12 14:43 ` [PATCH 3/3] lib: string_get_size: Return void Rasmus Villemoes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1418395428-25980-1-git-send-email-linux@rasmusvillemoes.dk \
--to=linux@rasmusvillemoes.dk \
--cc=James.Bottomley@HansenPartnership.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®