From 8be5c2eb2778af516157468e8c39979cdae3b00b Mon Sep 17 00:00:00 2001 From: Junhui Liu Date: Tue, 20 May 2025 14:41:50 +0800 Subject: [PATCH] mailbox: mailbox-test: Fix __might_sleep() warning in mbox_test_message_read() The following warning was observed when calling mbox_test_message_read() for the first time: [ 69.246375] do not call blocking ops when !TASK_RUNNING; state=1 set at [<(____ptrval____)>] mbox_test_message_read+0xba/0x23e [ 69.258608] WARNING: CPU: 0 PID: 62 at kernel/sched/core.c:8741 __might_sleep+0x62/0x66 This is triggered because simple_read_from_buffer() called in mbox_test_message_read() may sleep. As a result, the kernel warns about blocking operations when the task state is not TASK_RUNNING. Fix this by ensuring __set_current_state(TASK_RUNNING) is called before executing code paths that may sleep. Fixes: d597580d3737 ("generic ...copy_..._user primitives") Signed-off-by: Junhui Liu Signed-off-by: Linux RISC-V bot --- drivers/mailbox/mailbox-test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/mailbox/mailbox-test.c b/drivers/mailbox/mailbox-test.c index c9dd8c42c0cdf9..2540808d550d34 100644 --- a/drivers/mailbox/mailbox-test.c +++ b/drivers/mailbox/mailbox-test.c @@ -200,11 +200,13 @@ static ssize_t mbox_test_message_read(struct file *filp, char __user *userbuf, if (filp->f_flags & O_NONBLOCK) { ret = -EAGAIN; + __set_current_state(TASK_RUNNING); goto waitq_err; } if (signal_pending(current)) { ret = -ERESTARTSYS; + __set_current_state(TASK_RUNNING); goto waitq_err; } schedule(); @@ -231,9 +233,9 @@ static ssize_t mbox_test_message_read(struct file *filp, char __user *userbuf, spin_unlock_irqrestore(&tdev->lock, flags); + __set_current_state(TASK_RUNNING); ret = simple_read_from_buffer(userbuf, count, ppos, touser, MBOX_HEXDUMP_MAX_LEN); waitq_err: - __set_current_state(TASK_RUNNING); remove_wait_queue(&tdev->waitq, &wait); kfree_err: kfree(touser);