mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Denis Kirjanov <dkirjanov@suse.de>
To: Li Zhijian <lizhijian@fujitsu.com>, linux-kernel@vger.kernel.org
Cc: Chas Williams <3chas3@gmail.com>,
	linux-atm-general@lists.sourceforge.net, netdev@vger.kernel.org
Subject: Re: [PATCH] atm: Convert sprintf/snprintf to sysfs_emit
Date: Thu, 14 Mar 2024 12:54:22 +0300	[thread overview]
Message-ID: <8cf6fdc9-caa9-43dc-b392-575b4e596dfa@suse.de> (raw)
In-Reply-To: <20240314084417.1321811-1-lizhijian@fujitsu.com>



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);

      reply	other threads:[~2024-03-14  9:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-14  8:44 Li Zhijian
2024-03-14  9:54 ` Denis Kirjanov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8cf6fdc9-caa9-43dc-b392-575b4e596dfa@suse.de \
    --to=dkirjanov@suse.de \
    --cc=3chas3@gmail.com \
    --cc=linux-atm-general@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizhijian@fujitsu.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome