lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<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, &quot;Microsoft Yahei&quot;, sans-serif; background-color: rgb(255, 255, 255);">From: XieLudan &lt;xie.ludan@....com.cn&gt;</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 &lt;xie.ludan@....com.cn&gt;</p><p>---</p><p>&nbsp;kernel/workqueue.c | 22 +++++++++++-----------</p><p>&nbsp;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>&nbsp;<span style="white-space:pre">			</span> */</p><p>&nbsp;<span style="white-space:pre">			</span>if (worker-&gt;desc[0] != '\0') {</p><p>&nbsp;<span style="white-space:pre">				</span>if (worker-&gt;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>&nbsp;<span style="white-space:pre">						</span>&nbsp; worker-&gt;desc);</p><p>&nbsp;<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>&nbsp;<span style="white-space:pre">						</span>&nbsp; worker-&gt;desc);</p><p>&nbsp;<span style="white-space:pre">			</span>}</p><p>&nbsp;<span style="white-space:pre">			</span>raw_spin_unlock_irq(&amp;pool-&gt;lock);</p><p>@@ -7005,7 +7005,7 @@ static int wq_affn_dfl_set(const char *val, const struct kernel_param *kp)</p><p>&nbsp;</p><p>&nbsp;static int wq_affn_dfl_get(char *buffer, const struct kernel_param *kp)</p><p>&nbsp;{</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>&nbsp;}</p><p>&nbsp;</p><p>&nbsp;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>&nbsp;{</p><p>&nbsp;<span style="white-space:pre">	</span>struct workqueue_struct *wq = dev_to_wq(dev);</p><p>&nbsp;</p><p>-<span style="white-space:pre">	</span>return scnprintf(buf, PAGE_SIZE, "%d\n", (bool)!(wq-&gt;flags &amp; WQ_UNBOUND));</p><p>+<span style="white-space:pre">	</span>return sysfs_emit(buf, "%d\n", (bool)!(wq-&gt;flags &amp; WQ_UNBOUND));</p><p>&nbsp;}</p><p>&nbsp;static DEVICE_ATTR_RO(per_cpu);</p><p>&nbsp;</p><p>@@ -7057,7 +7057,7 @@ static ssize_t max_active_show(struct device *dev,</p><p>&nbsp;{</p><p>&nbsp;<span style="white-space:pre">	</span>struct workqueue_struct *wq = dev_to_wq(dev);</p><p>&nbsp;</p><p>-<span style="white-space:pre">	</span>return scnprintf(buf, PAGE_SIZE, "%d\n", wq-&gt;saved_max_active);</p><p>+<span style="white-space:pre">	</span>return sysfs_emit(buf, "%d\n", wq-&gt;saved_max_active);</p><p>&nbsp;}</p><p>&nbsp;</p><p>&nbsp;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>&nbsp;<span style="white-space:pre">	</span>int written;</p><p>&nbsp;</p><p>&nbsp;<span style="white-space:pre">	</span>mutex_lock(&amp;wq-&gt;mutex);</p><p>-<span style="white-space:pre">	</span>written = scnprintf(buf, PAGE_SIZE, "%d\n", wq-&gt;unbound_attrs-&gt;nice);</p><p>+<span style="white-space:pre">	</span>written = sysfs_emit(buf, "%d\n", wq-&gt;unbound_attrs-&gt;nice);</p><p>&nbsp;<span style="white-space:pre">	</span>mutex_unlock(&amp;wq-&gt;mutex);</p><p>&nbsp;</p><p>&nbsp;<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>&nbsp;<span style="white-space:pre">	</span>int written;</p><p>&nbsp;</p><p>&nbsp;<span style="white-space:pre">	</span>mutex_lock(&amp;wq-&gt;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>&nbsp;<span style="white-space:pre">			</span>&nbsp; &nbsp; cpumask_pr_args(wq-&gt;unbound_attrs-&gt;cpumask));</p><p>&nbsp;<span style="white-space:pre">	</span>mutex_unlock(&amp;wq-&gt;mutex);</p><p>&nbsp;<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>&nbsp;</p><p>&nbsp;<span style="white-space:pre">	</span>mutex_lock(&amp;wq-&gt;mutex);</p><p>&nbsp;<span style="white-space:pre">	</span>if (wq-&gt;unbound_attrs-&gt;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>&nbsp;<span style="white-space:pre">				</span>&nbsp; &nbsp; wq_affn_names[WQ_AFFN_DFL],</p><p>&nbsp;<span style="white-space:pre">				</span>&nbsp; &nbsp; wq_affn_names[wq_affn_dfl]);</p><p>&nbsp;<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>&nbsp;<span style="white-space:pre">				</span>&nbsp; &nbsp; wq_affn_names[wq-&gt;unbound_attrs-&gt;affn_scope]);</p><p>&nbsp;<span style="white-space:pre">	</span>mutex_unlock(&amp;wq-&gt;mutex);</p><p>&nbsp;</p><p>@@ -7219,7 +7219,7 @@ static ssize_t wq_affinity_strict_show(struct device *dev,</p><p>&nbsp;{</p><p>&nbsp;<span style="white-space:pre">	</span>struct workqueue_struct *wq = dev_to_wq(dev);</p><p>&nbsp;</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>&nbsp;<span style="white-space:pre">			</span> wq-&gt;unbound_attrs-&gt;affn_strict);</p><p>&nbsp;}</p><p>&nbsp;</p><p>@@ -7298,7 +7298,7 @@ static ssize_t __wq_cpumask_show(struct device *dev,</p><p>&nbsp;<span style="white-space:pre">	</span>int written;</p><p>&nbsp;</p><p>&nbsp;<span style="white-space:pre">	</span>mutex_lock(&amp;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>&nbsp;<span style="white-space:pre">	</span>mutex_unlock(&amp;wq_pool_mutex);</p><p>&nbsp;</p><p>&nbsp;<span style="white-space:pre">	</span>return written;</p><p>--&nbsp;</p><p>2.25.1</p><p><br></p></div>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ