Skip to content

Commit b775a05

Browse files
committed
pstore: inode: Use __free(pstore_iput) for inode allocations
Simplify error path for failures where "inode" needs to be freed. Cc: Guilherme G. Piccoli <[email protected]> Cc: Tony Luck <[email protected]> Cc: <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent e2eedde commit b775a05

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

fs/pstore/inode.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ static LIST_HEAD(records_list);
3535
static DEFINE_MUTEX(pstore_sb_lock);
3636
static struct super_block *pstore_sb;
3737

38+
DEFINE_FREE(pstore_iput, struct inode *, if (_T) iput(_T))
39+
3840
struct pstore_private {
3941
struct list_head list;
4042
struct dentry *dentry;
@@ -337,7 +339,7 @@ int pstore_put_backend_records(struct pstore_info *psi)
337339
int pstore_mkfile(struct dentry *root, struct pstore_record *record)
338340
{
339341
struct dentry *dentry;
340-
struct inode *inode;
342+
struct inode *inode __free(pstore_iput) = NULL;
341343
int rc = 0;
342344
char name[PSTORE_NAMELEN];
343345
struct pstore_private *private, *pos;
@@ -369,7 +371,7 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)
369371

370372
private = kzalloc(sizeof(*private), GFP_KERNEL);
371373
if (!private)
372-
goto fail_inode;
374+
return -ENOMEM;
373375

374376
dentry = d_alloc_name(root, name);
375377
if (!dentry)
@@ -384,16 +386,14 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)
384386
inode_set_mtime_to_ts(inode,
385387
inode_set_ctime_to_ts(inode, record->time));
386388

387-
d_add(dentry, inode);
389+
d_add(dentry, no_free_ptr(inode));
388390

389391
list_add(&private->list, &records_list);
390392

391393
return 0;
392394

393395
fail_private:
394396
free_pstore_private(private);
395-
fail_inode:
396-
iput(inode);
397397
return rc;
398398
}
399399

0 commit comments

Comments
 (0)