public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Christopher N. Hesse" <raymanfx@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: penguin-kernel@I-love.SAKURA.ne.jp,
	"Christopher N. Hesse" <raymanfx@gmail.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Arve Hjønnevåg" <arve@android.com>,
	"Todd Kjos" <tkjos@android.com>,
	"Martijn Coenen" <maco@android.com>,
	"Joel Fernandes" <joel@joelfernandes.org>,
	"Christian Brauner" <christian@brauner.io>,
	devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org
Subject: [PATCH] staging: android: ashmem: Fix zero area size return code
Date: Mon, 23 Sep 2019 16:54:51 +0200	[thread overview]
Message-ID: <20190923145451.13341-1-raymanfx@gmail.com> (raw)

The previous inline comment stated that a size of zero would make the
ashmem_read_iter function return EOF, but it returned 0 instead.

Looking at other functions, such as ashmem_llseek or ashmem_mmap, it
appears the convention is to return -EINVAL if the region size is unset or
zero.

To be consistent with the checks, I changed the one occurrence that used
the ! operator to compare the size to check against equal-to-zero instead.

Signed-off-by: Christopher N. Hesse <raymanfx@gmail.com>
---
 drivers/staging/android/ashmem.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c
index 74d497d39c5a..6af8130db0d7 100644
--- a/drivers/staging/android/ashmem.c
+++ b/drivers/staging/android/ashmem.c
@@ -291,9 +291,11 @@ static ssize_t ashmem_read_iter(struct kiocb *iocb, struct iov_iter *iter)
 
 	mutex_lock(&ashmem_mutex);
 
-	/* If size is not set, or set to 0, always return EOF. */
-	if (asma->size == 0)
+	/* If size is not set, or set to 0, always return EINVAL. */
+	if (asma->size == 0) {
+		ret = -EINVAL;
 		goto out_unlock;
+	}
 
 	if (!asma->file) {
 		ret = -EBADF;
@@ -359,7 +361,7 @@ static int ashmem_mmap(struct file *file, struct vm_area_struct *vma)
 	mutex_lock(&ashmem_mutex);
 
 	/* user needs to SET_SIZE before mapping */
-	if (!asma->size) {
+	if (asma->size == 0) {
 		ret = -EINVAL;
 		goto out;
 	}
-- 
2.23.0


                 reply	other threads:[~2019-09-23 14:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20190923145451.13341-1-raymanfx@gmail.com \
    --to=raymanfx@gmail.com \
    --cc=arve@android.com \
    --cc=christian@brauner.io \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=joel@joelfernandes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maco@android.com \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=tkjos@android.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox