video/via: Convert to kstrtou8_from_user
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. Signed-off-by: Peter Huewe <peterhuewe@gmx.de> Acked-by: Alexey Dobriyan <adobriyan@gmail.com> Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
This commit is contained in:
parent
c1f58f1e1e
commit
9f5610e20b
1 changed files with 12 additions and 22 deletions
|
@ -1276,17 +1276,12 @@ static int viafb_dfph_proc_open(struct inode *inode, struct file *file)
|
||||||
static ssize_t viafb_dfph_proc_write(struct file *file,
|
static ssize_t viafb_dfph_proc_write(struct file *file,
|
||||||
const char __user *buffer, size_t count, loff_t *pos)
|
const char __user *buffer, size_t count, loff_t *pos)
|
||||||
{
|
{
|
||||||
char buf[20];
|
int err;
|
||||||
u8 reg_val = 0;
|
u8 reg_val;
|
||||||
unsigned long length;
|
err = kstrtou8_from_user(buffer, count, 0, ®_val);
|
||||||
if (count < 1)
|
if (err)
|
||||||
return -EINVAL;
|
return err;
|
||||||
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, ®_val) < 0)
|
|
||||||
return -EINVAL;
|
|
||||||
viafb_write_reg_mask(CR97, VIACR, reg_val, 0x0f);
|
viafb_write_reg_mask(CR97, VIACR, reg_val, 0x0f);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
@ -1316,17 +1311,12 @@ static int viafb_dfpl_proc_open(struct inode *inode, struct file *file)
|
||||||
static ssize_t viafb_dfpl_proc_write(struct file *file,
|
static ssize_t viafb_dfpl_proc_write(struct file *file,
|
||||||
const char __user *buffer, size_t count, loff_t *pos)
|
const char __user *buffer, size_t count, loff_t *pos)
|
||||||
{
|
{
|
||||||
char buf[20];
|
int err;
|
||||||
u8 reg_val = 0;
|
u8 reg_val;
|
||||||
unsigned long length;
|
err = kstrtou8_from_user(buffer, count, 0, ®_val);
|
||||||
if (count < 1)
|
if (err)
|
||||||
return -EINVAL;
|
return err;
|
||||||
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, ®_val) < 0)
|
|
||||||
return -EINVAL;
|
|
||||||
viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f);
|
viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue