drivers/mtd/nand/raw/nand_base.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
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>
---
drivers/mtd/nand/raw/nand_base.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 770c26f9c6ce..9e3561f34ea8 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -43,6 +43,7 @@
#include <linux/mtd/partitions.h>
#include <linux/of.h>
#include <linux/gpio/consumer.h>
+#include <linux/cleanup.h>
#include "internals.h"
@@ -4704,16 +4705,16 @@ static void nand_resume(struct mtd_info *mtd)
{
struct nand_chip *chip = mtd_to_nand(mtd);
- mutex_lock(&chip->lock);
- if (chip->suspended) {
- if (chip->ops.resume)
- chip->ops.resume(chip);
- chip->suspended = 0;
- } else {
- pr_err("%s called for a chip which is not in suspended state\n",
- __func__);
+ scoped_guard(mutex, &chip->lock) {
+ if (chip->suspended) {
+ if (chip->ops.resume)
+ chip->ops.resume(chip);
+ chip->suspended = 0;
+ } else {
+ pr_err("%s called for a chip which is not in suspended state\n",
+ __func__);
+ }
}
- mutex_unlock(&chip->lock);
wake_up_all(&chip->resume_wq);
}
--
2.51.0
On Wed, 11 Mar 2026 00:30:43 +0800, Richard Lyu wrote:
> 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.
>
> [...]
Applied to nand/next, thanks!
[1/1] mtd: nand: Use scoped_guard for mutex in nand_resume
commit: 520886a1a6ca16862a0437b4a8fae133a895a9b8
Patche(s) should be available on mtd/linux.git and will be
part of the next PR (provided that no robot complains by then).
Kind regards,
Miquèl
© 2016 - 2026 Red Hat, Inc.