f2fs: fix error path when fail to read inline data
authorChao Yu <chao2.yu@samsung.com>
Sat, 29 Mar 2014 07:30:40 +0000 (15:30 +0800)
committerJaegeuk Kim <jaegeuk.kim@samsung.com>
Wed, 2 Apr 2014 00:56:27 +0000 (09:56 +0900)
We should unlock page in ->readpage() path and also should unlock & release page
in error path of ->write_begin() to avoid deadlock or memory leak.
So let's add release code to fix the problem when we fail to read inline data.

Signed-off-by: Chao Yu <chao2.yu@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
fs/f2fs/data.c
fs/f2fs/inline.c

index 598bfa617a7ec15c72165f54e58408eba6d5905f..45abd60e2bff54323139b037ed1bccd1e534e96e 100644 (file)
@@ -942,13 +942,19 @@ inline_data:
        if (dn.data_blkaddr == NEW_ADDR) {
                zero_user_segment(page, 0, PAGE_CACHE_SIZE);
        } else {
-               if (f2fs_has_inline_data(inode))
+               if (f2fs_has_inline_data(inode)) {
                        err = f2fs_read_inline_data(inode, page);
-               else
+                       if (err) {
+                               page_cache_release(page);
+                               return err;
+                       }
+               } else {
                        err = f2fs_submit_page_bio(sbi, page, dn.data_blkaddr,
                                                        READ_SYNC);
-               if (err)
-                       return err;
+                       if (err)
+                               return err;
+               }
+
                lock_page(page);
                if (unlikely(!PageUptodate(page))) {
                        f2fs_put_page(page, 1);
index 31ee5b164ff9f0ee27fa291bbd45df49e0da8d80..383db1fabcf4447637fd4153915e9512054b27ac 100644 (file)
@@ -45,8 +45,10 @@ int f2fs_read_inline_data(struct inode *inode, struct page *page)
        }
 
        ipage = get_node_page(sbi, inode->i_ino);
-       if (IS_ERR(ipage))
+       if (IS_ERR(ipage)) {
+               unlock_page(page);
                return PTR_ERR(ipage);
+       }
 
        zero_user_segment(page, MAX_INLINE_DATA, PAGE_CACHE_SIZE);