Skip to content

Commit 68ede28

Browse files
JustinStittdtor
authored andcommitted
Input: axp20x-pek - avoid needless newline removal
This code is doing more work than it needs to. Before handing off `val_str` to `kstrtouint()` we are eagerly removing any trailing newline which requires copying `buf`, validating it's length and checking/replacing any potential newlines. kstrtouint() handles this implicitly: kstrtouint -> kstrotoull -> (documentation) | /** | * kstrtoull - convert a string to an unsigned long long | * @s: The start of the string. The string must be null-terminated, and may also | * include a single newline before its terminating null. The first character | ... Let's remove the redundant functionality and let kstrtouint handle it. Suggested-by: Kees Cook <[email protected]> Signed-off-by: Justin Stitt <[email protected]> Reviewed-by: Chen-Yu Tsai <[email protected]> Reviewed-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/20230925-strncpy-drivers-input-misc-axp20x-pek-c-v2-1-ff7abe8498d6@google.com Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 348cbf9 commit 68ede28

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

drivers/input/misc/axp20x-pek.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,20 +133,11 @@ static ssize_t axp20x_store_attr(struct device *dev,
133133
size_t count)
134134
{
135135
struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev);
136-
char val_str[20];
137-
size_t len;
138136
int ret, i;
139137
unsigned int val, idx = 0;
140138
unsigned int best_err = UINT_MAX;
141139

142-
val_str[sizeof(val_str) - 1] = '\0';
143-
strncpy(val_str, buf, sizeof(val_str) - 1);
144-
len = strlen(val_str);
145-
146-
if (len && val_str[len - 1] == '\n')
147-
val_str[len - 1] = '\0';
148-
149-
ret = kstrtouint(val_str, 10, &val);
140+
ret = kstrtouint(buf, 10, &val);
150141
if (ret)
151142
return ret;
152143

0 commit comments

Comments
 (0)