[PATCH 2/8] mtd_blkdevs: use lockdep_assert_held

Christoph Hellwig
2021-08-23T07:37:02Z

Use lockdep_assert_held to ensure mtd_table_mutex is held instead of
mutex_trylock games.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/mtd/mtd_blkdevs.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index 6b81a1c9ccbe..81f0ce2a0b5a 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -310,10 +310,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
struct gendisk *gd;
int ret;

- if (mutex_trylock(&mtd_table_mutex)) {
- mutex_unlock(&mtd_table_mutex);
- BUG();
- }
+ lockdep_assert_held(&mtd_table_mutex);

mutex_lock(&blktrans_ref_mutex);
list_for_each_entry(d, &tr->devs, list) {
@@ -444,10 +441,7 @@ int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)
{
unsigned long flags;

- if (mutex_trylock(&mtd_table_mutex)) {
- mutex_unlock(&mtd_table_mutex);
- BUG();
- }
+ lockdep_assert_held(&mtd_table_mutex);

if (old->disk_attributes)
sysfs_remove_group(&disk_to_dev(old->disk)->kobj,
--
2.30.2