Skip to content

Commit 6ba6ee8

Browse files
committed
pstore: inode: Convert kfree() usage to __free(kfree)
Mostly as an example to myself, replace a simple allocation pattern with the automatic kfree cleanup features now exposed by cleanup.h. 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 86222a8 commit 6ba6ee8

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

fs/pstore/inode.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/pstore.h>
2424
#include <linux/slab.h>
2525
#include <linux/uaccess.h>
26+
#include <linux/cleanup.h>
2627

2728
#include "internal.h"
2829

@@ -64,21 +65,18 @@ static void free_pstore_private(struct pstore_private *private)
6465
static void *pstore_ftrace_seq_start(struct seq_file *s, loff_t *pos)
6566
{
6667
struct pstore_private *ps = s->private;
67-
struct pstore_ftrace_seq_data *data;
68+
struct pstore_ftrace_seq_data *data __free(kfree) = NULL;
6869

6970
data = kzalloc(sizeof(*data), GFP_KERNEL);
7071
if (!data)
7172
return NULL;
7273

7374
data->off = ps->total_size % REC_SIZE;
7475
data->off += *pos * REC_SIZE;
75-
if (data->off + REC_SIZE > ps->total_size) {
76-
kfree(data);
76+
if (data->off + REC_SIZE > ps->total_size)
7777
return NULL;
78-
}
79-
80-
return data;
8178

79+
return_ptr(data);
8280
}
8381

8482
static void pstore_ftrace_seq_stop(struct seq_file *s, void *v)

0 commit comments

Comments
 (0)