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>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <8cf6fdc9-caa9-43dc-b392-575b4e596dfa@suse.de>
Date: Thu, 14 Mar 2024 12:54:22 +0300
From: Denis Kirjanov <dkirjanov@...e.de>
To: Li Zhijian <lizhijian@...itsu.com>, linux-kernel@...r.kernel.org
Cc: Chas Williams <3chas3@...il.com>,
 linux-atm-general@...ts.sourceforge.net, netdev@...r.kernel.org
Subject: Re: [PATCH] atm: Convert sprintf/snprintf to sysfs_emit



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@...il.com>
> CC: linux-atm-general@...ts.sourceforge.net
> CC: netdev@...r.kernel.org
> Signed-off-by: Li Zhijian <lizhijian@...itsu.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);

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ