lkml.org 
[lkml]   [2012]   [May]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2] video/via: Convert to kstrtou8_from_user
On 05/04/2012 12:23 AM, Peter Huewe wrote:
> This patch replaces the code for getting an number from a
> userspace buffer by a simple call to kstrou8_from_user.
> This makes it easier to read and less error prone.
>
> v2:
> removed initialization of reg_val and dropped check if count < 1
>
> Signed-off-by: Peter Huewe <peterhuewe@gmx.de>

Applied.


Thanks,

Florian Tobias Schandinat

> ---
> @Alexey: Thanks for the review/feedback!
> drivers/video/via/viafbdev.c | 34 ++++++++++++----------------------
> 1 files changed, 12 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/video/via/viafbdev.c b/drivers/video/via/viafbdev.c
> index a13c258..88bf5ba 100644
> --- a/drivers/video/via/viafbdev.c
> +++ b/drivers/video/via/viafbdev.c
> @@ -1279,17 +1279,12 @@ static int viafb_dfph_proc_open(struct inode *inode, struct file *file)
> static ssize_t viafb_dfph_proc_write(struct file *file,
> const char __user *buffer, size_t count, loff_t *pos)
> {
> - char buf[20];
> - u8 reg_val = 0;
> - unsigned long length;
> - if (count < 1)
> - return -EINVAL;
> - length = count > 20 ? 20 : count;
> - if (copy_from_user(&buf[0], buffer, length))
> - return -EFAULT;
> - buf[length - 1] = '\0'; /*Ensure end string */
> - if (kstrtou8(buf, 0, &reg_val) < 0)
> - return -EINVAL;
> + int err;
> + u8 reg_val;
> + err = kstrtou8_from_user(buffer, count, 0, &reg_val);
> + if (err)
> + return err;
> +
> viafb_write_reg_mask(CR97, VIACR, reg_val, 0x0f);
> return count;
> }
> @@ -1319,17 +1314,12 @@ static int viafb_dfpl_proc_open(struct inode *inode, struct file *file)
> static ssize_t viafb_dfpl_proc_write(struct file *file,
> const char __user *buffer, size_t count, loff_t *pos)
> {
> - char buf[20];
> - u8 reg_val = 0;
> - unsigned long length;
> - if (count < 1)
> - return -EINVAL;
> - length = count > 20 ? 20 : count;
> - if (copy_from_user(&buf[0], buffer, length))
> - return -EFAULT;
> - buf[length - 1] = '\0'; /*Ensure end string */
> - if (kstrtou8(buf, 0, &reg_val) < 0)
> - return -EINVAL;
> + int err;
> + u8 reg_val;
> + err = kstrtou8_from_user(buffer, count, 0, &reg_val);
> + if (err)
> + return err;
> +
> viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f);
> return count;
> }



\
 
 \ /
  Last update: 2012-05-10 02:41    [W:0.046 / U:1.032 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site