From 64b8a16f4486912e4aa315497ea13c2d57402fc3 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Tue, 24 Mar 2015 20:32:40 +0100 Subject: [PATCH] greybus: es1: move debugfs function to use kstrotoint_from_user() No need to duplicate built-in functions that the kernel has, so have the core kernel parse the userspace string. Saves us an allocation and makes the logic simpler. Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/es1.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/staging/greybus/es1.c b/drivers/staging/greybus/es1.c index 796c2ab5dafd..a7fb4b52991b 100644 --- a/drivers/staging/greybus/es1.c +++ b/drivers/staging/greybus/es1.c @@ -581,20 +581,19 @@ static ssize_t apb1_log_enable_write(struct file *f, const char __user *buf, size_t count, loff_t *ppos) { int enable; - char *tmp_buf; - ssize_t retval = -EINVAL; + ssize_t retval; struct es1_ap_dev *es1 = (struct es1_ap_dev *)f->f_inode->i_private; - tmp_buf = kmalloc(count, GFP_KERNEL); - if (!tmp_buf) - return -ENOMEM; + retval = kstrtoint_from_user(buf, count, 10, &enable); + if (retval) + return retval; - copy_from_user(tmp_buf, buf, count); - if (sscanf(tmp_buf, "%d", &enable) == 1) { + if (enable) { usb_log_enable(es1, enable); retval = count; + } else { + retval = -EINVAL; } - kfree(tmp_buf); return retval; } -- 2.20.1