Skip to content

Commit

Permalink
blktrace: fix integer parse
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Jens Axboe <axboe@fb.com>
  • Loading branch information
Shaohua Li authored and Jens Axboe committed May 19, 2017
1 parent 69c8ebf commit 5f33945
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kernel/trace/blktrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5f33945

Please sign in to comment.