All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kernel-janitors@vger.kernel.org
Subject: [patch] staging: android: ion: Fix error handling in ion_query_heaps()
Date: Wed, 12 Oct 2016 12:49:40 +0000	[thread overview]
Message-ID: <20161012124940.GA23933@mwanda> (raw)

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)

             reply	other threads:[~2016-10-12 12:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-12 12:49 Dan Carpenter [this message]
2016-10-13  0:12 ` [patch] staging: android: ion: Fix error handling in ion_query_heaps() Laura Abbott

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161012124940.GA23933@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.