Skip to contentSkip to conversation

net: dqs: use sysfs_emit() in favor of sprintf()

PATCH Applied Eric Dumazet 4 participants 5 messages Apr 4, 2024 – Apr 8, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: dqs: use sysfs_emit() in favor of sprintf()

Commit 6025b9135f7a ("net: dqs: add NIC stall detector based on BQL") added three sysfs files.

Use the recommended sysfs_emit() helper.

Cc Jakub Kicinski <[email protected]>
Cc Breno Leitao <[email protected]>
---
 net/core/net-sysfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/core/net-sysfs.c +3 -3
index e3d7a8cfa20b7d1052f2b6c54b7a9810c55f91fc..ff3ee45be64a6a91d1abdcac5cd04b4bdd03e39c 100644
@@ -1419,7 +1419,7 @@ static ssize_t bql_show_stall_thrs(struct netdev_queue *queue, char *buf)
 {
 	struct dql *dql = &queue->dql;
 
-	return sprintf(buf, "%u\n", jiffies_to_msecs(dql->stall_thrs));
+	return sysfs_emit(buf, "%u\n", jiffies_to_msecs(dql->stall_thrs));
 }
 
 static ssize_t bql_set_stall_thrs(struct netdev_queue *queue,
@@ -1451,7 +1451,7 @@ static struct netdev_queue_attribute bql_stall_thrs_attribute __ro_after_init =
 
 static ssize_t bql_show_stall_max(struct netdev_queue *queue, char *buf)
 {
-	return sprintf(buf, "%u\n", READ_ONCE(queue->dql.stall_max));
+	return sysfs_emit(buf, "%u\n", READ_ONCE(queue->dql.stall_max));
 }
 
 static ssize_t bql_set_stall_max(struct netdev_queue *queue,
@@ -1468,7 +1468,7 @@ static ssize_t bql_show_stall_cnt(struct netdev_queue *queue, char *buf)
 {
 	struct dql *dql = &queue->dql;
 
-	return sprintf(buf, "%lu\n", dql->stall_cnt);
+	return sysfs_emit(buf, "%lu\n", dql->stall_cnt);
 }
 
 static struct netdev_queue_attribute bql_stall_cnt_attribute __ro_after_init =
Signature · 1 line
2.44.0.478.gd926399ef9-goog
#1 lore raw
Quoted 35 lines · Eric Dumazet

Commit 6025b9135f7a ("net: dqs: add NIC stall detector based on BQL") added three sysfs files.

Use the recommended sysfs_emit() helper.

Cc Jakub Kicinski <[email protected]>
Cc Breno Leitao <[email protected]>
---
 net/core/net-sysfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/core/net-sysfs.c +2 -2
index e3d7a8cfa20b7d1052f2b6c54b7a9810c55f91fc..ff3ee45be64a6a91d1abdcac5cd04b4bdd03e39c 100644
@@ -1419,7 +1419,7 @@ static ssize_t bql_show_stall_thrs(struct netdev_queue *queue, char *buf)
 {
 	struct dql *dql = &queue->dql;
 
-	return sprintf(buf, "%u\n", jiffies_to_msecs(dql->stall_thrs));
+	return sysfs_emit(buf, "%u\n", jiffies_to_msecs(dql->stall_thrs));
 }
 
 static ssize_t bql_set_stall_thrs(struct netdev_queue *queue,
@@ -1451,7 +1451,7 @@ static struct netdev_queue_attribute bql_stall_thrs_attribute __ro_after_init =
 
 static ssize_t bql_show_stall_max(struct netdev_queue *queue, char *buf)
 {
-	return sprintf(buf, "%u\n", READ_ONCE(queue->dql.stall_max));
+	return sysfs_emit(buf, "%u\n", READ_ONCE(queue->dql.stall_max));
 }
 
 static ssize_t bql_set_stall_max(struct netdev_queue *queue,

net/core/net-sysfs.c static ssize_t bql_show_stall_cnt(struct netdev_queue *queue, char *buf) · line 1474

Quoted 8 lines
net/core/net-sysfs.c +1 -1
@@ -1468,7 +1468,7 @@ static ssize_t bql_show_stall_cnt(struct netdev_queue *queue, char *buf)
 {
 	struct dql *dql = &queue->dql;
 
-	return sprintf(buf, "%lu\n", dql->stall_cnt);
+	return sysfs_emit(buf, "%lu\n", dql->stall_cnt);
 }
 
 static struct netdev_queue_attribute bql_stall_cnt_attribute __ro_after_init =

Checked that the above are the only 3 instances of sprintf() in net-sysfs.c. Rest of the file uses sysfs_emit() which has the same args as sprintf().

Interestingly the docs for sysfs_emit() claims it is an scnprintf() equivalent, but has no size_t size param. So it's more like a sprintf() equivalent.

#2 lore raw
Quoted 7 lines · David Wei

Checked that the above are the only 3 instances of sprintf() in net-sysfs.c. Rest of the file uses sysfs_emit() which has the same args as sprintf().

Interestingly the docs for sysfs_emit() claims it is an scnprintf() equivalent, but has no size_t size param. So it's more like a sprintf() equivalent.

sysfs uses PAGE_SIZE allocated buffers, this is kind of hardcoded in it.

#4 lore raw
In reply to Eric Dumazet
This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Quoted 10 lines · On Thu, 4 Apr 2024 16:46:04 +0000 you wrote:

Commit 6025b9135f7a ("net: dqs: add NIC stall detector based on BQL") added three sysfs files.

Use the recommended sysfs_emit() helper.

Cc Jakub Kicinski <[email protected]>
Cc Breno Leitao <[email protected]>

[...]

Here is the summary with links:
- [net-next] net: dqs: use sysfs_emit() in favor of sprintf()

    https://git.kernel.org/netdev/net-next/c/db77cdc69684

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html