Skip to content

Commit 56d2ca0

Browse files
authored
Merge pull request #53 from RoyWFHuang/master
Fix sb_read and umount cache not be freed
2 parents 403e1b8 + cc21eee commit 56d2ca0

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

dir.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ static int simplefs_iterate(struct file *dir, struct dir_context *ctx)
6060
goto release_bh;
6161
}
6262
dblock = (struct simplefs_dir_block *) bh2->b_data;
63-
if (dblock->files[0].inode == 0)
63+
if (dblock->files[0].inode == 0) {
64+
brelse(bh2);
65+
bh2 = NULL;
6466
break;
65-
67+
}
6668
/* Iterate every file in one block */
6769
for (; fi < SIMPLEFS_FILES_PER_BLOCK; fi++) {
6870
f = &dblock->files[fi];

fs.c

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ static int __init simplefs_init(void)
5858

5959
err_inode:
6060
simplefs_destroy_inode_cache();
61+
/* Only after rcu_barrier() is the memory guaranteed to be freed. */
62+
rcu_barrier();
6163
err:
6264
return ret;
6365
}
@@ -69,6 +71,8 @@ static void __exit simplefs_exit(void)
6971
pr_err("Failed to unregister file system\n");
7072

7173
simplefs_destroy_inode_cache();
74+
/* Only after rcu_barrier() is the memory guaranteed to be freed. */
75+
rcu_barrier();
7276

7377
pr_info("module unloaded\n");
7478
}

inode.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,8 @@ static int simplefs_rename(struct inode *old_dir,
749749
break;
750750
}
751751
}
752-
if (new_pos < 0)
753-
brelse(bh2);
752+
753+
brelse(bh2);
754754
}
755755
}
756756

super.c

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ int simplefs_init_inode_cache(void)
3737
/* De-allocate the inode cache */
3838
void simplefs_destroy_inode_cache(void)
3939
{
40+
/* wait for call_rcu() and prevent the free cache be used */
41+
rcu_barrier();
42+
4043
kmem_cache_destroy(simplefs_inode_cache);
4144
}
4245

0 commit comments

Comments
 (0)