linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Fix btrfs_file_llseek() to return -EINVAL directly
@ 2011-08-29  9:48 Jeff Liu
  2011-08-30  3:59 ` Jeff Liu
  0 siblings, 1 reply; 2+ messages in thread
From: Jeff Liu @ 2011-08-29  9:48 UTC (permalink / raw)
  To: linux-btrfs; +Cc: chris.mason

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) {


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-08-30  3:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-29  9:48 Fix btrfs_file_llseek() to return -EINVAL directly Jeff Liu
2011-08-30  3:59 ` Jeff Liu

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).