Skip to contentSkip to conversation

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

PATCH Superseded Christopher Heiny 2 participants 2 messages Jan 8, 2014

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 input: synaptics-rmi4 - use snprintf instead of sprintf in rmi_i2c.c

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

Cc Dmitry Torokhov <[email protected]>
Cc Benjamin Tissoires <[email protected]>

---

 drivers/input/rmi4/rmi_i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/rmi4/rmi_i2c.c +1 -1
index b33074c..43b0e53 100644
@@ -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;
 	}
 
maintainer
#1 lore raw
Quoted 17 lines · Christopher Heiny

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

Cc Dmitry Torokhov <[email protected]>
Cc Benjamin Tissoires <[email protected]>

---

 drivers/input/rmi4/rmi_i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/rmi4/rmi_i2c.c +0 -0
index b33074c..43b0e53 100644

drivers/input/rmi4/rmi_i2c.c static int copy_to_debug_buf(struct device *dev, struct rmi_i2c_data *data, · line 163

Quoted 8 lines
drivers/input/rmi4/rmi_i2c.c +1 -1
@@ -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.

Signature · 1 line
Dmitry