Skip to content

Commit 24a0b5e

Browse files
committed
pstore: inode: Use cleanup.h for struct pstore_private
Simplify error path when "private" 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 b775a05 commit 24a0b5e

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

fs/pstore/inode.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ static void free_pstore_private(struct pstore_private *private)
6363
}
6464
kfree(private);
6565
}
66+
DEFINE_FREE(pstore_private, struct pstore_private *, free_pstore_private(_T));
6667

6768
static void *pstore_ftrace_seq_start(struct seq_file *s, loff_t *pos)
6869
{
@@ -340,9 +341,8 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)
340341
{
341342
struct dentry *dentry;
342343
struct inode *inode __free(pstore_iput) = NULL;
343-
int rc = 0;
344344
char name[PSTORE_NAMELEN];
345-
struct pstore_private *private, *pos;
345+
struct pstore_private *private __free(pstore_private) = NULL, *pos;
346346
size_t size = record->size + record->ecc_notice_size;
347347

348348
if (WARN_ON(!inode_is_locked(d_inode(root))))
@@ -358,7 +358,6 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)
358358
return -EEXIST;
359359
}
360360

361-
rc = -ENOMEM;
362361
inode = pstore_get_inode(root->d_sb);
363362
if (!inode)
364363
return -ENOMEM;
@@ -375,7 +374,7 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)
375374

376375
dentry = d_alloc_name(root, name);
377376
if (!dentry)
378-
goto fail_private;
377+
return -ENOMEM;
379378

380379
private->dentry = dentry;
381380
private->record = record;
@@ -388,13 +387,9 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)
388387

389388
d_add(dentry, no_free_ptr(inode));
390389

391-
list_add(&private->list, &records_list);
390+
list_add(&(no_free_ptr(private))->list, &records_list);
392391

393392
return 0;
394-
395-
fail_private:
396-
free_pstore_private(private);
397-
return rc;
398393
}
399394

400395
/*

0 commit comments

Comments
 (0)