[PATCH] fs: ramfs: Free data when file is unlinked

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Since the switch to dentry cache implementation the memory is no
longer freed when a file in ramfs is deleted. Fix this.

Fixes: b283b72639 ("fs: ramfs: Switch to dentry cache implementation")

Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
---
 fs/ramfs.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/fs/ramfs.c b/fs/ramfs.c
index 7548bdac9f..09dafe02ae 100644
--- a/fs/ramfs.c
+++ b/fs/ramfs.c
@@ -176,6 +176,28 @@ static int ramfs_symlink(struct inode *dir, struct dentry *dentry,
 	return 0;
 }
 
+static int ramfs_unlink(struct inode *dir, struct dentry *dentry)
+{
+	struct inode *inode = d_inode(dentry);
+
+	if (inode) {
+		struct ramfs_inode *node = to_ramfs_inode(inode);
+		struct ramfs_chunk *chunk = node->data;
+
+		node->data = NULL;
+
+		while (chunk) {
+			struct ramfs_chunk *tmp = chunk;
+
+			chunk = chunk->next;
+
+			ramfs_put_chunk(tmp);
+		}
+	}
+
+	return simple_unlink(dir, dentry);
+}
+
 static const char *ramfs_get_link(struct dentry *dentry, struct inode *inode)
 {
 	return inode->i_link;
@@ -192,7 +214,7 @@ static const struct inode_operations ramfs_dir_inode_operations =
 	.symlink = ramfs_symlink,
 	.mkdir = ramfs_mkdir,
 	.rmdir = simple_rmdir,
-	.unlink = simple_unlink,
+	.unlink = ramfs_unlink,
 	.create = ramfs_create,
 };
 
-- 
2.19.0


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux