diff options
author | Jianyu Zhan <nasa4836@gmail.com> | 2014-04-17 05:52:10 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-04-25 15:25:13 -0400 |
commit | c1befb885939cdaaf420c10bbe9ff57aa00446ea (patch) | |
tree | e46f5797e3b17838b41f874f70facaf7b52bfea5 | |
parent | a798c10faf62a505d24e5f6213fbaf904a39623f (diff) |
kernfs: fix a subdir count leak
Currently kernfs_link_sibling() increates parent->dir.subdirs before
adding the node into parent's chidren rb tree.
Because it is possible that kernfs_link_sibling() couldn't find
a suitable slot and bail out, this leads to a mismatch between
elevated subdir count with actual children node numbers.
This patches fix this problem, by moving the subdir accouting
after the actual addtion happening.
Signed-off-by: Jianyu Zhan <nasa4836@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | fs/kernfs/dir.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c index 78f3403300af..ac127cd008bf 100644 --- a/fs/kernfs/dir.c +++ b/fs/kernfs/dir.c | |||
@@ -232,9 +232,6 @@ static int kernfs_link_sibling(struct kernfs_node *kn) | |||
232 | struct rb_node **node = &kn->parent->dir.children.rb_node; | 232 | struct rb_node **node = &kn->parent->dir.children.rb_node; |
233 | struct rb_node *parent = NULL; | 233 | struct rb_node *parent = NULL; |
234 | 234 | ||
235 | if (kernfs_type(kn) == KERNFS_DIR) | ||
236 | kn->parent->dir.subdirs++; | ||
237 | |||
238 | while (*node) { | 235 | while (*node) { |
239 | struct kernfs_node *pos; | 236 | struct kernfs_node *pos; |
240 | int result; | 237 | int result; |
@@ -249,9 +246,15 @@ static int kernfs_link_sibling(struct kernfs_node *kn) | |||
249 | else | 246 | else |
250 | return -EEXIST; | 247 | return -EEXIST; |
251 | } | 248 | } |
249 | |||
252 | /* add new node and rebalance the tree */ | 250 | /* add new node and rebalance the tree */ |
253 | rb_link_node(&kn->rb, parent, node); | 251 | rb_link_node(&kn->rb, parent, node); |
254 | rb_insert_color(&kn->rb, &kn->parent->dir.children); | 252 | rb_insert_color(&kn->rb, &kn->parent->dir.children); |
253 | |||
254 | /* successfully added, account subdir number */ | ||
255 | if (kernfs_type(kn) == KERNFS_DIR) | ||
256 | kn->parent->dir.subdirs++; | ||
257 | |||
255 | return 0; | 258 | return 0; |
256 | } | 259 | } |
257 | 260 | ||