mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH] fs: ramfs: Free data when file is unlinked
Date: Wed, 26 Sep 2018 09:56:25 +0200	[thread overview]
Message-ID: <20180926075625.444-1-s.hauer@pengutronix.de> (raw)

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

                 reply	other threads:[~2018-09-26  7:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180926075625.444-1-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox