Solve a crash where the stack is overrun when reading sysfs and small negative values are present. Also correct output, as before it would output "1.10" for numbers bigger than "1.9", and negative fractional output was incorrect. Signed-off-by: Michael Lyle <mlyle@xxxxxxxx> Reported-by: Dmitry Yu Okunev <dyokunev@xxxxxxxxxxx> --- drivers/md/bcache/util.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/md/bcache/util.c b/drivers/md/bcache/util.c index 8c3a938f4bf0..11957038c630 100644 --- a/drivers/md/bcache/util.c +++ b/drivers/md/bcache/util.c @@ -86,10 +86,14 @@ ssize_t bch_hprint(char *buf, int64_t v) } if (!u) - return sprintf(buf, "%llu", v); + return sprintf(buf, "%lli", v); - if (v < 100 && v > -100) - snprintf(dec, sizeof(dec), ".%i", t / 100); + if (t > 103) { + if (v > 0) + snprintf(dec, sizeof(dec), ".%i", t * 10 / 1024); + else + snprintf(dec, sizeof(dec), ".%i", 10 - (t * 10 / 1024)); + } return sprintf(buf, "%lli%s%c", v, dec, units[u]); } -- 2.11.0 -- To unsubscribe from this list: send the line "unsubscribe linux-bcache" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html