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

Commit 40a4b263 authored by Takashi Iwai's avatar Takashi Iwai
Browse files

ALSA: Simplify snd_device_register() variants



Now that all callers have been replaced with
snd_device_register_for_dev(), let's drop the obsolete device
registration code and concentrate only on the code handling struct
device directly.  That said,

- remove the old snd_device_register(),
- rename snd_device_register_for_dev() with snd_device_register(),
- drop superfluous arguments from snd_device_register(),
- change snd_unregister_device() to pass the device pointer directly

Reviewed-by: default avatarJaroslav Kysela <perex@perex.cz>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 04c5d5a4
Loading
Loading
Loading
Loading
+4 −35
Original line number Diff line number Diff line
@@ -187,7 +187,6 @@ struct snd_minor {
	int type;			/* SNDRV_DEVICE_TYPE_XXX */
	int card;			/* card number */
	int device;			/* device number */
	bool created;
	const struct file_operations *f_ops;	/* file operations */
	void *private_data;		/* private data for f_ops->open */
	struct device *dev;		/* device for sysfs */
@@ -210,40 +209,10 @@ void snd_request_card(int card);

void snd_device_initialize(struct device *dev, struct snd_card *card);

int snd_register_device_for_dev(int type, struct snd_card *card, int dev,
int snd_register_device(int type, struct snd_card *card, int dev,
			const struct file_operations *f_ops,
				void *private_data, struct device *device,
				struct device *parent, const char *name);

/**
 * snd_register_device - Register the ALSA device file for the card
 * @type: the device type, SNDRV_DEVICE_TYPE_XXX
 * @card: the card instance
 * @dev: the device index
 * @f_ops: the file operations
 * @private_data: user pointer for f_ops->open()
 * @name: the device file name
 *
 * Registers an ALSA device file for the given card.
 * The operators have to be set in reg parameter.
 *
 * This function uses the card's device pointer to link to the
 * correct &struct device.
 *
 * Return: Zero if successful, or a negative error code on failure.
 */
static inline int snd_register_device(int type, struct snd_card *card, int dev,
				      const struct file_operations *f_ops,
				      void *private_data,
				      const char *name)
{
	return snd_register_device_for_dev(type, card, dev, f_ops,
					   private_data, NULL,
					   snd_card_get_device_link(card),
					   name);
}

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

+4 −6
Original line number Diff line number Diff line
@@ -871,10 +871,9 @@ static int snd_compress_dev_register(struct snd_device *device)
	pr_debug("reg %s for device %s, direction %d\n", str, compr->name,
			compr->direction);
	/* register compressed device */
	ret = snd_register_device_for_dev(SNDRV_DEVICE_TYPE_COMPRESS,
	ret = snd_register_device(SNDRV_DEVICE_TYPE_COMPRESS,
				  compr->card, compr->device,
					  &snd_compr_file_ops, compr,
					  &compr->dev, NULL, NULL);
				  &snd_compr_file_ops, compr, &compr->dev);
	if (ret < 0) {
		pr_err("snd_register_device failed\n %d", ret);
		return ret;
@@ -888,8 +887,7 @@ static int snd_compress_dev_disconnect(struct snd_device *device)
	struct snd_compr *compr;

	compr = device->device_data;
	snd_unregister_device(SNDRV_DEVICE_TYPE_COMPRESS, compr->card,
		compr->device);
	snd_unregister_device(&compr->dev);
	return 0;
}

+3 −4
Original line number Diff line number Diff line
@@ -1661,9 +1661,8 @@ static int snd_ctl_dev_register(struct snd_device *device)
{
	struct snd_card *card = device->device_data;

	return snd_register_device_for_dev(SNDRV_DEVICE_TYPE_CONTROL, card,
					   -1, &snd_ctl_f_ops, card,
					   &card->ctl_dev, NULL, NULL);
	return snd_register_device(SNDRV_DEVICE_TYPE_CONTROL, card, -1,
				   &snd_ctl_f_ops, card, &card->ctl_dev);
}

/*
@@ -1681,7 +1680,7 @@ static int snd_ctl_dev_disconnect(struct snd_device *device)
	}
	read_unlock(&card->ctl_files_rwlock);

	return snd_unregister_device(SNDRV_DEVICE_TYPE_CONTROL, card, -1);
	return snd_unregister_device(&card->ctl_dev);
}

/*
+4 −5
Original line number Diff line number Diff line
@@ -432,10 +432,9 @@ static int snd_hwdep_dev_register(struct snd_device *device)
		return -EBUSY;
	}
	list_add_tail(&hwdep->list, &snd_hwdep_devices);
	err = snd_register_device_for_dev(SNDRV_DEVICE_TYPE_HWDEP,
	err = snd_register_device(SNDRV_DEVICE_TYPE_HWDEP,
				  hwdep->card, hwdep->device,
					  &snd_hwdep_f_ops, hwdep,
					  &hwdep->dev, NULL, NULL);
				  &snd_hwdep_f_ops, hwdep, &hwdep->dev);
	if (err < 0) {
		dev_err(&hwdep->dev, "unable to register\n");
		list_del(&hwdep->list);
@@ -480,7 +479,7 @@ static int snd_hwdep_dev_disconnect(struct snd_device *device)
	if (hwdep->ossreg)
		snd_unregister_oss_device(hwdep->oss_type, hwdep->card, hwdep->device);
#endif
	snd_unregister_device(SNDRV_DEVICE_TYPE_HWDEP, hwdep->card, hwdep->device);
	snd_unregister_device(&hwdep->dev);
	list_del_init(&hwdep->list);
	mutex_unlock(&hwdep->open_mutex);
	mutex_unlock(&register_mutex);
+5 −16
Original line number Diff line number Diff line
@@ -1105,11 +1105,9 @@ static int snd_pcm_dev_register(struct snd_device *device)
			break;
		}
		/* register pcm */
		err = snd_register_device_for_dev(devtype, pcm->card,
						  pcm->device,
						  &snd_pcm_f_ops[cidx],
						  pcm, &pcm->streams[cidx].dev,
						  NULL, NULL);
		err = snd_register_device(devtype, pcm->card, pcm->device,
					  &snd_pcm_f_ops[cidx], pcm,
					  &pcm->streams[cidx].dev);
		if (err < 0) {
			list_del(&pcm->list);
			mutex_unlock(&register_mutex);
@@ -1132,7 +1130,7 @@ static int snd_pcm_dev_disconnect(struct snd_device *device)
	struct snd_pcm *pcm = device->device_data;
	struct snd_pcm_notify *notify;
	struct snd_pcm_substream *substream;
	int cidx, devtype;
	int cidx;

	mutex_lock(&register_mutex);
	if (list_empty(&pcm->list))
@@ -1155,16 +1153,7 @@ static int snd_pcm_dev_disconnect(struct snd_device *device)
		notify->n_disconnect(pcm);
	}
	for (cidx = 0; cidx < 2; cidx++) {
		devtype = -1;
		switch (cidx) {
		case SNDRV_PCM_STREAM_PLAYBACK:
			devtype = SNDRV_DEVICE_TYPE_PCM_PLAYBACK;
			break;
		case SNDRV_PCM_STREAM_CAPTURE:
			devtype = SNDRV_DEVICE_TYPE_PCM_CAPTURE;
			break;
		}
		snd_unregister_device(devtype, pcm->card, pcm->device);
		snd_unregister_device(&pcm->streams[cidx].dev);
		if (pcm->streams[cidx].chmap_kctl) {
			snd_ctl_remove(pcm->card, pcm->streams[cidx].chmap_kctl);
			pcm->streams[cidx].chmap_kctl = NULL;
Loading