[alsa-devel] [PATCH v2] ALSA: aoa: convert bus code to use dev_groups

Takashi Iwai tiwai at suse.de
Thu Jun 11 12:02:45 CEST 2015


At Thu, 11 Jun 2015 10:03:38 +0200,
Quentin Lambert wrote:
> 
> 
> The dev_attrs field of struct bus_type is going away, use dev_groups instead.
> This converts the soundbus code to use the correct field.
> 
> Given that all other usages of the macro define the struct attribute
> *xxx_attrs[] in the same file they assign the .dev_groups field, this patch
> merges sysfs.c into core.c.
> 
> These modifications were made using Coccinelle.
> 
> Signed-off-by: Quentin Lambert <lambert.quentin at gmail.com>
> ---
>  Changes since v1:
>   - Fix the commit message to actually talk about soundbus rather than MDIO
>   - This version attempt to fix a problem resulting from the macro
>     ATTRIBUTE_GROUPS declaring the structure as static by merging sysfs.c into
>     core.c. I understand that this may not be the prefered solution since 
>     Takashi suggested that adding a comment line to the previous version could
>     be acceptable. 

Hmm, the patch doesn't look as mentioned here.
It's rather bigger than the previous patch.  Is this intentional?


Takashi

> 
>  sound/aoa/soundbus/Makefile   |    2 -
>  sound/aoa/soundbus/core.c     |   44 +++++++++++++++++++++++++++++++++++++++++-
>  sound/aoa/soundbus/soundbus.h |    2 -
>  sound/aoa/soundbus/sysfs.c    |   42 ----------------------------------------
>  4 files changed, 44 insertions(+), 46 deletions(-)
> 
> --- a/sound/aoa/soundbus/Makefile
> +++ b/sound/aoa/soundbus/Makefile
> @@ -1,3 +1,3 @@
>  obj-$(CONFIG_SND_AOA_SOUNDBUS) += snd-aoa-soundbus.o
> -snd-aoa-soundbus-objs := core.o sysfs.o
> +snd-aoa-soundbus-objs := core.o
>  obj-$(CONFIG_SND_AOA_SOUNDBUS_I2S) += i2sbus/
> --- a/sound/aoa/soundbus/core.c
> +++ b/sound/aoa/soundbus/core.c
> @@ -150,6 +150,48 @@ static int soundbus_device_resume(struct
>  
>  #endif /* CONFIG_PM */
>  
> +#define soundbus_config_of_attr(field, format_string)			\
> +static ssize_t								\
> +field##_show (struct device *dev, struct device_attribute *attr,	\
> +              char *buf)						\
> +{									\
> +	struct soundbus_dev *mdev = to_soundbus_device (dev);		\
> +	return sprintf (buf, format_string, mdev->ofdev.dev.of_node->field); \
> +}
> +
> +static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
> +			     char *buf)
> +{
> +	struct soundbus_dev *sdev = to_soundbus_device(dev);
> +	struct platform_device *of = &sdev->ofdev;
> +	int length;
> +
> +	if (*sdev->modalias) {
> +		strlcpy(buf, sdev->modalias, sizeof(sdev->modalias) + 1);
> +		strcat(buf, "\n");
> +		length = strlen(buf);
> +	} else {
> +		length = sprintf(buf, "of:N%sT%s\n",
> +				 of->dev.of_node->name, of->dev.of_node->type);
> +	}
> +
> +	return length;
> +}
> +static DEVICE_ATTR_RO(modalias);
> +
> +soundbus_config_of_attr (name, "%s\n");
> +static DEVICE_ATTR_RO(name);
> +soundbus_config_of_attr (type, "%s\n");
> +static DEVICE_ATTR_RO(type);
> +
> +struct attribute *soundbus_dev_attrs[] = {
> +	&dev_attr_name.attr,
> +	&dev_attr_type.attr,
> +	&dev_attr_modalias.attr,
> +	NULL,
> +};
> +ATTRIBUTE_GROUPS(soundbus_dev);
> +
>  static struct bus_type soundbus_bus_type = {
>  	.name		= "aoa-soundbus",
>  	.probe		= soundbus_probe,
> @@ -160,7 +202,7 @@ static struct bus_type soundbus_bus_type
>  	.suspend	= soundbus_device_suspend,
>  	.resume		= soundbus_device_resume,
>  #endif
> -	.dev_attrs	= soundbus_dev_attrs,
> +	.dev_groups	= soundbus_dev_groups,
>  };
>  
>  int soundbus_add_one(struct soundbus_dev *dev)
> --- a/sound/aoa/soundbus/soundbus.h
> +++ b/sound/aoa/soundbus/soundbus.h
> @@ -199,6 +199,4 @@ struct soundbus_driver {
>  extern int soundbus_register_driver(struct soundbus_driver *drv);
>  extern void soundbus_unregister_driver(struct soundbus_driver *drv);
>  
> -extern struct device_attribute soundbus_dev_attrs[];
> -
>  #endif /* __SOUNDBUS_H */
> --- a/sound/aoa/soundbus/sysfs.c
> +++ /dev/null
> @@ -1,42 +0,0 @@
> -#include <linux/kernel.h>
> -#include <linux/stat.h>
> -/* FIX UP */
> -#include "soundbus.h"
> -
> -#define soundbus_config_of_attr(field, format_string)			\
> -static ssize_t								\
> -field##_show (struct device *dev, struct device_attribute *attr,	\
> -              char *buf)						\
> -{									\
> -	struct soundbus_dev *mdev = to_soundbus_device (dev);		\
> -	return sprintf (buf, format_string, mdev->ofdev.dev.of_node->field); \
> -}
> -
> -static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
> -			     char *buf)
> -{
> -	struct soundbus_dev *sdev = to_soundbus_device(dev);
> -	struct platform_device *of = &sdev->ofdev;
> -	int length;
> -
> -	if (*sdev->modalias) {
> -		strlcpy(buf, sdev->modalias, sizeof(sdev->modalias) + 1);
> -		strcat(buf, "\n");
> -		length = strlen(buf);
> -	} else {
> -		length = sprintf(buf, "of:N%sT%s\n",
> -				 of->dev.of_node->name, of->dev.of_node->type);
> -	}
> -
> -	return length;
> -}
> -
> -soundbus_config_of_attr (name, "%s\n");
> -soundbus_config_of_attr (type, "%s\n");
> -
> -struct device_attribute soundbus_dev_attrs[] = {
> -	__ATTR_RO(name),
> -	__ATTR_RO(type),
> -	__ATTR_RO(modalias),
> -	__ATTR_NULL
> -};
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel at alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
> 


More information about the Alsa-devel mailing list