summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2018-09-26 09:51:04 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2018-09-26 09:54:30 +0200
commita4514478e6a20edf70537af15fbffbfb1bc5982b (patch)
tree5cd404e0457a3fee1262889ad42c22ea34604324 /fs
parentf70141447cf1aedd77a40d8bf76657927bb73840 (diff)
downloadbarebox-a4514478e6a20edf70537af15fbffbfb1bc5982b.tar.gz
barebox-a4514478e6a20edf70537af15fbffbfb1bc5982b.tar.xz
fs: ramfs: Free data when file is unlinked
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>
Diffstat (limited to 'fs')
-rw-r--r--fs/ramfs.c24
1 files changed, 23 insertions, 1 deletions
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,
};