Skip to contentSkip to conversation

Input: iqs626a - replace snprintf() with scnprintf()

PATCH Applied Jeff LaBundy 2 participants 2 messages Jan 5, 2025 – Jun 4, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Input: iqs626a - replace snprintf() with scnprintf()

W=1 builds warn that the data written to 'tc_name' is truncated for theoretical strings such as "channel-2147483646".

Solve this problem by replacing snprintf() with scnprintf() so that the return value corresponds to what was actually written.

In practice, the largest string that will be written is "channel-8", and the return value is not actually evaluated. Instead, this patch ultimately removes the warning without unnecessarily increasing the size of 'tc_name' from 10 bytes.

---
Changes in v2:
- Fixed commit message ("channel-9" -> "channel-8")

 drivers/input/misc/iqs626a.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/misc/iqs626a.c +1 -1
index 7a6e6927f331..7fba4a8edceb 100644
@@ -771,7 +771,7 @@ static int iqs626_parse_trackpad(struct iqs626_private *iqs626,
 		u8 *thresh = &sys_reg->tp_grp_reg.ch_reg_tp[i].thresh;
 		char tc_name[10];
 
-		snprintf(tc_name, sizeof(tc_name), "channel-%d", i);
+		scnprintf(tc_name, sizeof(tc_name), "channel-%d", i);
 
 		struct fwnode_handle *tc_node __free(fwnode_handle) =
 				fwnode_get_named_child_node(ch_node, tc_name);
Signature · 1 line
2.34.1
maintainer Applied
#1 lore raw
Quoted 6 lines · Jeff LaBundy

W=1 builds warn that the data written to 'tc_name' is truncated for theoretical strings such as "channel-2147483646".

Solve this problem by replacing snprintf() with scnprintf() so that the return value corresponds to what was actually written.

Quoted 8 lines

In practice, the largest string that will be written is "channel-8", and the return value is not actually evaluated. Instead, this patch ultimately removes the warning without unnecessarily increasing the size of 'tc_name' from 10 bytes.

Applied, thank you.

Signature · 1 line
Dmitry