Skip to contentSkip to conversation

btrfs: fix btrfs_cont_expand() freeing IS_ERR em

PATCH In review Zach Brown 2 participants 3 messages Jan 8, 2013 Btrfs file system

lore
Share & tools
lore

Zach Brown

author
#0 lore raw

PATCH 1/1 btrfs: fix btrfs_cont_expand() freeing IS_ERR em

btrfs_cont_expand() tries to free an IS_ERR em as it gets an error from btrfs_get_extent() and breaks out of its loop.

An instance of -EEXIST was reported in the wild:

https://bugzilla.redhat.com/show_bug.cgi?id=874407

I have no idea if that -EEXIST is surprising, or not. Regardless, this error handling should be cleaned up to handle other reasonable errors (ENOMEM, EIO; whatever).

This seemed to be the only buggy freeing of the relatively rare IS_ERR em so I opted to fix the caller rather than teach free_extent_map() to use IS_ERR_OR_NULL().

---
 fs/btrfs/inode.c | 1 +
 1 file changed, 1 insertion(+)
fs/btrfs/inode.c +1 -0
index edd30ae..0bc7bb3 100644
@@ -3690,6 +3690,7 @@ int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size)
 				block_end - cur_offset, 0);
 		if (IS_ERR(em)) {
 			err = PTR_ERR(em);
+			em = NULL;
 			break;
 		}
 		last_byte = min(extent_map_end(em), block_end);
Signature · 6 lines
1.7.11.7

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Zach Brown

btrfs_cont_expand() tries to free an IS_ERR em as it gets an error from btrfs_get_extent() and breaks out of its loop.

An instance of -EEXIST was reported in the wild:

https://bugzilla.redhat.com/show_bug.cgi?id=874407

I have no idea if that -EEXIST is surprising, or not. Regardless, this error handling should be cleaned up to handle other reasonable errors (ENOMEM, EIO; whatever).

Quoted 5 lines

This seemed to be the only buggy freeing of the relatively rare IS_ERR em so I opted to fix the caller rather than teach free_extent_map() to use IS_ERR_OR_NULL().

Looks good (maybe IS_ERR_OR_NULL would be more future-proof, but *shrug*)

Quoted 17 lines
---
 fs/btrfs/inode.c | 1 +
 1 file changed, 1 insertion(+)
fs/btrfs/inode.c +1 -0
index edd30ae..0bc7bb3 100644
@@ -3690,6 +3690,7 @@ int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size)
 				block_end - cur_offset, 0);
 		if (IS_ERR(em)) {
 			err = PTR_ERR(em);
+			em = NULL;
 			break;
 		}
 		last_byte = min(extent_map_end(em), block_end);
author
#2 lore raw
Quoted 1 line

Looks good (maybe IS_ERR_OR_NULL would be more future-proof, but *shrug*)

Yeah. I don't feel strongly about it. I'm happy to do that, and dance around the tree pulling out redundant 'em = NULL' bits that wouldn't be needed, if anyone feels strongly about it.

- z
(*shrug*)