* [patch] staging: android: ion: Fix error handling in ion_query_heaps()
@ 2016-10-12 12:49 Dan Carpenter
2016-10-13 0:12 ` Laura Abbott
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2016-10-12 12:49 UTC (permalink / raw)
To: kernel-janitors
copy_to_user() returns the number of bytes remaining to be copied. We
want to return -EFAULT here instead. Also there seems like no point
in continuing the loop if copy_to_user() fails.
Fixes: 02b23803c6af ('staging: android: ion: Add ioctl to query available heaps')
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
The error handling still might be wrong here. Do we really want to
change query->cnt? Please review.
diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c
index 396ded5..4cec0b2 100644
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -1187,8 +1187,10 @@ int ion_query_heaps(struct ion_client *client, struct ion_heap_query *query)
hdata.type = heap->type;
hdata.heap_id = heap->id;
- ret = copy_to_user(&buffer[cnt],
- &hdata, sizeof(hdata));
+ if (copy_to_user(&buffer[cnt], &hdata, sizeof(hdata))) {
+ ret = -EFAULT;
+ break;
+ }
cnt++;
if (cnt >= max_cnt)
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [patch] staging: android: ion: Fix error handling in ion_query_heaps()
2016-10-12 12:49 [patch] staging: android: ion: Fix error handling in ion_query_heaps() Dan Carpenter
@ 2016-10-13 0:12 ` Laura Abbott
0 siblings, 0 replies; 2+ messages in thread
From: Laura Abbott @ 2016-10-13 0:12 UTC (permalink / raw)
To: kernel-janitors
On 10/12/2016 05:49 AM, Dan Carpenter wrote:
> copy_to_user() returns the number of bytes remaining to be copied. We
> want to return -EFAULT here instead. Also there seems like no point
> in continuing the loop if copy_to_user() fails.
>
> Fixes: 02b23803c6af ('staging: android: ion: Add ioctl to query available heaps')
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> The error handling still might be wrong here. Do we really want to
> change query->cnt? Please review.
>
> diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c
> index 396ded5..4cec0b2 100644
> --- a/drivers/staging/android/ion/ion.c
> +++ b/drivers/staging/android/ion/ion.c
> @@ -1187,8 +1187,10 @@ int ion_query_heaps(struct ion_client *client, struct ion_heap_query *query)
> hdata.type = heap->type;
> hdata.heap_id = heap->id;
>
> - ret = copy_to_user(&buffer[cnt],
> - &hdata, sizeof(hdata));
> + if (copy_to_user(&buffer[cnt], &hdata, sizeof(hdata))) {
> + ret = -EFAULT;
> + break;
> + }
>
> cnt++;
> if (cnt >= max_cnt)
>
Yeah, I really butchered the error handling on this. You are correct,
query->cnt shouldn't be updated. break can be changed to 'goto out'.
Thanks,
Laura
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-10-13 0:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-12 12:49 [patch] staging: android: ion: Fix error handling in ion_query_heaps() Dan Carpenter
2016-10-13 0:12 ` Laura Abbott
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox