Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libstring_helpers.c:string_get_size(): return void

string_get_size() was documented to return an error, but in fact always
returned 0. Since the output always fits in 9 bytes, just document that
and let callers do what they do now: pass a small stack buffer and ignore
the return value.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Rasmus Villemoes and committed by
Linus Torvalds
d1214c65 84b9fbed

+6 -8
+2 -2
include/linux/string_helpers.h
··· 10 10 STRING_UNITS_2, /* use binary powers of 2^10 */ 11 11 }; 12 12 13 - int string_get_size(u64 size, enum string_size_units units, 14 - char *buf, int len); 13 + void string_get_size(u64 size, enum string_size_units units, 14 + char *buf, int len); 15 15 16 16 #define UNESCAPE_SPACE 0x01 17 17 #define UNESCAPE_OCTAL 0x02
+4 -6
lib/string_helpers.c
··· 20 20 * @len: length of buffer 21 21 * 22 22 * This function returns a string formatted to 3 significant figures 23 - * giving the size in the required units. Returns 0 on success or 24 - * error on failure. @buf is always zero terminated. 23 + * giving the size in the required units. @buf should have room for 24 + * at least 9 bytes and will always be zero terminated. 25 25 * 26 26 */ 27 - int string_get_size(u64 size, const enum string_size_units units, 28 - char *buf, int len) 27 + void string_get_size(u64 size, const enum string_size_units units, 28 + char *buf, int len) 29 29 { 30 30 static const char *const units_10[] = { 31 31 "B", "kB", "MB", "GB", "TB", "PB", "EB" ··· 67 67 68 68 snprintf(buf, len, "%u%s %s", (u32)size, 69 69 tmp, units_str[units][i]); 70 - 71 - return 0; 72 70 } 73 71 EXPORT_SYMBOL(string_get_size); 74 72