mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Xuezhi Zhang <zhangxuezhi1@coolpad.com>, gregkh@linuxfoundation.org
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] usb: core: sysfs: convert sysfs snprintf to sysfs_emit
Date: Fri, 24 Jun 2022 05:37:08 -0700	[thread overview]
Message-ID: <85d412b8b2413d98e429ec129880f69e99c98539.camel@perches.com> (raw)
In-Reply-To: <20220624121238.134256-1-zhangxuezhi1@coolpad.com>

On Fri, 2022-06-24 at 20:12 +0800, Xuezhi Zhang wrote:
> Fix up all sysfs show entries to use sysfs_emit

Thanks.

Some trivia: (perhaps for a separate patch)

> diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
[]
> @@ -35,7 +35,7 @@ static ssize_t field##_show(struct device *dev,				\
>  		return -EINTR;						\
>  	actconfig = udev->actconfig;					\
>  	if (actconfig)							\
> -		rc = sprintf(buf, format_string,			\
> +		rc = sysfs_emit(buf, format_string,			\
>  				actconfig->desc.field);			\

It's much more common to use fmt and not format_string

Using fmt would make several multi-line statements fit on a single line

e.g.:

		rc = sysfs_emit(buf, fmt, actconfig->desc.field);	\

> @@ -305,8 +305,8 @@ static ssize_t ltm_capable_show(struct device *dev,
>  				struct device_attribute *attr, char *buf)
>  {
>  	if (usb_device_supports_ltm(to_usb_device(dev)))
> -		return sprintf(buf, "%s\n", "yes");
> -	return sprintf(buf, "%s\n", "no");
> +		return sysfs_emit(buf, "%s\n", "yes");
> +	return sysfs_emit(buf, "%s\n", "no");

Using a ?: might be nicer

	return sysfs_emit(buf, "%s\n",
			  usb_device_supports_ltm(to_usb_device(dev)) ? "yes" : "no");

>  static ssize_t persist_store(struct device *dev, struct device_attribute *attr,
> @@ -372,7 +372,7 @@ static ssize_t connected_duration_show(struct device *dev,
>  {
>  	struct usb_device *udev = to_usb_device(dev);
>  
> -	return sprintf(buf, "%u\n",
> +	return sysfs_emit(buf, "%u\n",
>  			jiffies_to_msecs(jiffies - udev->connect_time));

Might be nicer to rewrap multi-line statements to the open parenthesis

	return sysfs_emit(buf, "%u\n",
			  jiffies_to_msecs(jiffies - udev->connect_time));



      reply	other threads:[~2022-06-24 12:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-24 12:12 Xuezhi Zhang
2022-06-24 12:37 ` Joe Perches [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=85d412b8b2413d98e429ec129880f69e99c98539.camel@perches.com \
    --to=joe@perches.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=zhangxuezhi1@coolpad.com \
    /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

all inboxes | Powered by JetHome®