* [PATCH 1/3] regmap: debugfs: Ensure we don't underflow when printing access masks
@ 2015-09-19 14:37 Mark Brown
2015-09-19 14:37 ` [PATCH 2/3] regmap: debugfs: Don't bother actually printing when calculating max length Mark Brown
2015-09-19 14:37 ` [PATCH 3/3] regmap: debugfs: Remove scratch buffer for register length calculation Mark Brown
0 siblings, 2 replies; 3+ messages in thread
From: Mark Brown @ 2015-09-19 14:37 UTC (permalink / raw)
To: Rasmus Villemoes; +Cc: linux-kernel, Mark Brown, stable
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
---
drivers/base/regmap/regmap-debugfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c
index f42f2ba..1f32789 100644
--- a/drivers/base/regmap/regmap-debugfs.c
+++ b/drivers/base/regmap/regmap-debugfs.c
@@ -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 */
--
2.5.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/3] regmap: debugfs: Don't bother actually printing when calculating max length
2015-09-19 14:37 [PATCH 1/3] regmap: debugfs: Ensure we don't underflow when printing access masks Mark Brown
@ 2015-09-19 14:37 ` Mark Brown
2015-09-19 14:37 ` [PATCH 3/3] regmap: debugfs: Remove scratch buffer for register length calculation Mark Brown
1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2015-09-19 14:37 UTC (permalink / raw)
To: Rasmus Villemoes; +Cc: linux-kernel, Mark Brown, stable
The in kernel snprintf() will conveniently return the actual length of
the printed string even if not given an output beffer at all so just do
that rather than relying on the user to pass in a suitable buffer,
ensuring that we don't need to worry if the buffer was truncated due to
the size of the buffer passed in.
Reported-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Mark Brown <broonie@kernel.org>
Cc: stable@vger.kernel.org
---
drivers/base/regmap/regmap-debugfs.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c
index 1f32789..4c55cfb 100644
--- a/drivers/base/regmap/regmap-debugfs.c
+++ b/drivers/base/regmap/regmap-debugfs.c
@@ -32,8 +32,7 @@ static DEFINE_MUTEX(regmap_debugfs_early_lock);
/* Calculate the length of a fixed format */
static size_t regmap_calc_reg_len(int max_val, char *buf, size_t buf_size)
{
- snprintf(buf, buf_size, "%x", max_val);
- return strlen(buf);
+ return snprintf(NULL, 0, "%x", max_val);
}
static ssize_t regmap_name_read_file(struct file *file,
--
2.5.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 3/3] regmap: debugfs: Remove scratch buffer for register length calculation
2015-09-19 14:37 [PATCH 1/3] regmap: debugfs: Ensure we don't underflow when printing access masks Mark Brown
2015-09-19 14:37 ` [PATCH 2/3] regmap: debugfs: Don't bother actually printing when calculating max length Mark Brown
@ 2015-09-19 14:37 ` Mark Brown
1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2015-09-19 14:37 UTC (permalink / raw)
To: Rasmus Villemoes; +Cc: linux-kernel, Mark Brown
Now we no longer use the scratch buffer for register length calculation
there is no need for callers to supply one.
Signed-off-by: Mark Brown <broonie@kernel.org>
---
drivers/base/regmap/regmap-debugfs.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c
index 4c55cfb..4a47378 100644
--- a/drivers/base/regmap/regmap-debugfs.c
+++ b/drivers/base/regmap/regmap-debugfs.c
@@ -30,7 +30,7 @@ static LIST_HEAD(regmap_debugfs_early_list);
static DEFINE_MUTEX(regmap_debugfs_early_lock);
/* Calculate the length of a fixed format */
-static size_t regmap_calc_reg_len(int max_val, char *buf, size_t buf_size)
+static size_t regmap_calc_reg_len(int max_val)
{
return snprintf(NULL, 0, "%x", max_val);
}
@@ -173,8 +173,7 @@ static inline void regmap_calc_tot_len(struct regmap *map,
{
/* Calculate the length of a fixed format */
if (!map->debugfs_tot_len) {
- map->debugfs_reg_len = regmap_calc_reg_len(map->max_register,
- buf, count);
+ map->debugfs_reg_len = regmap_calc_reg_len(map->max_register),
map->debugfs_val_len = 2 * map->format.val_bytes;
map->debugfs_tot_len = map->debugfs_reg_len +
map->debugfs_val_len + 3; /* : \n */
@@ -420,7 +419,7 @@ static ssize_t regmap_access_read_file(struct file *file,
return -ENOMEM;
/* Calculate the length of a fixed format */
- reg_len = regmap_calc_reg_len(map->max_register, buf, count);
+ reg_len = regmap_calc_reg_len(map->max_register);
tot_len = reg_len + 10; /* ': R W V P\n' */
for (i = 0; i <= map->max_register; i += map->reg_stride) {
--
2.5.0
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-09-20 0:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-19 14:37 [PATCH 1/3] regmap: debugfs: Ensure we don't underflow when printing access masks Mark Brown
2015-09-19 14:37 ` [PATCH 2/3] regmap: debugfs: Don't bother actually printing when calculating max length Mark Brown
2015-09-19 14:37 ` [PATCH 3/3] regmap: debugfs: Remove scratch buffer for register length calculation Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®