Skip to contentSkip to conversation

btrfs: check return value of filemap_fdatawrite_range()

PATCH In review Alex Dewar 3 participants 3 messages Aug 21, 2020 Btrfs file system

lore
Share & tools
lore

Alex Dewar

author
#0 lore raw

PATCH 1/1 btrfs: check return value of filemap_fdatawrite_range()

In btrfs_dio_imap_begin(), filemap_fdatawrite_range() is called without checking the return value. Add a check to catch errors.

Fixes c0aaf9b7a114f ("btrfs: switch to iomap_dio_rw() for dio")

Addresses-Coverity: ("Unused value")

---
 fs/btrfs/inode.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/btrfs/inode.c +4 -1
index 7b57aaa1f9acc..38fde20b4a81b 100644
@@ -7347,9 +7347,12 @@ static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start,
 	 * outstanding dirty pages are on disk.
 	 */
 	if (test_bit(BTRFS_INODE_HAS_ASYNC_EXTENT,
-		     &BTRFS_I(inode)->runtime_flags))
+		     &BTRFS_I(inode)->runtime_flags)) {
 		ret = filemap_fdatawrite_range(inode->i_mapping, start,
 					       start + length - 1);
+		if (ret)
+			return ret;
+	}
 
 	dio_data = kzalloc(sizeof(*dio_data), GFP_NOFS);
 	if (!dio_data)
Signature · 1 line
2.28.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 19 lines · Alex Dewar

In btrfs_dio_imap_begin(), filemap_fdatawrite_range() is called without checking the return value. Add a check to catch errors.

Fixes c0aaf9b7a114f ("btrfs: switch to iomap_dio_rw() for dio")

Addresses-Coverity: ("Unused value")

---
  fs/btrfs/inode.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
fs/btrfs/inode.c +0 -0
index 7b57aaa1f9acc..38fde20b4a81b 100644
@@ -7347,9 +7347,12 @@ static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start,
  	 * outstanding dirty pages are on disk.
  	 */
  	if (test_bit(BTRFS_INODE_HAS_ASYNC_EXTENT,

fs/btrfs/inode.c static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start, · line 7358

Quoted 10 lines
fs/btrfs/inode.c +4 -1
-		     &BTRFS_I(inode)->runtime_flags))
+		     &BTRFS_I(inode)->runtime_flags)) {
  		ret = filemap_fdatawrite_range(inode->i_mapping, start,
  					       start + length - 1);
+		if (ret)
+			return ret;
+	}
 
  	dio_data = kzalloc(sizeof(*dio_data), GFP_NOFS);
  	if (!dio_data)

Had to check to make sure there's no cleanup that's needed, there isn't, you can add

Thanks,

Josef

#2 lore raw
In reply to Alex Dewar
Quoted 6 lines · Alex Dewar

In btrfs_dio_imap_begin(), filemap_fdatawrite_range() is called without checking the return value. Add a check to catch errors.

Fixes c0aaf9b7a114f ("btrfs: switch to iomap_dio_rw() for dio")

Addresses-Coverity: ("Unused value")

Folded to the patch, thanks.