Skip to content

Commit 520886a

Browse files
r1chard-lyumiquelraynal
authored andcommitted
mtd: nand: Use scoped_guard for mutex in nand_resume
Refactor nand_resume() to use scoped_guard() instead of explicit mutex_lock/unlock. This improves code safety by ensuring the mutex is always released through the RAII-based cleanup infrastructure. The behavior is functionally equivalent. The mutex is released at the end of the scoped block, after which wake_up_all() is called to preserve the original locking semantics. Signed-off-by: Richard Lyu <richard.lyu@suse.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent d9a2a92 commit 520886a

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

drivers/mtd/nand/raw/nand_base.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <linux/mtd/partitions.h>
4444
#include <linux/of.h>
4545
#include <linux/gpio/consumer.h>
46+
#include <linux/cleanup.h>
4647

4748
#include "internals.h"
4849

@@ -4704,16 +4705,16 @@ static void nand_resume(struct mtd_info *mtd)
47044705
{
47054706
struct nand_chip *chip = mtd_to_nand(mtd);
47064707

4707-
mutex_lock(&chip->lock);
4708-
if (chip->suspended) {
4709-
if (chip->ops.resume)
4710-
chip->ops.resume(chip);
4711-
chip->suspended = 0;
4712-
} else {
4713-
pr_err("%s called for a chip which is not in suspended state\n",
4714-
__func__);
4708+
scoped_guard(mutex, &chip->lock) {
4709+
if (chip->suspended) {
4710+
if (chip->ops.resume)
4711+
chip->ops.resume(chip);
4712+
chip->suspended = 0;
4713+
} else {
4714+
pr_err("%s called for a chip which is not in suspended state\n",
4715+
__func__);
4716+
}
47154717
}
4716-
mutex_unlock(&chip->lock);
47174718

47184719
wake_up_all(&chip->resume_wq);
47194720
}

0 commit comments

Comments
 (0)