[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20250315141758672YYVCK97SOzH7bky44hoBe@zte.com.cn>
Date: Sat, 15 Mar 2025 14:17:58 +0800 (CST)
From: <xie.ludan@....com.cn>
To: <tj@...nel.org>
Cc: <jiangshanlai@...il.com>, <linux-kernel@...r.kernel.org>
Subject: [PATCH linux-next] workqueue: use sysfs_emit() instead of scnprintf().
From: XieLudan <xie.ludan@....com.cn>
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@....com.cn>
---
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);
@@ -7005,7 +7005,7 @@ static int wq_affn_dfl_set(const char *val, const struct kernel_param *kp)
static int wq_affn_dfl_get(char *buffer, const struct kernel_param *kp)
{
- return scnprintf(buffer, PAGE_SIZE, "%s\n", wq_affn_names[wq_affn_dfl]);
+ return sysfs_emit(buffer, "%s\n", wq_affn_names[wq_affn_dfl]);
}
static const struct kernel_param_ops wq_affn_dfl_ops = {
@@ -7048,7 +7048,7 @@ static ssize_t per_cpu_show(struct device *dev, struct device_attribute *attr,
{
struct workqueue_struct *wq = dev_to_wq(dev);
- return scnprintf(buf, PAGE_SIZE, "%d\n", (bool)!(wq->flags & WQ_UNBOUND));
+ return sysfs_emit(buf, "%d\n", (bool)!(wq->flags & WQ_UNBOUND));
}
static DEVICE_ATTR_RO(per_cpu);
@@ -7057,7 +7057,7 @@ static ssize_t max_active_show(struct device *dev,
{
struct workqueue_struct *wq = dev_to_wq(dev);
- return scnprintf(buf, PAGE_SIZE, "%d\n", wq->saved_max_active);
+ return sysfs_emit(buf, "%d\n", wq->saved_max_active);
}
static ssize_t max_active_store(struct device *dev,
@@ -7089,7 +7089,7 @@ static ssize_t wq_nice_show(struct device *dev, struct device_attribute *attr,
int written;
mutex_lock(&wq->mutex);
- written = scnprintf(buf, PAGE_SIZE, "%d\n", wq->unbound_attrs->nice);
+ written = sysfs_emit(buf, "%d\n", wq->unbound_attrs->nice);
mutex_unlock(&wq->mutex);
return written;
@@ -7142,7 +7142,7 @@ static ssize_t wq_cpumask_show(struct device *dev,
int written;
mutex_lock(&wq->mutex);
- written = scnprintf(buf, PAGE_SIZE, "%*pb\n",
+ written = sysfs_emit(buf, "%*pb\n",
cpumask_pr_args(wq->unbound_attrs->cpumask));
mutex_unlock(&wq->mutex);
return written;
@@ -7180,11 +7180,11 @@ static ssize_t wq_affn_scope_show(struct device *dev,
mutex_lock(&wq->mutex);
if (wq->unbound_attrs->affn_scope == WQ_AFFN_DFL)
- written = scnprintf(buf, PAGE_SIZE, "%s (%s)\n",
+ written = sysfs_emit(buf, "%s (%s)\n",
wq_affn_names[WQ_AFFN_DFL],
wq_affn_names[wq_affn_dfl]);
else
- written = scnprintf(buf, PAGE_SIZE, "%s\n",
+ written = sysfs_emit(buf, "%s\n",
wq_affn_names[wq->unbound_attrs->affn_scope]);
mutex_unlock(&wq->mutex);
@@ -7219,7 +7219,7 @@ static ssize_t wq_affinity_strict_show(struct device *dev,
{
struct workqueue_struct *wq = dev_to_wq(dev);
- return scnprintf(buf, PAGE_SIZE, "%d\n",
+ return sysfs_emit(buf, "%d\n",
wq->unbound_attrs->affn_strict);
}
@@ -7298,7 +7298,7 @@ static ssize_t __wq_cpumask_show(struct device *dev,
int written;
mutex_lock(&wq_pool_mutex);
- written = scnprintf(buf, PAGE_SIZE, "%*pb\n", cpumask_pr_args(mask));
+ written = sysfs_emit(buf, "%*pb\n", cpumask_pr_args(mask));
mutex_unlock(&wq_pool_mutex);
return written;
--
2.25.1
<div class="zcontentRow"><p><span style="font-family: Arial, Helvetica, "Microsoft Yahei", sans-serif; background-color: rgb(255, 255, 255);">From: XieLudan <xie.ludan@....com.cn></span></p><p><br></p><p>Follow the advice in Documentation/filesystems/sysfs.rst:</p><p>show() should only use sysfs_emit() or sysfs_emit_at() when formatting</p><p>the value to be returned to user space.</p><p><br></p><p>Signed-off-by: XieLudan <xie.ludan@....com.cn></p><p>---</p><p> kernel/workqueue.c | 22 +++++++++++-----------</p><p> 1 file changed, 11 insertions(+), 11 deletions(-)</p><p><br></p><p>diff --git a/kernel/workqueue.c b/kernel/workqueue.c</p><p>index bfe030b443e2..648e89dd3ef1 100644</p><p>--- a/kernel/workqueue.c</p><p>+++ b/kernel/workqueue.c</p><p>@@ -6463,10 +6463,10 @@ void wq_worker_comm(char *buf, size_t size, struct task_struct *task)</p><p> <span style="white-space:pre"> </span> */</p><p> <span style="white-space:pre"> </span>if (worker->desc[0] != '\0') {</p><p> <span style="white-space:pre"> </span>if (worker->current_work)</p><p>-<span style="white-space:pre"> </span>scnprintf(buf + off, size - off, "+%s",</p><p>+<span style="white-space:pre"> </span>sysfs_emit(buf + off, "+%s",</p><p> <span style="white-space:pre"> </span> worker->desc);</p><p> <span style="white-space:pre"> </span>else</p><p>-<span style="white-space:pre"> </span>scnprintf(buf + off, size - off, "-%s",</p><p>+<span style="white-space:pre"> </span>sysfs_emit(buf + off, "-%s",</p><p> <span style="white-space:pre"> </span> worker->desc);</p><p> <span style="white-space:pre"> </span>}</p><p> <span style="white-space:pre"> </span>raw_spin_unlock_irq(&pool->lock);</p><p>@@ -7005,7 +7005,7 @@ static int wq_affn_dfl_set(const char *val, const struct kernel_param *kp)</p><p> </p><p> static int wq_affn_dfl_get(char *buffer, const struct kernel_param *kp)</p><p> {</p><p>-<span style="white-space:pre"> </span>return scnprintf(buffer, PAGE_SIZE, "%s\n", wq_affn_names[wq_affn_dfl]);</p><p>+<span style="white-space:pre"> </span>return sysfs_emit(buffer, "%s\n", wq_affn_names[wq_affn_dfl]);</p><p> }</p><p> </p><p> static const struct kernel_param_ops wq_affn_dfl_ops = {</p><p>@@ -7048,7 +7048,7 @@ static ssize_t per_cpu_show(struct device *dev, struct device_attribute *attr,</p><p> {</p><p> <span style="white-space:pre"> </span>struct workqueue_struct *wq = dev_to_wq(dev);</p><p> </p><p>-<span style="white-space:pre"> </span>return scnprintf(buf, PAGE_SIZE, "%d\n", (bool)!(wq->flags & WQ_UNBOUND));</p><p>+<span style="white-space:pre"> </span>return sysfs_emit(buf, "%d\n", (bool)!(wq->flags & WQ_UNBOUND));</p><p> }</p><p> static DEVICE_ATTR_RO(per_cpu);</p><p> </p><p>@@ -7057,7 +7057,7 @@ static ssize_t max_active_show(struct device *dev,</p><p> {</p><p> <span style="white-space:pre"> </span>struct workqueue_struct *wq = dev_to_wq(dev);</p><p> </p><p>-<span style="white-space:pre"> </span>return scnprintf(buf, PAGE_SIZE, "%d\n", wq->saved_max_active);</p><p>+<span style="white-space:pre"> </span>return sysfs_emit(buf, "%d\n", wq->saved_max_active);</p><p> }</p><p> </p><p> static ssize_t max_active_store(struct device *dev,</p><p>@@ -7089,7 +7089,7 @@ static ssize_t wq_nice_show(struct device *dev, struct device_attribute *attr,</p><p> <span style="white-space:pre"> </span>int written;</p><p> </p><p> <span style="white-space:pre"> </span>mutex_lock(&wq->mutex);</p><p>-<span style="white-space:pre"> </span>written = scnprintf(buf, PAGE_SIZE, "%d\n", wq->unbound_attrs->nice);</p><p>+<span style="white-space:pre"> </span>written = sysfs_emit(buf, "%d\n", wq->unbound_attrs->nice);</p><p> <span style="white-space:pre"> </span>mutex_unlock(&wq->mutex);</p><p> </p><p> <span style="white-space:pre"> </span>return written;</p><p>@@ -7142,7 +7142,7 @@ static ssize_t wq_cpumask_show(struct device *dev,</p><p> <span style="white-space:pre"> </span>int written;</p><p> </p><p> <span style="white-space:pre"> </span>mutex_lock(&wq->mutex);</p><p>-<span style="white-space:pre"> </span>written = scnprintf(buf, PAGE_SIZE, "%*pb\n",</p><p>+<span style="white-space:pre"> </span>written = sysfs_emit(buf, "%*pb\n",</p><p> <span style="white-space:pre"> </span> cpumask_pr_args(wq->unbound_attrs->cpumask));</p><p> <span style="white-space:pre"> </span>mutex_unlock(&wq->mutex);</p><p> <span style="white-space:pre"> </span>return written;</p><p>@@ -7180,11 +7180,11 @@ static ssize_t wq_affn_scope_show(struct device *dev,</p><p> </p><p> <span style="white-space:pre"> </span>mutex_lock(&wq->mutex);</p><p> <span style="white-space:pre"> </span>if (wq->unbound_attrs->affn_scope == WQ_AFFN_DFL)</p><p>-<span style="white-space:pre"> </span>written = scnprintf(buf, PAGE_SIZE, "%s (%s)\n",</p><p>+<span style="white-space:pre"> </span>written = sysfs_emit(buf, "%s (%s)\n",</p><p> <span style="white-space:pre"> </span> wq_affn_names[WQ_AFFN_DFL],</p><p> <span style="white-space:pre"> </span> wq_affn_names[wq_affn_dfl]);</p><p> <span style="white-space:pre"> </span>else</p><p>-<span style="white-space:pre"> </span>written = scnprintf(buf, PAGE_SIZE, "%s\n",</p><p>+<span style="white-space:pre"> </span>written = sysfs_emit(buf, "%s\n",</p><p> <span style="white-space:pre"> </span> wq_affn_names[wq->unbound_attrs->affn_scope]);</p><p> <span style="white-space:pre"> </span>mutex_unlock(&wq->mutex);</p><p> </p><p>@@ -7219,7 +7219,7 @@ static ssize_t wq_affinity_strict_show(struct device *dev,</p><p> {</p><p> <span style="white-space:pre"> </span>struct workqueue_struct *wq = dev_to_wq(dev);</p><p> </p><p>-<span style="white-space:pre"> </span>return scnprintf(buf, PAGE_SIZE, "%d\n",</p><p>+<span style="white-space:pre"> </span>return sysfs_emit(buf, "%d\n",</p><p> <span style="white-space:pre"> </span> wq->unbound_attrs->affn_strict);</p><p> }</p><p> </p><p>@@ -7298,7 +7298,7 @@ static ssize_t __wq_cpumask_show(struct device *dev,</p><p> <span style="white-space:pre"> </span>int written;</p><p> </p><p> <span style="white-space:pre"> </span>mutex_lock(&wq_pool_mutex);</p><p>-<span style="white-space:pre"> </span>written = scnprintf(buf, PAGE_SIZE, "%*pb\n", cpumask_pr_args(mask));</p><p>+<span style="white-space:pre"> </span>written = sysfs_emit(buf, "%*pb\n", cpumask_pr_args(mask));</p><p> <span style="white-space:pre"> </span>mutex_unlock(&wq_pool_mutex);</p><p> </p><p> <span style="white-space:pre"> </span>return written;</p><p>-- </p><p>2.25.1</p><p><br></p></div>
Powered by blists - more mailing lists