diff mbox series

[net-next] net: dqs: use sysfs_emit() in favor of sprintf()

Message ID 20240404164604.3055832-1-edumazet@google.com (mailing list archive)
State Accepted
Commit db77cdc69684890b37ff2bb9fb9e0be2ba4d6efe
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: dqs: use sysfs_emit() in favor of sprintf() | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 944 this patch: 944
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 954 this patch: 954
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 955 this patch: 955
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 24 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-04-07--00-00 (tests: 956)

Commit Message

Eric Dumazet April 4, 2024, 4:46 p.m. UTC
Commit 6025b9135f7a ("net: dqs: add NIC stall detector based on BQL")
added three sysfs files.

Use the recommended sysfs_emit() helper.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Breno Leitao <leitao@debian.org>
---
 net/core/net-sysfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

David Wei April 4, 2024, 5:57 p.m. UTC | #1
On 2024-04-04 09:46, Eric Dumazet wrote:
> Commit 6025b9135f7a ("net: dqs: add NIC stall detector based on BQL")
> added three sysfs files.
> 
> Use the recommended sysfs_emit() helper.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Breno Leitao <leitao@debian.org>
> ---
>  net/core/net-sysfs.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
> index e3d7a8cfa20b7d1052f2b6c54b7a9810c55f91fc..ff3ee45be64a6a91d1abdcac5cd04b4bdd03e39c 100644
> --- a/net/core/net-sysfs.c
> +++ b/net/core/net-sysfs.c
> @@ -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 =

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.
Eric Dumazet April 4, 2024, 6:04 p.m. UTC | #2
On Thu, Apr 4, 2024 at 7:57 PM David Wei <dw@davidwei.uk> wrote:

> 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.
Breno Leitao April 4, 2024, 6:09 p.m. UTC | #3
On Thu, Apr 04, 2024 at 04:46:04PM +0000, Eric Dumazet wrote:
> Commit 6025b9135f7a ("net: dqs: add NIC stall detector based on BQL")
> added three sysfs files.
> 
> Use the recommended sysfs_emit() helper.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Reviwed-by: Breno Leitao <leitao@debian.org>
patchwork-bot+netdevbpf@kernel.org April 8, 2024, 10:10 a.m. UTC | #4
Hello:

This patch was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:

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.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Breno Leitao <leitao@debian.org>
> 
> [...]

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!
diff mbox series

Patch

diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index e3d7a8cfa20b7d1052f2b6c54b7a9810c55f91fc..ff3ee45be64a6a91d1abdcac5cd04b4bdd03e39c 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -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 =