diff mbox

blktrace: fix integer parse

Message ID 3ceaaf95edea4e3f506f1e458323ceef5886f955.1495169957.git.shli@fb.com (mailing list archive)
State New, archived
Headers show

Commit Message

Shaohua Li May 19, 2017, 3:04 p.m. UTC
sscanf is a very poor way to parse integer. For example, I input
"discard" for act_mask, it gets 0xd and completely messes up. Using
correct API to do integer parse.

This patch also makes attributes accept any base of integer.

Signed-off-by: Shaohua Li <shli@fb.com>
---
 kernel/trace/blktrace.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Jens Axboe May 19, 2017, 3:21 p.m. UTC | #1
On 05/19/2017 09:04 AM, Shaohua Li wrote:
> sscanf is a very poor way to parse integer. For example, I input
> "discard" for act_mask, it gets 0xd and completely messes up. Using
> correct API to do integer parse.
> 
> This patch also makes attributes accept any base of integer.

Thanks Shaohua, applied.
diff mbox

Patch

diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index bd8ae8d..193c5f5 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -1662,14 +1662,14 @@  static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
 		goto out;
 
 	if (attr == &dev_attr_act_mask) {
-		if (sscanf(buf, "%llx", &value) != 1) {
+		if (kstrtoull(buf, 0, &value)) {
 			/* Assume it is a list of trace category names */
 			ret = blk_trace_str2mask(buf);
 			if (ret < 0)
 				goto out;
 			value = ret;
 		}
-	} else if (sscanf(buf, "%llu", &value) != 1)
+	} else if (kstrtoull(buf, 0, &value))
 		goto out;
 
 	ret = -ENXIO;