VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   35 Branches   59 Tags
author: Muchun Song <songmuchun@bytedance.com> 2021-04-02 17:11:45 +0800 committer: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 2021-07-14 17:07:23 +0200 commit: cae2f265c5a94019caf25019be946fd46a11aeff parent: 6eeb73fa1492a66a8c095bf69aa3355d2430e4b0
Commit Summary:
writeback: fix obtain a reference to a freeing memcg css
Diffstat:
1 file changed, 6 insertions, 2 deletions
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index d684f541af48..8d4130b01423 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -510,9 +510,14 @@ static void inode_switch_wbs(struct inode *inode, int new_wb_id)
 	/* find and pin the new wb */
 	rcu_read_lock();
 	memcg_css = css_from_id(new_wb_id, &memory_cgrp_subsys);
-	if (memcg_css)
-		isw->new_wb = wb_get_create(bdi, memcg_css, GFP_ATOMIC);
+	if (memcg_css && !css_tryget(memcg_css))
+		memcg_css = NULL;
 	rcu_read_unlock();
+	if (!memcg_css)
+		goto out_free;
+
+	isw->new_wb = wb_get_create(bdi, memcg_css, GFP_ATOMIC);
+	css_put(memcg_css);
 	if (!isw->new_wb)
 		goto out_free;