All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: YueHaibing <yuehaibing@huawei.com>
Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org,
	tiwai@suse.com
Subject: Re: [PATCH -next] ALSA: control_led - use DEVICE_ATTR_*() macro
Date: Sun, 23 May 2021 18:11:33 +0900	[thread overview]
Message-ID: <20210523091133.GA220048@workstation> (raw)
In-Reply-To: <20210523071109.28940-1-yuehaibing@huawei.com>

On Sun, May 23, 2021 at 03:11:09PM +0800, YueHaibing wrote:
> Use DEVICE_ATTR_*() helper instead of plain DEVICE_ATTR,
> which makes the code a bit shorter and easier to read.
> 
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
>  sound/core/control_led.c | 34 +++++++++++++++++++---------------
>  1 file changed, 19 insertions(+), 15 deletions(-)
 
The usage of common macro is better way for safe than own way as long as
achieving the same function. This looks good to me.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>

> diff --git a/sound/core/control_led.c b/sound/core/control_led.c
> index 25f57c14f294..a5e751f26d46 100644
> --- a/sound/core/control_led.c
> +++ b/sound/core/control_led.c
> @@ -375,7 +375,7 @@ static void snd_ctl_led_disconnect(struct snd_card *card)
>   * sysfs
>   */
>  
> -static ssize_t show_mode(struct device *dev,
> +static ssize_t mode_show(struct device *dev,
>  			 struct device_attribute *attr, char *buf)
>  {
>  	struct snd_ctl_led *led = container_of(dev, struct snd_ctl_led, dev);
> @@ -390,7 +390,8 @@ static ssize_t show_mode(struct device *dev,
>  	return sprintf(buf, "%s\n", str);
>  }
>  
> -static ssize_t store_mode(struct device *dev, struct device_attribute *attr,
> +static ssize_t mode_store(struct device *dev,
> +			  struct device_attribute *attr,
>  			  const char *buf, size_t count)
>  {
>  	struct snd_ctl_led *led = container_of(dev, struct snd_ctl_led, dev);
> @@ -419,7 +420,7 @@ static ssize_t store_mode(struct device *dev, struct device_attribute *attr,
>  	return count;
>  }
>  
> -static ssize_t show_brightness(struct device *dev,
> +static ssize_t brightness_show(struct device *dev,
>  			       struct device_attribute *attr, char *buf)
>  {
>  	struct snd_ctl_led *led = container_of(dev, struct snd_ctl_led, dev);
> @@ -427,8 +428,8 @@ static ssize_t show_brightness(struct device *dev,
>  	return sprintf(buf, "%u\n", ledtrig_audio_get(led->trigger_type));
>  }
>  
> -static DEVICE_ATTR(mode, 0644, show_mode, store_mode);
> -static DEVICE_ATTR(brightness, 0444, show_brightness, NULL);
> +static DEVICE_ATTR_RW(mode);
> +static DEVICE_ATTR_RO(brightness);
>  
>  static struct attribute *snd_ctl_led_dev_attrs[] = {
>  	&dev_attr_mode.attr,
> @@ -562,22 +563,25 @@ static ssize_t set_led_id(struct snd_ctl_led_card *led_card, const char *buf, si
>  	return count;
>  }
>  
> -static ssize_t parse_attach(struct device *dev, struct device_attribute *attr,
> +static ssize_t attach_store(struct device *dev,
> +			    struct device_attribute *attr,
>  			    const char *buf, size_t count)
>  {
>  	struct snd_ctl_led_card *led_card = container_of(dev, struct snd_ctl_led_card, dev);
>  	return set_led_id(led_card, buf, count, true);
>  }
>  
> -static ssize_t parse_detach(struct device *dev, struct device_attribute *attr,
> +static ssize_t detach_store(struct device *dev,
> +			    struct device_attribute *attr,
>  			    const char *buf, size_t count)
>  {
>  	struct snd_ctl_led_card *led_card = container_of(dev, struct snd_ctl_led_card, dev);
>  	return set_led_id(led_card, buf, count, false);
>  }
>  
> -static ssize_t ctl_reset(struct device *dev, struct device_attribute *attr,
> -			 const char *buf, size_t count)
> +static ssize_t reset_store(struct device *dev,
> +			   struct device_attribute *attr,
> +			   const char *buf, size_t count)
>  {
>  	struct snd_ctl_led_card *led_card = container_of(dev, struct snd_ctl_led_card, dev);
>  	int err;
> @@ -590,8 +594,8 @@ static ssize_t ctl_reset(struct device *dev, struct device_attribute *attr,
>  	return count;
>  }
>  
> -static ssize_t ctl_list(struct device *dev,
> -			struct device_attribute *attr, char *buf)
> +static ssize_t list_show(struct device *dev,
> +			 struct device_attribute *attr, char *buf)
>  {
>  	struct snd_ctl_led_card *led_card = container_of(dev, struct snd_ctl_led_card, dev);
>  	struct snd_card *card;
> @@ -624,10 +628,10 @@ static ssize_t ctl_list(struct device *dev,
>  	return buf2 - buf;
>  }
>  
> -static DEVICE_ATTR(attach, 0200, NULL, parse_attach);
> -static DEVICE_ATTR(detach, 0200, NULL, parse_detach);
> -static DEVICE_ATTR(reset, 0200, NULL, ctl_reset);
> -static DEVICE_ATTR(list, 0444, ctl_list, NULL);
> +static DEVICE_ATTR_WO(attach);
> +static DEVICE_ATTR_WO(detach);
> +static DEVICE_ATTR_WO(reset);
> +static DEVICE_ATTR_RO(list);
>  
>  static struct attribute *snd_ctl_led_card_attrs[] = {
>  	&dev_attr_attach.attr,
> -- 
> 2.17.1
 

Regards

Takashi Sakamoto

WARNING: multiple messages have this Message-ID (diff)
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: YueHaibing <yuehaibing@huawei.com>
Cc: perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH -next] ALSA: control_led - use DEVICE_ATTR_*() macro
Date: Sun, 23 May 2021 18:11:33 +0900	[thread overview]
Message-ID: <20210523091133.GA220048@workstation> (raw)
In-Reply-To: <20210523071109.28940-1-yuehaibing@huawei.com>

On Sun, May 23, 2021 at 03:11:09PM +0800, YueHaibing wrote:
> Use DEVICE_ATTR_*() helper instead of plain DEVICE_ATTR,
> which makes the code a bit shorter and easier to read.
> 
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
>  sound/core/control_led.c | 34 +++++++++++++++++++---------------
>  1 file changed, 19 insertions(+), 15 deletions(-)
 
The usage of common macro is better way for safe than own way as long as
achieving the same function. This looks good to me.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>

> diff --git a/sound/core/control_led.c b/sound/core/control_led.c
> index 25f57c14f294..a5e751f26d46 100644
> --- a/sound/core/control_led.c
> +++ b/sound/core/control_led.c
> @@ -375,7 +375,7 @@ static void snd_ctl_led_disconnect(struct snd_card *card)
>   * sysfs
>   */
>  
> -static ssize_t show_mode(struct device *dev,
> +static ssize_t mode_show(struct device *dev,
>  			 struct device_attribute *attr, char *buf)
>  {
>  	struct snd_ctl_led *led = container_of(dev, struct snd_ctl_led, dev);
> @@ -390,7 +390,8 @@ static ssize_t show_mode(struct device *dev,
>  	return sprintf(buf, "%s\n", str);
>  }
>  
> -static ssize_t store_mode(struct device *dev, struct device_attribute *attr,
> +static ssize_t mode_store(struct device *dev,
> +			  struct device_attribute *attr,
>  			  const char *buf, size_t count)
>  {
>  	struct snd_ctl_led *led = container_of(dev, struct snd_ctl_led, dev);
> @@ -419,7 +420,7 @@ static ssize_t store_mode(struct device *dev, struct device_attribute *attr,
>  	return count;
>  }
>  
> -static ssize_t show_brightness(struct device *dev,
> +static ssize_t brightness_show(struct device *dev,
>  			       struct device_attribute *attr, char *buf)
>  {
>  	struct snd_ctl_led *led = container_of(dev, struct snd_ctl_led, dev);
> @@ -427,8 +428,8 @@ static ssize_t show_brightness(struct device *dev,
>  	return sprintf(buf, "%u\n", ledtrig_audio_get(led->trigger_type));
>  }
>  
> -static DEVICE_ATTR(mode, 0644, show_mode, store_mode);
> -static DEVICE_ATTR(brightness, 0444, show_brightness, NULL);
> +static DEVICE_ATTR_RW(mode);
> +static DEVICE_ATTR_RO(brightness);
>  
>  static struct attribute *snd_ctl_led_dev_attrs[] = {
>  	&dev_attr_mode.attr,
> @@ -562,22 +563,25 @@ static ssize_t set_led_id(struct snd_ctl_led_card *led_card, const char *buf, si
>  	return count;
>  }
>  
> -static ssize_t parse_attach(struct device *dev, struct device_attribute *attr,
> +static ssize_t attach_store(struct device *dev,
> +			    struct device_attribute *attr,
>  			    const char *buf, size_t count)
>  {
>  	struct snd_ctl_led_card *led_card = container_of(dev, struct snd_ctl_led_card, dev);
>  	return set_led_id(led_card, buf, count, true);
>  }
>  
> -static ssize_t parse_detach(struct device *dev, struct device_attribute *attr,
> +static ssize_t detach_store(struct device *dev,
> +			    struct device_attribute *attr,
>  			    const char *buf, size_t count)
>  {
>  	struct snd_ctl_led_card *led_card = container_of(dev, struct snd_ctl_led_card, dev);
>  	return set_led_id(led_card, buf, count, false);
>  }
>  
> -static ssize_t ctl_reset(struct device *dev, struct device_attribute *attr,
> -			 const char *buf, size_t count)
> +static ssize_t reset_store(struct device *dev,
> +			   struct device_attribute *attr,
> +			   const char *buf, size_t count)
>  {
>  	struct snd_ctl_led_card *led_card = container_of(dev, struct snd_ctl_led_card, dev);
>  	int err;
> @@ -590,8 +594,8 @@ static ssize_t ctl_reset(struct device *dev, struct device_attribute *attr,
>  	return count;
>  }
>  
> -static ssize_t ctl_list(struct device *dev,
> -			struct device_attribute *attr, char *buf)
> +static ssize_t list_show(struct device *dev,
> +			 struct device_attribute *attr, char *buf)
>  {
>  	struct snd_ctl_led_card *led_card = container_of(dev, struct snd_ctl_led_card, dev);
>  	struct snd_card *card;
> @@ -624,10 +628,10 @@ static ssize_t ctl_list(struct device *dev,
>  	return buf2 - buf;
>  }
>  
> -static DEVICE_ATTR(attach, 0200, NULL, parse_attach);
> -static DEVICE_ATTR(detach, 0200, NULL, parse_detach);
> -static DEVICE_ATTR(reset, 0200, NULL, ctl_reset);
> -static DEVICE_ATTR(list, 0444, ctl_list, NULL);
> +static DEVICE_ATTR_WO(attach);
> +static DEVICE_ATTR_WO(detach);
> +static DEVICE_ATTR_WO(reset);
> +static DEVICE_ATTR_RO(list);
>  
>  static struct attribute *snd_ctl_led_card_attrs[] = {
>  	&dev_attr_attach.attr,
> -- 
> 2.17.1
 

Regards

Takashi Sakamoto

  reply	other threads:[~2021-05-23  9:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-23  7:11 [PATCH -next] ALSA: control_led - use DEVICE_ATTR_*() macro YueHaibing
2021-05-23  7:11 ` YueHaibing
2021-05-23  9:11 ` Takashi Sakamoto [this message]
2021-05-23  9:11   ` Takashi Sakamoto
2021-05-25  8:32 ` Takashi Iwai
2021-05-25  8:32   ` Takashi Iwai

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=20210523091133.GA220048@workstation \
    --to=o-takashi@sakamocchi.jp \
    --cc=alsa-devel@alsa-project.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tiwai@suse.com \
    --cc=yuehaibing@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.