diff mbox series

[linux-next,v2] net: atm: use sysfs_emit()/sysfs_emit_at() instead of scnprintf().

Message ID 20250325102805210eUc7-ji7GineR0TUNA9Nn@zte.com.cn (mailing list archive)
State Deferred
Delegated to: Netdev Maintainers
Headers show
Series [linux-next,v2] net: atm: use sysfs_emit()/sysfs_emit_at() instead of scnprintf(). | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be 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: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
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: 0 this patch: 0
netdev/checkpatch warning WARNING: line length of 81 exceeds 80 columns WARNING: line length of 86 exceeds 80 columns
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-2025-03-26--00-00 (tests: 896)

Commit Message

xie.ludan@zte.com.cn March 25, 2025, 2:28 a.m. UTC
From: XieLudan <xie.ludan@zte.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@zte.com.cn>
---
v2:
    - adapting the alignment of argument lines
 net/atm/atm_sysfs.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

Comments

xu.xin16@zte.com.cn March 26, 2025, 7:22 a.m. UTC | #1
>From: XieLudan <xie.ludan@zte.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@zte.com.cn>
>---
>v2:
>    - adapting the alignment of argument lines
> net/atm/atm_sysfs.c | 24 +++++++++++-------------
> 1 file changed, 11 insertions(+), 13 deletions(-)
>
>diff --git a/net/atm/atm_sysfs.c b/net/atm/atm_sysfs.c
>index 54e7fb1a4ee5..726398fa848e 100644
>--- a/net/atm/atm_sysfs.c
>+++ b/net/atm/atm_sysfs.c
>@@ -16,7 +16,7 @@ static ssize_t type_show(struct device *cdev,
> {
> 	struct atm_dev *adev = to_atm_dev(cdev);
>
>-	return scnprintf(buf, PAGE_SIZE, "%s\n", adev->type);
>+	return sysfs_emit(buf, "%s\n", adev->type);
> }
>

Generally LGTM. Thanks.

Reviewed-by: xu xin <xu.xin16@zte.com.cn>

> static ssize_t address_show(struct device *cdev,
>@@ -24,7 +24,7 @@ static ssize_t address_show(struct device *cdev,
> {
> 	struct atm_dev *adev = to_atm_dev(cdev);
>
>-	return scnprintf(buf, PAGE_SIZE, "%pM\n", adev->esi);
>+	return sysfs_emit(buf, "%pM\n", adev->esi);
> }
>
> static ssize_t atmaddress_show(struct device *cdev,
>@@ -37,13 +37,12 @@ static ssize_t atmaddress_show(struct device *cdev,
>
> 	spin_lock_irqsave(&adev->lock, flags);
> 	list_for_each_entry(aaddr, &adev->local, entry) {
>-		count += scnprintf(buf + count, PAGE_SIZE - count,
>-				   "%1phN.%2phN.%10phN.%6phN.%1phN\n",
>-				   &aaddr->addr.sas_addr.prv[0],
>-				   &aaddr->addr.sas_addr.prv[1],
>-				   &aaddr->addr.sas_addr.prv[3],
>-				   &aaddr->addr.sas_addr.prv[13],
>-				   &aaddr->addr.sas_addr.prv[19]);
>+		count += sysfs_emit_at(buf, count, "%1phN.%2phN.%10phN.%6phN.%1phN\n",
>+				       &aaddr->addr.sas_addr.prv[0],
>+				       &aaddr->addr.sas_addr.prv[1],
>+				       &aaddr->addr.sas_addr.prv[3],
>+				       &aaddr->addr.sas_addr.prv[13],
>+				       &aaddr->addr.sas_addr.prv[19]);
> 	}
> 	spin_unlock_irqrestore(&adev->lock, flags);
>
>@@ -55,7 +54,7 @@ static ssize_t atmindex_show(struct device *cdev,
> {
> 	struct atm_dev *adev = to_atm_dev(cdev);
>
>-	return scnprintf(buf, PAGE_SIZE, "%d\n", adev->number);
>+	return sysfs_emit(buf, "%d\n", adev->number);
> }
>
> static ssize_t carrier_show(struct device *cdev,
>@@ -63,8 +62,7 @@ static ssize_t carrier_show(struct device *cdev,
> {
> 	struct atm_dev *adev = to_atm_dev(cdev);
>
>-	return scnprintf(buf, PAGE_SIZE, "%d\n",
>-			 adev->signal == ATM_PHY_SIG_LOST ? 0 : 1);
>+	return sysfs_emit(buf, "%d\n", adev->signal == ATM_PHY_SIG_LOST ? 0 : 1);
> }
>
> static ssize_t link_rate_show(struct device *cdev,
>@@ -87,7 +85,7 @@ static ssize_t link_rate_show(struct device *cdev,
> 	default:
> 		link_rate = adev->link_rate * 8 * 53;
> 	}
>-	return scnprintf(buf, PAGE_SIZE, "%d\n", link_rate);
>+	return sysfs_emit(buf, "%d\n", link_rate);
> }
>
> static DEVICE_ATTR_RO(address);
>-- 
>2.25.1
Jakub Kicinski March 26, 2025, 11:45 a.m. UTC | #2
On Tue, 25 Mar 2025 10:28:05 +0800 (CST) xie.ludan@zte.com.cn wrote:
> From: XieLudan <xie.ludan@zte.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.

## Form letter - net-next-closed

The merge window for v6.15 has begun and therefore net-next is closed for
new drivers, features, code refactoring and optimizations. We are currently
accepting bug fixes only.

Please repost when net-next reopens after Apr 7th.

RFC patches sent for review only are obviously welcome at any time.

See: https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#development-cycle
diff mbox series

Patch

diff --git a/net/atm/atm_sysfs.c b/net/atm/atm_sysfs.c
index 54e7fb1a4ee5..726398fa848e 100644
--- a/net/atm/atm_sysfs.c
+++ b/net/atm/atm_sysfs.c
@@ -16,7 +16,7 @@  static ssize_t type_show(struct device *cdev,
 {
 	struct atm_dev *adev = to_atm_dev(cdev);

-	return scnprintf(buf, PAGE_SIZE, "%s\n", adev->type);
+	return sysfs_emit(buf, "%s\n", adev->type);
 }

 static ssize_t address_show(struct device *cdev,
@@ -24,7 +24,7 @@  static ssize_t address_show(struct device *cdev,
 {
 	struct atm_dev *adev = to_atm_dev(cdev);

-	return scnprintf(buf, PAGE_SIZE, "%pM\n", adev->esi);
+	return sysfs_emit(buf, "%pM\n", adev->esi);
 }

 static ssize_t atmaddress_show(struct device *cdev,
@@ -37,13 +37,12 @@  static ssize_t atmaddress_show(struct device *cdev,

 	spin_lock_irqsave(&adev->lock, flags);
 	list_for_each_entry(aaddr, &adev->local, entry) {
-		count += scnprintf(buf + count, PAGE_SIZE - count,
-				   "%1phN.%2phN.%10phN.%6phN.%1phN\n",
-				   &aaddr->addr.sas_addr.prv[0],
-				   &aaddr->addr.sas_addr.prv[1],
-				   &aaddr->addr.sas_addr.prv[3],
-				   &aaddr->addr.sas_addr.prv[13],
-				   &aaddr->addr.sas_addr.prv[19]);
+		count += sysfs_emit_at(buf, count, "%1phN.%2phN.%10phN.%6phN.%1phN\n",
+				       &aaddr->addr.sas_addr.prv[0],
+				       &aaddr->addr.sas_addr.prv[1],
+				       &aaddr->addr.sas_addr.prv[3],
+				       &aaddr->addr.sas_addr.prv[13],
+				       &aaddr->addr.sas_addr.prv[19]);
 	}
 	spin_unlock_irqrestore(&adev->lock, flags);

@@ -55,7 +54,7 @@  static ssize_t atmindex_show(struct device *cdev,
 {
 	struct atm_dev *adev = to_atm_dev(cdev);

-	return scnprintf(buf, PAGE_SIZE, "%d\n", adev->number);
+	return sysfs_emit(buf, "%d\n", adev->number);
 }

 static ssize_t carrier_show(struct device *cdev,
@@ -63,8 +62,7 @@  static ssize_t carrier_show(struct device *cdev,
 {
 	struct atm_dev *adev = to_atm_dev(cdev);

-	return scnprintf(buf, PAGE_SIZE, "%d\n",
-			 adev->signal == ATM_PHY_SIG_LOST ? 0 : 1);
+	return sysfs_emit(buf, "%d\n", adev->signal == ATM_PHY_SIG_LOST ? 0 : 1);
 }

 static ssize_t link_rate_show(struct device *cdev,
@@ -87,7 +85,7 @@  static ssize_t link_rate_show(struct device *cdev,
 	default:
 		link_rate = adev->link_rate * 8 * 53;
 	}
-	return scnprintf(buf, PAGE_SIZE, "%d\n", link_rate);
+	return sysfs_emit(buf, "%d\n", link_rate);
 }

 static DEVICE_ATTR_RO(address);