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

Configure Feed

Select the types of activity you want to include in your feed.

lib/string_helpers: string_get_size() now returns characters wrote

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 <kent.overstreet@linux.dev>

authored by

Kent Overstreet and committed by
Kent Overstreet
83feeb19 7d672f40

+8 -6
+2 -2
include/linux/string_helpers.h
··· 24 24 STRING_UNITS_2, /* use binary powers of 2^10 */ 25 25 }; 26 26 27 - void string_get_size(u64 size, u64 blk_size, enum string_size_units units, 28 - char *buf, int len); 27 + int string_get_size(u64 size, u64 blk_size, enum string_size_units units, 28 + char *buf, int len); 29 29 30 30 int parse_int_array_user(const char __user *from, size_t count, int **array); 31 31
+6 -4
lib/string_helpers.c
··· 31 31 * giving the size in the required units. @buf should have room for 32 32 * at least 9 bytes and will always be zero terminated. 33 33 * 34 + * Return value: number of characters of output that would have been written 35 + * (which may be greater than len, if output was truncated). 34 36 */ 35 - void string_get_size(u64 size, u64 blk_size, const enum string_size_units units, 36 - char *buf, int len) 37 + int string_get_size(u64 size, u64 blk_size, const enum string_size_units units, 38 + char *buf, int len) 37 39 { 38 40 static const char *const units_10[] = { 39 41 "B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" ··· 128 126 else 129 127 unit = units_str[units][i]; 130 128 131 - snprintf(buf, len, "%u%s %s", (u32)size, 132 - tmp, unit); 129 + return snprintf(buf, len, "%u%s %s", (u32)size, 130 + tmp, unit); 133 131 } 134 132 EXPORT_SYMBOL(string_get_size); 135 133