Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit caa751ba authored by Takashi Iwai's avatar Takashi Iwai
Browse files

ALSA: Create sysfs attribute files via groups



Instead of calling each time device_create_file(), create the groups
of sysfs attribute files at once in a normal way.  Add a new helper
function, snd_get_device(), to return the associated device object,
so that we can handle the sysfs addition locally.

Since the sysfs file addition is done differently now,
snd_add_device_sysfs_file() helper function is removed.

Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent d01a838c
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -248,8 +248,7 @@ static inline int snd_register_device(int type, struct snd_card *card, int dev,

int snd_unregister_device(int type, struct snd_card *card, int dev);
void *snd_lookup_minor_data(unsigned int minor, int type);
int snd_add_device_sysfs_file(int type, struct snd_card *card, int dev,
			      struct device_attribute *attr);
struct device *snd_get_device(int type, struct snd_card *card, int dev);

#ifdef CONFIG_SND_OSSEMUL
int snd_register_oss_device(int type, struct snd_card *card, int dev,
+1 −0
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ struct snd_hwdep {
	wait_queue_head_t open_wait;
	void *private_data;
	void (*private_free) (struct snd_hwdep *hwdep);
	const struct attribute_group **groups;

	struct mutex open_mutex;
	int used;			/* reference counter */
+14 −0
Original line number Diff line number Diff line
@@ -436,6 +436,20 @@ static int snd_hwdep_dev_register(struct snd_device *device)
		mutex_unlock(&register_mutex);
		return err;
	}

	if (hwdep->groups) {
		struct device *d = snd_get_device(SNDRV_DEVICE_TYPE_HWDEP,
						  hwdep->card, hwdep->device);
		if (d) {
			err = sysfs_create_groups(&d->kobj, hwdep->groups);
			if (err < 0)
				dev_warn(card->dev,
					 "hwdep %d:%d: cannot create sysfs groups\n",
					 card->number, hwdep->device);
			put_device(d);
		}
	}

#ifdef CONFIG_SND_OSSEMUL
	hwdep->ossreg = 0;
	if (hwdep->oss_type >= 0) {
+26 −4
Original line number Diff line number Diff line
@@ -1018,8 +1018,20 @@ static ssize_t show_pcm_class(struct device *dev,
        return snprintf(buf, PAGE_SIZE, "%s\n", str);
}

static struct device_attribute pcm_attrs =
	__ATTR(pcm_class, S_IRUGO, show_pcm_class, NULL);
static DEVICE_ATTR(pcm_class, S_IRUGO, show_pcm_class, NULL);
static struct attribute *pcm_dev_attrs[] = {
	&dev_attr_pcm_class.attr,
	NULL
};

static struct attribute_group pcm_dev_attr_group = {
	.attrs	= pcm_dev_attrs,
};

static const struct attribute_group *pcm_dev_attr_groups[] = {
	&pcm_dev_attr_group,
	NULL
};

static int snd_pcm_dev_register(struct snd_device *device)
{
@@ -1069,8 +1081,18 @@ static int snd_pcm_dev_register(struct snd_device *device)
			mutex_unlock(&register_mutex);
			return err;
		}
		snd_add_device_sysfs_file(devtype, pcm->card, pcm->device,
					  &pcm_attrs);

		dev = snd_get_device(devtype, pcm->card, pcm->device);
		if (dev) {
			err = sysfs_create_groups(&dev->kobj,
						  pcm_dev_attr_groups);
			if (err < 0)
				dev_warn(dev,
					 "pcm %d:%d: cannot create sysfs groups\n",
					 pcm->card->number, pcm->device);
			put_device(dev);
		}

		for (substream = pcm->streams[cidx].substream; substream; substream = substream->next)
			snd_pcm_timer_init(substream);
	}
+13 −10
Original line number Diff line number Diff line
@@ -355,22 +355,25 @@ int snd_unregister_device(int type, struct snd_card *card, int dev)

EXPORT_SYMBOL(snd_unregister_device);

int snd_add_device_sysfs_file(int type, struct snd_card *card, int dev,
			      struct device_attribute *attr)
/* get the assigned device to the given type and device number;
 * the caller needs to release it via put_device() after using it
 */
struct device *snd_get_device(int type, struct snd_card *card, int dev)
{
	int minor, ret = -EINVAL;
	struct device *d;
	int minor;
	struct device *d = NULL;

	mutex_lock(&sound_mutex);
	minor = find_snd_minor(type, card, dev);
	if (minor >= 0 && (d = snd_minors[minor]->dev) != NULL)
		ret = device_create_file(d, attr);
	if (minor >= 0) {
		d = snd_minors[minor]->dev;
		if (d)
			get_device(d);
	}
	mutex_unlock(&sound_mutex);
	return ret;

	return d;
}

EXPORT_SYMBOL(snd_add_device_sysfs_file);
EXPORT_SYMBOL(snd_get_device);

#ifdef CONFIG_PROC_FS
/*
Loading