Implement ->proc_write_buf() so procfs copies in what is written to /proc/led before it pins the entry, and parse the command from that copy. Writes larger than PAGE_SIZE - 1 bytes fail with -EINVAL now.
Signed-off-by: Christian Brauner (Amutable) <[email protected]> --- arch/sparc/kernel/led.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/arch/sparc/kernel/led.c b/arch/sparc/kernel/led.c index 12400bb59ab8..01449b056cdd 100644 --- a/arch/sparc/kernel/led.c +++ b/arch/sparc/kernel/led.c @@ -60,17 +60,12 @@ static int led_proc_show(struct seq_file *m, void *v) return 0; } -static ssize_t led_proc_write(struct file *file, const char __user *buffer, +static ssize_t led_proc_write(struct file *file, char *buf, size_t count, loff_t *ppos) { - char *buf = NULL; - if (count > LED_MAX_LENGTH) count = LED_MAX_LENGTH; - - buf = memdup_user_nul(buffer, count); - if (IS_ERR(buf)) - return PTR_ERR(buf); + buf[count] = '\0'; /* work around \n when echo'ing into proc */ if (count > 0 && buf[count - 1] == '\n') @@ -95,14 +90,12 @@ static ssize_t led_proc_write(struct file *file, const char __user *buffer, auxio_set_led(AUXIO_LED_OFF); } - kfree(buf); - return count; } static const struct proc_ops led_proc_ops = { .proc_show = led_proc_show, - .proc_write = led_proc_write, + .proc_write_buf = led_proc_write, }; #endif -- 2.53.0
