dma/coh901318: fix copy_to_user error path
PATCH 1/1 dma/coh901318: fix copy_to_user error path
If copy_to_user fails, the assigned error code instantly gets overwritten, and the failure apparently ignored. Moreover, shouldn't the error code be -EFAULT instead of -EINVAL?
--- drivers/dma/coh901318.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
drivers/dma/coh901318.c +4 -2
@@ -140,8 +140,10 @@ static int coh901318_debugfs_read(struct file *file, char __user *buf,if (count > dev_size - *f_pos) count = dev_size - *f_pos; -if (copy_to_user (buf, dev_buf + *f_pos, count)) - ret = -EINVAL ; +if (copy_to_user (buf, dev_buf + *f_pos, count)) { + ret = -EFAULT ; + goto out; + } ret = count; *f_pos += count;
Signature · 1 line
1.7.2.2
Quoted 3 lines · On Friday 22 October 2010 19:29:53 Nicolas Kaiser wrote:
If
copy_to_userfails, the assigned error code instantly gets overwritten, and the failure apparently ignored. Moreover, shouldn't the error code be-EFAULTinstead of-EINVAL?
Looks good, but it would be even better to just use simple_read_from_buffer in this function, which takes care of a lot the other complexities as well.
Arnd
PATCH 1/1 dma/coh901318: use simple_read_from_buffer
* Arnd Bergmann <[email protected]>:
Quoted 8 lines · On Friday 22 October 2010 19:29:53 Nicolas Kaiser wrote:
Quoted 3 lines
If
copy_to_userfails, the assigned error code instantly gets overwritten, and the failure apparently ignored. Moreover, shouldn't the error code be-EFAULTinstead of-EINVAL?Looks good, but it would be even better to just use
simple_read_from_bufferin this function, which takes care of a lot the other complexities as well.
Like this? (Sorry, untested.)
---
obsoletes patch "dma/coh901318: fix copy_to_user error path"
drivers/dma/coh901318.c | 12 +----------- 1 files changed, 1 insertions(+), 11 deletions(-)
drivers/dma/coh901318.c +1 -11
@@ -133,17 +133,7 @@ static int coh901318_debugfs_read(struct file *file, char __user *buf, tmp +=sprintf (tmp,"Pool alloc nbr %d\n" , pool_count); dev_size = tmp - dev_buf; -/* No more to read if offset != 0 */ -if (*f_pos > dev_size) - goto out; - -if (count > dev_size - *f_pos) - count = dev_size - *f_pos; - -if (copy_to_user (buf, dev_buf + *f_pos, count)) - ret = -EINVAL ; - ret = count; - *f_pos += count; + ret =simple_read_from_buffer (buf, count, f_pos, dev_buf, dev_size); out:kfree (dev_buf);
Signature · 1 line
1.7.2.2
Re: [PATCH] dma/coh901318: use simple_read_from_buffer
Quoted 6 lines · On Friday 22 October 2010 20:30:39 Nicolas Kaiser wrote:
* Arnd Bergmann <[email protected]>:
Quoted 5 lines · On Friday 22 October 2010 19:29:53 Nicolas Kaiser wrote:
Quoted 3 lines
If
copy_to_userfails, the assigned error code instantly gets overwritten, and the failure apparently ignored. Moreover, shouldn't the error code be-EFAULTinstead of-EINVAL?
Quoted 7 lines
Quoted 3 lines
Looks good, but it would be even better to just use
simple_read_from_bufferin this function, which takes care of a lot the other complexities as well.Like this? (Sorry, untested.)
Signed-off-by Nicolas Kaiser <[email protected]>
Yes, exactly. For stable kernels, your smaller fix is probably good enough though and it's obviously correct.
Arnd