Skip to content

Commit 7eb475e

Browse files
neosys007andreas-gaisler
authored andcommitted
sparc: led: avoid trimming a newline from empty writes
led_proc_write() duplicates up to LED_MAX_LENGTH bytes with memdup_user_nul() and then unconditionally inspects buf[count - 1] to strip a trailing newline. A zero-length write therefore reads one byte before the duplicated buffer. The previous version rejected empty writes, but empty input already falls through to the existing default case and turns the LED off like any other unrecognized string. Preserve that behavior and only skip the newline trim when there is no input byte to inspect. Fixes: ee1858d ("[SPARC]: Add sun4m LED driver.") Suggested-by: Andreas Larsson <andreas@gaisler.com> Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn> Signed-off-by: Andreas Larsson <andreas@gaisler.com>
1 parent 2416b30 commit 7eb475e

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

arch/sparc/kernel/led.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static ssize_t led_proc_write(struct file *file, const char __user *buffer,
7878
return PTR_ERR(buf);
7979

8080
/* work around \n when echo'ing into proc */
81-
if (buf[count - 1] == '\n')
81+
if (count > 0 && buf[count - 1] == '\n')
8282
buf[count - 1] = '\0';
8383

8484
/* before we change anything we want to stop any running timers,

0 commit comments

Comments
 (0)