mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] fs: ramfs: Free data when file is unlinked
@ 2018-09-26  7:56 Sascha Hauer
  0 siblings, 0 replies; only message in thread
From: Sascha Hauer @ 2018-09-26  7:56 UTC (permalink / raw)
  To: Barebox List

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@pengutronix.de>
---
 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@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-09-26  7:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-26  7:56 [PATCH] fs: ramfs: Free data when file is unlinked Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox