diff mbox series

atm: Convert sprintf/snprintf to sysfs_emit

Message ID 20240314084417.1321811-1-lizhijian@fujitsu.com (mailing list archive)
State Deferred
Headers show
Series atm: Convert sprintf/snprintf to sysfs_emit | 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: 939 this patch: 939
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 3 of 3 maintainers
netdev/build_clang success Errors and warnings before: 956 this patch: 956
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: 956 this patch: 956
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 34 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-03-14--12-00 (tests: 908)

Commit Message

Li Zhijian March 14, 2024, 8:44 a.m. UTC
Per filesystems/sysfs.rst, show() should only use sysfs_emit()
or sysfs_emit_at() when formatting the value to be returned to user space.

coccinelle complains that there are still a couple of functions that use
snprintf(). Convert them to sysfs_emit().

sprintf() will be converted as weel if they have.

Generally, this patch is generated by
make coccicheck M=<path/to/file> MODE=patch \
COCCI=scripts/coccinelle/api/device_attr_show.cocci

No functional change intended

CC: Chas Williams <3chas3@gmail.com>
CC: linux-atm-general@lists.sourceforge.net
CC: netdev@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
This is a part of the work "Fix coccicheck device_attr_show warnings"[1]
Split them per subsystem so that the maintainer can review it easily
[1] https://lore.kernel.org/lkml/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 drivers/atm/solos-pci.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Denis Kirjanov March 14, 2024, 9:54 a.m. UTC | #1
On 3/14/24 11:44, Li Zhijian wrote:
> Per filesystems/sysfs.rst, show() should only use sysfs_emit()
> or sysfs_emit_at() when formatting the value to be returned to user space.
> 
> coccinelle complains that there are still a couple of functions that use
> snprintf(). Convert them to sysfs_emit().
> 
> sprintf() will be converted as weel if they have.
> 
> Generally, this patch is generated by
> make coccicheck M=<path/to/file> MODE=patch \
> COCCI=scripts/coccinelle/api/device_attr_show.cocci
> 
> No functional change intended

The patch should be targeted to net-next which is closed now.

> 
> CC: Chas Williams <3chas3@gmail.com>
> CC: linux-atm-general@lists.sourceforge.net
> CC: netdev@vger.kernel.org
> Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
> ---
> This is a part of the work "Fix coccicheck device_attr_show warnings"[1]
> Split them per subsystem so that the maintainer can review it easily
> [1] https://lore.kernel.org/lkml/20240116041129.3937800-1-lizhijian@fujitsu.com/
> ---
>  drivers/atm/solos-pci.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
> index d3c30a28c410..369a7f414f05 100644
> --- a/drivers/atm/solos-pci.c
> +++ b/drivers/atm/solos-pci.c
> @@ -198,8 +198,8 @@ static ssize_t solos_param_show(struct device *dev, struct device_attribute *att
>  
>  	header = skb_put(skb, sizeof(*header));
>  
> -	buflen = snprintf((void *)&header[1], buflen - 1,
> -			  "L%05d\n%s\n", current->pid, attr->attr.name);
> +	buflen = sysfs_emit((void *)&header[1], "L%05d\n%s\n", current->pid,
> +			    attr->attr.name);
>  	skb_put(skb, buflen);
>  
>  	header->size = cpu_to_le16(buflen);
> @@ -453,7 +453,7 @@ static ssize_t console_show(struct device *dev, struct device_attribute *attr,
>  	skb = skb_dequeue(&card->cli_queue[SOLOS_CHAN(atmdev)]);
>  	spin_unlock_bh(&card->cli_queue_lock);
>  	if(skb == NULL)
> -		return sprintf(buf, "No data.\n");
> +		return sysfs_emit(buf, "No data.\n");
>  
>  	len = skb->len;
>  	memcpy(buf, skb->data, len);
> @@ -548,7 +548,7 @@ static ssize_t geos_gpio_show(struct device *dev, struct device_attribute *attr,
>  	data32 = ioread32(card->config_regs + GPIO_STATUS);
>  	data32 = (data32 >> gattr->offset) & 1;
>  
> -	return sprintf(buf, "%d\n", data32);
> +	return sysfs_emit(buf, "%d\n", data32);
>  }
>  
>  static ssize_t hardware_show(struct device *dev, struct device_attribute *attr,
> @@ -569,7 +569,7 @@ static ssize_t hardware_show(struct device *dev, struct device_attribute *attr,
>  		data32 = (data32 >> 5) & 0x0F;
>  		break;
>  	}
> -	return sprintf(buf, "%d\n", data32);
> +	return sysfs_emit(buf, "%d\n", data32);
>  }
>  
>  static DEVICE_ATTR_RW(console);
diff mbox series

Patch

diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
index d3c30a28c410..369a7f414f05 100644
--- a/drivers/atm/solos-pci.c
+++ b/drivers/atm/solos-pci.c
@@ -198,8 +198,8 @@  static ssize_t solos_param_show(struct device *dev, struct device_attribute *att
 
 	header = skb_put(skb, sizeof(*header));
 
-	buflen = snprintf((void *)&header[1], buflen - 1,
-			  "L%05d\n%s\n", current->pid, attr->attr.name);
+	buflen = sysfs_emit((void *)&header[1], "L%05d\n%s\n", current->pid,
+			    attr->attr.name);
 	skb_put(skb, buflen);
 
 	header->size = cpu_to_le16(buflen);
@@ -453,7 +453,7 @@  static ssize_t console_show(struct device *dev, struct device_attribute *attr,
 	skb = skb_dequeue(&card->cli_queue[SOLOS_CHAN(atmdev)]);
 	spin_unlock_bh(&card->cli_queue_lock);
 	if(skb == NULL)
-		return sprintf(buf, "No data.\n");
+		return sysfs_emit(buf, "No data.\n");
 
 	len = skb->len;
 	memcpy(buf, skb->data, len);
@@ -548,7 +548,7 @@  static ssize_t geos_gpio_show(struct device *dev, struct device_attribute *attr,
 	data32 = ioread32(card->config_regs + GPIO_STATUS);
 	data32 = (data32 >> gattr->offset) & 1;
 
-	return sprintf(buf, "%d\n", data32);
+	return sysfs_emit(buf, "%d\n", data32);
 }
 
 static ssize_t hardware_show(struct device *dev, struct device_attribute *attr,
@@ -569,7 +569,7 @@  static ssize_t hardware_show(struct device *dev, struct device_attribute *attr,
 		data32 = (data32 >> 5) & 0x0F;
 		break;
 	}
-	return sprintf(buf, "%d\n", data32);
+	return sysfs_emit(buf, "%d\n", data32);
 }
 
 static DEVICE_ATTR_RW(console);