diff options
author | Kees Cook <keescook@chromium.org> | 2023-12-05 10:26:16 -0800 |
---|---|---|
committer | Kees Cook <keescook@chromium.org> | 2023-12-08 14:15:44 -0800 |
commit | b775a054e9dcd4ca20d56367b3d39b3d69e50a46 (patch) | |
tree | 3bcca5d24c4235a2497caceff224332d6cd9f923 /fs/pstore | |
parent | e2eeddefb046dbc771a6fa426f7f98fb25adfe68 (diff) |
pstore: inode: Use __free(pstore_iput) for inode allocations
Simplify error path for failures where "inode" needs to be freed.
Cc: Guilherme G. Piccoli <gpiccoli@igalia.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: <linux-hardening@vger.kernel.org>
Link: https://lore.kernel.org/r/20231205182622.1329923-3-keescook@chromium.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Diffstat (limited to 'fs/pstore')
-rw-r--r-- | fs/pstore/inode.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c index 0d89e0014b6f..a27764341079 100644 --- a/fs/pstore/inode.c +++ b/fs/pstore/inode.c @@ -35,6 +35,8 @@ static LIST_HEAD(records_list); static DEFINE_MUTEX(pstore_sb_lock); static struct super_block *pstore_sb; +DEFINE_FREE(pstore_iput, struct inode *, if (_T) iput(_T)) + struct pstore_private { struct list_head list; struct dentry *dentry; @@ -337,7 +339,7 @@ int pstore_put_backend_records(struct pstore_info *psi) int pstore_mkfile(struct dentry *root, struct pstore_record *record) { struct dentry *dentry; - struct inode *inode; + struct inode *inode __free(pstore_iput) = NULL; int rc = 0; char name[PSTORE_NAMELEN]; struct pstore_private *private, *pos; @@ -369,7 +371,7 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) private = kzalloc(sizeof(*private), GFP_KERNEL); if (!private) - goto fail_inode; + return -ENOMEM; dentry = d_alloc_name(root, name); if (!dentry) @@ -384,7 +386,7 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) inode_set_mtime_to_ts(inode, inode_set_ctime_to_ts(inode, record->time)); - d_add(dentry, inode); + d_add(dentry, no_free_ptr(inode)); list_add(&private->list, &records_list); @@ -392,8 +394,6 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) fail_private: free_pstore_private(private); -fail_inode: - iput(inode); return rc; } |