pstore: fix leaking ->i_private

From: Luck, Tony
Date: Fri Mar 18 2011 - 14:44:58 EST


From: Tony Luck <tony.luck@xxxxxxxxx>

Move kfree() of i_private out of ->unlink() and into ->evict_inode()

Signed-off-by: Tony Luck <tony.luck@xxxxxxxxx>

---

> Incidentally, you are leaking ->i_private on umount. You want ->evict_inode()
> doing that kfree(), not ->unlink(). And possibly ->erase() as well, with
> check for zero i_nlink around it (in ->evict_inode()).

I think this does what I want.

I only want to ->erase() the persistant store if there has been an unlink(2)
on the file. It looks to be safe and right to do this in ->unlink()

I don't think I need any checks on i_nlink - pstore filesystem won't let you
make extra links to a file.

end_writeback(inode) looks to be somewhat overkill, all I need is to set I_CLEAR
bit in ->i_state. But nobody else does this by hand, and the extra actions in
end_writeback() look to be harmless.

diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c
index 0834223..e8b0c08 100644
--- a/fs/pstore/inode.c
+++ b/fs/pstore/inode.c
@@ -73,11 +73,16 @@ static int pstore_unlink(struct inode *dir, struct dentry *dentry)
struct pstore_private *p = dentry->d_inode->i_private;

p->erase(p->id);
- kfree(p);

return simple_unlink(dir, dentry);
}

+static void pstore_evict_inode(struct inode *inode)
+{
+ kfree(inode->i_private);
+ end_writeback(inode);
+}
+
static const struct inode_operations pstore_dir_inode_operations = {
.lookup = simple_lookup,
.unlink = pstore_unlink,
@@ -110,6 +115,7 @@ static struct inode *pstore_get_inode(struct super_block *sb,
static const struct super_operations pstore_ops = {
.statfs = simple_statfs,
.drop_inode = generic_delete_inode,
+ .evict_inode = pstore_evict_inode,
.show_options = generic_show_options,
};

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/