linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kernfs: fix a subdir count leak
@ 2014-04-17  9:52 Jianyu Zhan
  2014-04-17 13:19 ` Tejun Heo
  0 siblings, 1 reply; 2+ messages in thread
From: Jianyu Zhan @ 2014-04-17  9:52 UTC (permalink / raw)
  To: gregkh, tj; +Cc: linux-kernel, nasa4836

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>
---
 fs/kernfs/dir.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index 78f3403..ac127cd 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -232,9 +232,6 @@ static int kernfs_link_sibling(struct kernfs_node *kn)
 	struct rb_node **node = &kn->parent->dir.children.rb_node;
 	struct rb_node *parent = NULL;
 
-	if (kernfs_type(kn) == KERNFS_DIR)
-		kn->parent->dir.subdirs++;
-
 	while (*node) {
 		struct kernfs_node *pos;
 		int result;
@@ -249,9 +246,15 @@ static int kernfs_link_sibling(struct kernfs_node *kn)
 		else
 			return -EEXIST;
 	}
+
 	/* add new node and rebalance the tree */
 	rb_link_node(&kn->rb, parent, node);
 	rb_insert_color(&kn->rb, &kn->parent->dir.children);
+
+	/* successfully added, account subdir number */
+	if (kernfs_type(kn) == KERNFS_DIR)
+		kn->parent->dir.subdirs++;
+
 	return 0;
 }
 
-- 
1.9.0.GIT


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] kernfs: fix a subdir count leak
  2014-04-17  9:52 [PATCH] kernfs: fix a subdir count leak Jianyu Zhan
@ 2014-04-17 13:19 ` Tejun Heo
  0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2014-04-17 13:19 UTC (permalink / raw)
  To: Jianyu Zhan; +Cc: gregkh, linux-kernel

On Thu, Apr 17, 2014 at 05:52:10PM +0800, Jianyu Zhan wrote:
> 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>

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-04-17 13:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-17  9:52 [PATCH] kernfs: fix a subdir count leak Jianyu Zhan
2014-04-17 13:19 ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).