linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Liu <jeff.liu@oracle.com>
To: linux-btrfs@vger.kernel.org
Cc: chris.mason@oracle.com
Subject: Fix btrfs_file_llseek() to return -EINVAL directly
Date: Mon, 29 Aug 2011 02:48:05 -0700 (PDT)	[thread overview]
Message-ID: <4E5B6055.1080807@oracle.com> (raw)

Hello,

In btrfs_file_llseek(), if the offset < 0 or offset > 
inode->i_sb->s_maxbytes, we should return -EINVAL rather than offset.
Also,  if the offset >= inode->i_size for SEEK_DATA or SEEK_HOLE, return 
-ENXIO is ok IMHO.


Signed-off-by: Jie Liu <jeff.liu@oracle.com>

diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index e7872e4..2c126d0 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1813,6 +1813,11 @@ static loff_t btrfs_file_llseek(struct file 
*file, loff_t offset, int origin)
          goto out;
      case SEEK_DATA:
      case SEEK_HOLE:
+        if (offset >= inode->i_size) {
+            mutex_unlock(&inode->i_mutex);
+            return -ENXIO;
+        }
+
          ret = find_desired_extent(inode, &offset, origin);
          if (ret) {
              mutex_unlock(&inode->i_mutex);
@@ -1820,14 +1825,11 @@ static loff_t btrfs_file_llseek(struct file 
*file, loff_t offset, int origin)
          }
      }

-    if (offset < 0 && !(file->f_mode & FMODE_UNSIGNED_OFFSET)) {
-        ret = -EINVAL;
-        goto out;
-    }
-    if (offset > inode->i_sb->s_maxbytes) {
-        ret = -EINVAL;
-        goto out;
-    }
+    if (offset < 0 && !(file->f_mode & FMODE_UNSIGNED_OFFSET))
+        return -EINVAL;
+
+    if (offset > inode->i_sb->s_maxbytes)
+        return -EINVAL;

      /* Special lock needed here? */
      if (offset != file->f_pos) {


             reply	other threads:[~2011-08-29  9:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-29  9:48 Jeff Liu [this message]
2011-08-30  3:59 ` Fix btrfs_file_llseek() to return -EINVAL directly Jeff Liu

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=4E5B6055.1080807@oracle.com \
    --to=jeff.liu@oracle.com \
    --cc=chris.mason@oracle.com \
    --cc=linux-btrfs@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 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).