From: Michael Lyle <mlyle@lyle.org>
To: linux-bcache@vger.kernel.org
Cc: kent.overstreet@gmail.com, mlyle@lyle.org
Subject: [PATCH] bcache: fix bch_hprint crash and improve output
Date: Fri, 1 Sep 2017 13:37:22 -0700 [thread overview]
Message-ID: <20170901203722.29974-1-mlyle@lyle.org> (raw)
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@lyle.org>
Reported-by: Dmitry Yu Okunev <dyokunev@ut.mephi.ru>
---
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
next reply other threads:[~2017-09-01 20:38 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-01 20:37 Michael Lyle [this message]
2017-09-04 6:07 ` [PATCH] bcache: fix bch_hprint crash and improve output Coly Li
2017-09-04 16:31 ` Michael Lyle
2017-09-04 16:56 ` Coly Li
-- strict thread matches above, loose matches on Subject: below --
2017-09-04 21:55 Michael Lyle
2017-09-05 2:50 ` Coly Li
2017-09-05 4:19 ` Kent Overstreet
2017-09-05 4:52 ` Coly Li
2017-09-05 4:55 ` Kent Overstreet
2017-09-05 4:19 ` Kent Overstreet
2017-09-05 4:54 ` Coly Li
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=20170901203722.29974-1-mlyle@lyle.org \
--to=mlyle@lyle.org \
--cc=kent.overstreet@gmail.com \
--cc=linux-bcache@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