Skip to content

Commit 0d8675e

Browse files
andy-shevlinusw
authored andcommitted
pinctrl: Duplicate user memory in one go in pinmux_select()
Current code is suboptimal in three ways: 1) it explicitly terminates the string which is not needed; 2) it might provoke additional faults, because asked lenght might be bigger than the real one; 3) it consumes more than needed lines in the source. Instead of using kmalloc() + strncpy_from_user() + terminating, just utilize memdup_user_nul(). Signed-off-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Linus Walleij <[email protected]>
1 parent 5cc9525 commit 0d8675e

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

drivers/pinctrl/pinmux.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -692,14 +692,9 @@ static ssize_t pinmux_select(struct file *file, const char __user *user_buf,
692692
if (len > PINMUX_SELECT_MAX)
693693
return -ENOMEM;
694694

695-
buf = kzalloc(PINMUX_SELECT_MAX, GFP_KERNEL);
696-
if (!buf)
697-
return -ENOMEM;
698-
699-
ret = strncpy_from_user(buf, user_buf, PINMUX_SELECT_MAX);
700-
if (ret < 0)
701-
goto exit_free_buf;
702-
buf[len-1] = '\0';
695+
buf = memdup_user_nul(user_buf, len);
696+
if (IS_ERR(buf))
697+
return PTR_ERR(buf);
703698

704699
/* remove leading and trailing spaces of input buffer */
705700
gname = strstrip(buf);

0 commit comments

Comments
 (0)