[PATCH] input: synaptics-rmi4 - use snprintf instead of sprintf in rmi_i2c.c

Subsystems: input (keyboard, mouse, joystick, touchscreen) drivers, the rest

STALE4647d

2 messages, 2 authors, 2014-01-08 · open the first message on its own page

[PATCH] input: synaptics-rmi4 - use snprintf instead of sprintf in rmi_i2c.c

From: Christopher Heiny <hidden>
Date: 2014-01-08 21:38:00

This is a trivial change to use snprintf rather than sprintf while building
the diagnostic output buffer.

Signed-off-by: Christopher Heiny <redacted>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Benjamin Tissoires <redacted>

---

 drivers/input/rmi4/rmi_i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/input/rmi4/rmi_i2c.c b/drivers/input/rmi4/rmi_i2c.c
index b33074c..43b0e53 100644
--- a/drivers/input/rmi4/rmi_i2c.c
+++ b/drivers/input/rmi4/rmi_i2c.c
@@ -157,7 +157,7 @@ static int copy_to_debug_buf(struct device *dev, struct rmi_i2c_data *data,
 	temp = data->debug_buf;
 
 	for (i = 0; i < len; i++) {
-		n = sprintf(temp, " %02x", buf[i]);
+		n = snprintf(temp, 3, " %02x", buf[i]);
 		temp += n;
 	}
 

Re: [PATCH] input: synaptics-rmi4 - use snprintf instead of sprintf in rmi_i2c.c

From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Date: 2014-01-08 22:44:28

On Wed, Jan 08, 2014 at 01:37:55PM -0800, Christopher Heiny wrote:
quoted hunk
This is a trivial change to use snprintf rather than sprintf while building
the diagnostic output buffer.

Signed-off-by: Christopher Heiny <redacted>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Benjamin Tissoires <redacted>

---

 drivers/input/rmi4/rmi_i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/input/rmi4/rmi_i2c.c b/drivers/input/rmi4/rmi_i2c.c
index b33074c..43b0e53 100644
--- a/drivers/input/rmi4/rmi_i2c.c
+++ b/drivers/input/rmi4/rmi_i2c.c
@@ -157,7 +157,7 @@ static int copy_to_debug_buf(struct device *dev, struct rmi_i2c_data *data,
 	temp = data->debug_buf;
 
 	for (i = 0; i < len; i++) {
-		n = sprintf(temp, " %02x", buf[i]);
+		n = snprintf(temp, 3, " %02x", buf[i]);
 		temp += n;
 	}
 
I do not think it is right, as if there is truncation you'd move too
far. In any case please replace the while loop with:

	snprintf(data->debug_buf, data->debug_buf_size, "%*ph", len, buf);

Thanks.

-- 
Dmitry
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help