Skip to contentSkip to conversation

fs/affs/file.c: unlock/release page on error

PATCH In review Taesoo Kim 2 participants 2 messages Mar 20, 2015

Subsystems (2)
lore
Share & tools
lore

Taesoo Kim

author
#0 lore raw

PATCH 1/1 fs/affs/file.c: unlock/release page on error

When affs_bread_ino() fails, correctly unlock the page and release the page cache with proper error value. All write_end() should unlock/release the page that was locked by write_beg().

---
 fs/affs/file.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
fs/affs/file.c +9 -4
index d2468bf..15d07a0 100644
@@ -699,8 +699,10 @@ static int affs_write_end_ofs(struct file *file, struct address_space *mapping,
 	boff = tmp % bsize;
 	if (boff) {
 		bh = affs_bread_ino(inode, bidx, 0);
-		if (IS_ERR(bh))
-			return PTR_ERR(bh);
+		if (IS_ERR(bh)) {
+			written = PTR_ERR(bh);
+			goto err;
+		}
 		tmp = min(bsize - boff, to - from);
 		BUG_ON(boff + tmp > bsize || tmp > bsize);
 		memcpy(AFFS_DATA(bh) + boff, data + from, tmp);
@@ -712,8 +714,10 @@ static int affs_write_end_ofs(struct file *file, struct address_space *mapping,
 		bidx++;
 	} else if (bidx) {
 		bh = affs_bread_ino(inode, bidx - 1, 0);
-		if (IS_ERR(bh))
-			return PTR_ERR(bh);
+		if (IS_ERR(bh)) {
+			written = PTR_ERR(bh);
+			goto err;
+		}
 	}
 	while (from + bsize <= to) {
 		prev_bh = bh;
@@ -790,6 +794,7 @@ done:
 	if (tmp > inode->i_size)
 		inode->i_size = AFFS_I(inode)->mmu_private = tmp;
 
+err:
 	unlock_page(page);
 	page_cache_release(page);
 
Signature · 1 line
2.3.3
#1 lore raw
Quoted 49 lines · On 20 March 2015 at 04:19 Taesoo Kim <[email protected]> wrote:

When affs_bread_ino() fails, correctly unlock the page and release the page cache with proper error value. All write_end() should unlock/release the page that was locked by write_beg().

---
  fs/affs/file.c | 13 +++++++++----

  1 file changed, 9 insertions(+), 4 deletions(-)
fs/affs/file.c +4 -2
index d2468bf..15d07a0 100644
@@ -699,8 +699,10 @@ static int affs_write_end_ofs(struct file *file, struct
 address_space *mapping,
        boff = tmp % bsize;
        if (boff) {
                bh = affs_bread_ino(inode, bidx, 0);
-             if (IS_ERR(bh))
-                     return PTR_ERR(bh);
+             if (IS_ERR(bh)) {
+                     written = PTR_ERR(bh);
+                     goto err;
+             }
                tmp = min(bsize - boff, to - from);
                BUG_ON(boff + tmp > bsize || tmp > bsize);

               memcpy(AFFS_DATA(bh) + boff, data + from, tmp);

fs/affs/file.c +4 -2
@@ -712,8 +714,10 @@ static int affs_write_end_ofs(struct file *file, struct
 address_space *mapping,
                bidx++;
        } else if (bidx) {
                bh = affs_bread_ino(inode, bidx - 1, 0);
-             if (IS_ERR(bh))
-                     return PTR_ERR(bh);
+             if (IS_ERR(bh)) {
+                     written = PTR_ERR(bh);
+                     goto err;
+             }
        }
        while (from + bsize <= to) {

               prev_bh = bh;

fs/affs/file.c +0 -0
@@ -790,6 +794,7 @@ done:
        if (tmp > inode->i_size)
                inode->i_size = AFFS_I(inode)->mmu_private = tmp;
Quoted 8 lines


+err:
       unlock_page(page);
       page_cache_release(page);

--
2.3.3

Patch looks good. Maybe you could use more explicit labels like

err_first_bh instead of err
err_bh instead of out

Regards,
Fabian