Skip to content

Commit

Permalink
regmap: debugfs: Ensure we don't underflow when printing access masks
Browse files Browse the repository at this point in the history
If a read is attempted which is smaller than the line length then we may
underflow the subtraction we're doing with the unsigned size_t type so
move some of the calculation to be additions on the right hand side
instead in order to avoid this.

Reported-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Mark Brown <broonie@kernel.org>
Cc: stable@vger.kernel.org
  • Loading branch information
Mark Brown committed Sep 19, 2015
1 parent 6ff33f3 commit b763ec1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/base/regmap/regmap-debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ static ssize_t regmap_access_read_file(struct file *file,
/* If we're in the region the user is trying to read */
if (p >= *ppos) {
/* ...but not beyond it */
if (buf_pos >= count - 1 - tot_len)
if (buf_pos + tot_len + 1 >= count)
break;

/* Format the register */
Expand Down

0 comments on commit b763ec1

Please sign in to comment.