summaryrefslogtreecommitdiffstats
path: root/fs/ext4/ext4.h
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2014-09-01 14:34:09 -0400
committerTheodore Ts'o <tytso@mit.edu>2014-09-01 14:34:09 -0400
commit705912ca95f4bbdbb3be753e46bf30d6be15a5e8 (patch)
tree39b983f9ac9964104cf1475e31631b6dd554c728 /fs/ext4/ext4.h
parentbd30d702fc320085f178d22866b32fdc4736c991 (diff)
ext4: teach ext4_ext_find_extent() to free path on error
Right now, there are a places where it is all to easy to leak memory on an error path, via a usage like this: struct ext4_ext_path *path = NULL while (...) { ... path = ext4_ext_find_extent(inode, block, path, 0); if (IS_ERR(path)) { /* oops, if path was non-NULL before the call to ext4_ext_find_extent, we've leaked it! :-( */ ... return PTR_ERR(path); } ... } Unfortunately, there some code paths where we are doing the following instead: path = ext4_ext_find_extent(inode, block, orig_path, 0); and where it's important that we _not_ free orig_path in the case where ext4_ext_find_extent() returns an error. So change the function signature of ext4_ext_find_extent() so that it takes a struct ext4_ext_path ** for its third argument, and by default, on an error, it will free the struct ext4_ext_path, and then zero out the struct ext4_ext_path * pointer. In order to avoid causing problems, we add a flag EXT4_EX_NOFREE_ON_ERR which causes ext4_ext_find_extent() to use the original behavior of forcing the caller to deal with freeing the original path pointer on the error case. The goal is to get rid of EXT4_EX_NOFREE_ON_ERR entirely, but this allows for a gentle transition and makes the patches easier to verify. Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'fs/ext4/ext4.h')
-rw-r--r--fs/ext4/ext4.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 550b4f99a843..696e51ae02fa 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -582,6 +582,7 @@ enum {
582 */ 582 */
583#define EXT4_EX_NOCACHE 0x0800 583#define EXT4_EX_NOCACHE 0x0800
584#define EXT4_EX_FORCE_CACHE 0x1000 584#define EXT4_EX_FORCE_CACHE 0x1000
585#define EXT4_EX_NOFREE_ON_ERR 0x2000
585 586
586/* 587/*
587 * Flags used by ext4_free_blocks 588 * Flags used by ext4_free_blocks
@@ -2733,7 +2734,7 @@ extern int ext4_ext_insert_extent(handle_t *, struct inode *,
2733 struct ext4_ext_path *, 2734 struct ext4_ext_path *,
2734 struct ext4_extent *, int); 2735 struct ext4_extent *, int);
2735extern struct ext4_ext_path *ext4_ext_find_extent(struct inode *, ext4_lblk_t, 2736extern struct ext4_ext_path *ext4_ext_find_extent(struct inode *, ext4_lblk_t,
2736 struct ext4_ext_path *, 2737 struct ext4_ext_path **,
2737 int flags); 2738 int flags);
2738extern void ext4_ext_drop_refs(struct ext4_ext_path *); 2739extern void ext4_ext_drop_refs(struct ext4_ext_path *);
2739extern int ext4_ext_check_inode(struct inode *inode); 2740extern int ext4_ext_check_inode(struct inode *inode);