Commit f87135f5 authored by Clemens Ladisch's avatar Clemens Ladisch Committed by Jaroslav Kysela
Browse files

[ALSA] dynamic minors (3/6): store device-specific object pointers dynamically



Instead of storing the pointers to the device-specific structures in an
array, put them into the struct snd_minor, and look them up dynamically.

This makes the device type modules independent of the minor number
encoding.

Signed-off-by: default avatarClemens Ladisch <clemens@ladisch.de>
parent 6983b724
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -187,6 +187,7 @@ struct snd_minor {
	int card;			/* card number */
	int device;			/* device number */
	struct file_operations *f_ops;	/* file operations */
	void *private_data;		/* private data for f_ops->open */
	char name[0];			/* device name (keep at the end of
								structure) */
};
@@ -199,13 +200,17 @@ extern int snd_ecards_limit;
void snd_request_card(int card);

int snd_register_device(int type, struct snd_card *card, int dev,
			struct file_operations *f_ops, const char *name);
			struct file_operations *f_ops, void *private_data,
			const char *name);
int snd_unregister_device(int type, struct snd_card *card, int dev);
void *snd_lookup_minor_data(unsigned int minor, int type);

#ifdef CONFIG_SND_OSSEMUL
int snd_register_oss_device(int type, struct snd_card *card, int dev,
			    struct file_operations *f_ops, const char *name);
			    struct file_operations *f_ops, void *private_data,
			    const char *name);
int snd_unregister_oss_device(int type, struct snd_card *card, int dev);
void *snd_lookup_oss_minor_data(unsigned int minor, int type);
#endif

int snd_minor_info_init(void);
+1 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ struct snd_hwdep_ops {

struct snd_hwdep {
	struct snd_card *card;
	struct list_head list;
	int device;
	char id[32];
	char name[80];
+1 −1
Original line number Diff line number Diff line
@@ -412,6 +412,7 @@ struct snd_pcm_str {

struct snd_pcm {
	struct snd_card *card;
	struct list_head list;
	unsigned int device;	/* device number */
	unsigned int info_flags;
	unsigned short dev_class;
@@ -439,7 +440,6 @@ struct snd_pcm_notify {
 *  Registering
 */

extern struct snd_pcm *snd_pcm_devices[];
extern struct file_operations snd_pcm_f_ops[2];

int snd_pcm_new(struct snd_card *card, char *id, int device,
+3 −3
Original line number Diff line number Diff line
@@ -113,7 +113,7 @@ struct snd_rawmidi_str {

struct snd_rawmidi {
	struct snd_card *card;

	struct list_head list;
	unsigned int device;		/* device number */
	unsigned int info_flags;	/* SNDRV_RAWMIDI_INFO_XXXX */
	char id[64];
@@ -165,8 +165,8 @@ int snd_rawmidi_transmit(struct snd_rawmidi_substream *substream,
/* main midi functions */

int snd_rawmidi_info_select(struct snd_card *card, struct snd_rawmidi_info *info);
int snd_rawmidi_kernel_open(int cardnum, int device, int subdevice, int mode,
			    struct snd_rawmidi_file *rfile);
int snd_rawmidi_kernel_open(struct snd_card *card, int device, int subdevice,
			    int mode, struct snd_rawmidi_file *rfile);
int snd_rawmidi_kernel_release(struct snd_rawmidi_file *rfile);
int snd_rawmidi_output_params(struct snd_rawmidi_substream *substream,
			      struct snd_rawmidi_params *params);
+3 −4
Original line number Diff line number Diff line
@@ -47,13 +47,12 @@ static LIST_HEAD(snd_control_compat_ioctls);

static int snd_ctl_open(struct inode *inode, struct file *file)
{
	int cardnum = SNDRV_MINOR_CARD(iminor(inode));
	unsigned long flags;
	struct snd_card *card;
	struct snd_ctl_file *ctl;
	int err;

	card = snd_cards[cardnum];
	card = snd_lookup_minor_data(iminor(inode), SNDRV_DEVICE_TYPE_CONTROL);
	if (!card) {
		err = -ENODEV;
		goto __error1;
@@ -1277,8 +1276,8 @@ static int snd_ctl_dev_register(struct snd_device *device)
	cardnum = card->number;
	snd_assert(cardnum >= 0 && cardnum < SNDRV_CARDS, return -ENXIO);
	sprintf(name, "controlC%i", cardnum);
	if ((err = snd_register_device(SNDRV_DEVICE_TYPE_CONTROL,
				       card, -1, &snd_ctl_f_ops, name)) < 0)
	if ((err = snd_register_device(SNDRV_DEVICE_TYPE_CONTROL, card, -1,
				       &snd_ctl_f_ops, card, name)) < 0)
		return err;
	return 0;
}
Loading