Skip to content

Commit 7a0ad54

Browse files
committed
pstore: Refactor pstorefs record list removal
The "unlink" handling should perform list removal (which can also make sure records don't get double-erased), and the "evict" handling should be responsible only for memory freeing. Link: https://lore.kernel.org/lkml/[email protected]/ Signed-off-by: Kees Cook <[email protected]>
1 parent 6248a06 commit 7a0ad54

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

fs/pstore/inode.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,21 @@ static int pstore_unlink(struct inode *dir, struct dentry *dentry)
177177
{
178178
struct pstore_private *p = d_inode(dentry)->i_private;
179179
struct pstore_record *record = p->record;
180+
int rc = 0;
180181

181182
if (!record->psi->erase)
182183
return -EPERM;
183184

185+
/* Make sure we can't race while removing this file. */
186+
mutex_lock(&records_list_lock);
187+
if (!list_empty(&p->list))
188+
list_del_init(&p->list);
189+
else
190+
rc = -ENOENT;
191+
mutex_unlock(&records_list_lock);
192+
if (rc)
193+
return rc;
194+
184195
mutex_lock(&record->psi->read_mutex);
185196
record->psi->erase(record);
186197
mutex_unlock(&record->psi->read_mutex);
@@ -193,12 +204,7 @@ static void pstore_evict_inode(struct inode *inode)
193204
struct pstore_private *p = inode->i_private;
194205

195206
clear_inode(inode);
196-
if (p) {
197-
mutex_lock(&records_list_lock);
198-
list_del(&p->list);
199-
mutex_unlock(&records_list_lock);
200-
free_pstore_private(p);
201-
}
207+
free_pstore_private(p);
202208
}
203209

204210
static const struct inode_operations pstore_dir_inode_operations = {
@@ -417,6 +423,7 @@ static void pstore_kill_sb(struct super_block *sb)
417423
{
418424
kill_litter_super(sb);
419425
pstore_sb = NULL;
426+
INIT_LIST_HEAD(&records_list);
420427
}
421428

422429
static struct file_system_type pstore_fs_type = {

0 commit comments

Comments
 (0)