* [PATCH] video/via: Convert to kstrtou8_from_user
@ 2012-04-14 23:24 Peter Huewe
2012-04-16 16:36 ` Alexey Dobriyan
0 siblings, 1 reply; 4+ messages in thread
From: Peter Huewe @ 2012-04-14 23:24 UTC (permalink / raw)
To: Florian Tobias Schandinat
Cc: linux-fbdev, linux-kernel, kernel-janitors, Peter Huewe
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>
---
drivers/video/via/viafbdev.c | 26 ++++++++++----------------
1 files changed, 10 insertions(+), 16 deletions(-)
diff --git a/drivers/video/via/viafbdev.c b/drivers/video/via/viafbdev.c
index 0c88375..5b0d524 100644
--- a/drivers/video/via/viafbdev.c
+++ b/drivers/video/via/viafbdev.c
@@ -1276,17 +1276,14 @@ 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];
+ int err;
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, ®_val) < 0)
- return -EINVAL;
+ err = kstrtou8_from_user(buffer, count, 0, ®_val);
+ if (err)
+ return err;
+
viafb_write_reg_mask(CR97, VIACR, reg_val, 0x0f);
return count;
}
@@ -1316,17 +1313,14 @@ 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];
+ int err;
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, ®_val) < 0)
- return -EINVAL;
+ err = kstrtou8_from_user(buffer, count, 0, ®_val);
+ if (err)
+ return err;
+
viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f);
return count;
}
--
1.7.3.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] video/via: Convert to kstrtou8_from_user
2012-04-14 23:24 [PATCH] video/via: Convert to kstrtou8_from_user Peter Huewe
@ 2012-04-16 16:36 ` Alexey Dobriyan
2012-05-04 0:23 ` [PATCH v2] " Peter Huewe
0 siblings, 1 reply; 4+ messages in thread
From: Alexey Dobriyan @ 2012-04-16 16:36 UTC (permalink / raw)
To: Peter Huewe
Cc: Florian Tobias Schandinat, linux-fbdev, linux-kernel,
kernel-janitors
On Sun, Apr 15, 2012 at 2:24 AM, Peter Huewe <peterhuewe@gmx.de> 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.
Initialization with 0 is not necessary then.
Also "count < 1" check could be dropped, since empty string will fail
with EINVAL.
Otherwise OK.
> --- a/drivers/video/via/viafbdev.c
> +++ b/drivers/video/via/viafbdev.c
> @@ -1276,17 +1276,14 @@ 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];
> + int err;
> 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, ®_val) < 0)
> - return -EINVAL;
> + err = kstrtou8_from_user(buffer, count, 0, ®_val);
> + if (err)
> + return err;
> +
> viafb_write_reg_mask(CR97, VIACR, reg_val, 0x0f);
> return count;
> }
> @@ -1316,17 +1313,14 @@ 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];
> + int err;
> 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, ®_val) < 0)
> - return -EINVAL;
> + err = kstrtou8_from_user(buffer, count, 0, ®_val);
> + if (err)
> + return err;
> +
> viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f);
> return count;
> }
> --
> 1.7.3.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] video/via: Convert to kstrtou8_from_user
2012-04-16 16:36 ` Alexey Dobriyan
@ 2012-05-04 0:23 ` Peter Huewe
2012-05-10 0:19 ` Florian Tobias Schandinat
0 siblings, 1 reply; 4+ messages in thread
From: Peter Huewe @ 2012-05-04 0:23 UTC (permalink / raw)
To: Florian Tobias Schandinat
Cc: Alexey Dobriyan, linux-fbdev, linux-kernel, kernel-janitors,
Peter Huewe
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>
---
@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, ®_val) < 0)
- return -EINVAL;
+ int err;
+ u8 reg_val;
+ err = kstrtou8_from_user(buffer, count, 0, ®_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, ®_val) < 0)
- return -EINVAL;
+ int err;
+ u8 reg_val;
+ err = kstrtou8_from_user(buffer, count, 0, ®_val);
+ if (err)
+ return err;
+
viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f);
return count;
}
--
1.7.3.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] video/via: Convert to kstrtou8_from_user
2012-05-04 0:23 ` [PATCH v2] " Peter Huewe
@ 2012-05-10 0:19 ` Florian Tobias Schandinat
0 siblings, 0 replies; 4+ messages in thread
From: Florian Tobias Schandinat @ 2012-05-10 0:19 UTC (permalink / raw)
To: Peter Huewe; +Cc: Alexey Dobriyan, linux-fbdev, linux-kernel, kernel-janitors
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, ®_val) < 0)
> - return -EINVAL;
> + int err;
> + u8 reg_val;
> + err = kstrtou8_from_user(buffer, count, 0, ®_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, ®_val) < 0)
> - return -EINVAL;
> + int err;
> + u8 reg_val;
> + err = kstrtou8_from_user(buffer, count, 0, ®_val);
> + if (err)
> + return err;
> +
> viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f);
> return count;
> }
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-05-10 0:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-14 23:24 [PATCH] video/via: Convert to kstrtou8_from_user Peter Huewe
2012-04-16 16:36 ` Alexey Dobriyan
2012-05-04 0:23 ` [PATCH v2] " Peter Huewe
2012-05-10 0:19 ` Florian Tobias Schandinat
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).