Skip to content

Commit db23491

Browse files
committed
pstore: Convert "records_list" locking to mutex
The pstorefs internal list lock doesn't need to be a spinlock and will create problems when trying to access the list in the subsequent patch that will walk the pstorefs records during pstore_unregister(). Change this to a mutex to avoid may_sleep() warnings when unregistering devices. Link: https://lore.kernel.org/lkml/[email protected]/ Signed-off-by: Kees Cook <[email protected]>
1 parent 47af61f commit db23491

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

fs/pstore/inode.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@
2222
#include <linux/magic.h>
2323
#include <linux/pstore.h>
2424
#include <linux/slab.h>
25-
#include <linux/spinlock.h>
2625
#include <linux/uaccess.h>
2726

2827
#include "internal.h"
2928

3029
#define PSTORE_NAMELEN 64
3130

32-
static DEFINE_SPINLOCK(records_list_lock);
31+
static DEFINE_MUTEX(records_list_lock);
3332
static LIST_HEAD(records_list);
3433

3534
struct pstore_private {
@@ -192,13 +191,12 @@ static int pstore_unlink(struct inode *dir, struct dentry *dentry)
192191
static void pstore_evict_inode(struct inode *inode)
193192
{
194193
struct pstore_private *p = inode->i_private;
195-
unsigned long flags;
196194

197195
clear_inode(inode);
198196
if (p) {
199-
spin_lock_irqsave(&records_list_lock, flags);
197+
mutex_lock(&records_list_lock);
200198
list_del(&p->list);
201-
spin_unlock_irqrestore(&records_list_lock, flags);
199+
mutex_unlock(&records_list_lock);
202200
free_pstore_private(p);
203201
}
204202
}
@@ -297,12 +295,11 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)
297295
int rc = 0;
298296
char name[PSTORE_NAMELEN];
299297
struct pstore_private *private, *pos;
300-
unsigned long flags;
301298
size_t size = record->size + record->ecc_notice_size;
302299

303300
WARN_ON(!inode_is_locked(d_inode(root)));
304301

305-
spin_lock_irqsave(&records_list_lock, flags);
302+
mutex_lock(&records_list_lock);
306303
list_for_each_entry(pos, &records_list, list) {
307304
if (pos->record->type == record->type &&
308305
pos->record->id == record->id &&
@@ -311,7 +308,7 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)
311308
break;
312309
}
313310
}
314-
spin_unlock_irqrestore(&records_list_lock, flags);
311+
mutex_unlock(&records_list_lock);
315312
if (rc)
316313
return rc;
317314

@@ -343,9 +340,9 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)
343340

344341
d_add(dentry, inode);
345342

346-
spin_lock_irqsave(&records_list_lock, flags);
343+
mutex_lock(&records_list_lock);
347344
list_add(&private->list, &records_list);
348-
spin_unlock_irqrestore(&records_list_lock, flags);
345+
mutex_unlock(&records_list_lock);
349346

350347
return 0;
351348

0 commit comments

Comments
 (0)