Re: [PATCH linux-next] workqueue: use sysfs_emit() instead of scnprintf().
From: Tejun Heo
Date: Sat Mar 15 2025 - 11:50:55 EST
On Sat, Mar 15, 2025 at 02:17:58PM +0800, xie.ludan@xxxxxxxxxx wrote:
> From: XieLudan <xie.ludan@xxxxxxxxxx>
>
> Follow the advice in Documentation/filesystems/sysfs.rst:
> show() should only use sysfs_emit() or sysfs_emit_at() when formatting
> the value to be returned to user space.
>
> Signed-off-by: XieLudan <xie.ludan@xxxxxxxxxx>
> ---
> kernel/workqueue.c | 22 +++++++++++-----------
> 1 file changed, 11 insertions(+), 11 deletions(-)
>
> diff --git a/kernel/workqueue.c b/kernel/workqueue.c
> index bfe030b443e2..648e89dd3ef1 100644
> --- a/kernel/workqueue.c
> +++ b/kernel/workqueue.c
> @@ -6463,10 +6463,10 @@ void wq_worker_comm(char *buf, size_t size, struct task_struct *task)
> */
> if (worker->desc[0] != '\0') {
> if (worker->current_work)
> - scnprintf(buf + off, size - off, "+%s",
> + sysfs_emit(buf + off, "+%s",
> worker->desc);
> else
> - scnprintf(buf + off, size - off, "-%s",
> + sysfs_emit(buf + off, "-%s",
> worker->desc);
> }
> raw_spin_unlock_irq(&pool->lock);
How did you verify your changes? wq_worker_comm() is used from procfs not
sysfs. @buf is on-stack 64byte buffer from proc_task_name() which is not
page aligned and will most likely trigger WARN() path in sysfs_emit().
Thanks.
--
tejun