[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: Clemens Ladisch <clemens@ladisch.de>
diff --git a/sound/core/sound_oss.c b/sound/core/sound_oss.c
index afbfd8d..b9e89ca 100644
--- a/sound/core/sound_oss.c
+++ b/sound/core/sound_oss.c
@@ -38,9 +38,25 @@
 #define SNDRV_OSS_MINORS 128
 
 static struct snd_minor *snd_oss_minors[SNDRV_OSS_MINORS];
-
 static DECLARE_MUTEX(sound_oss_mutex);
 
+void *snd_lookup_oss_minor_data(unsigned int minor, int type)
+{
+	struct snd_minor *mreg;
+	void *private_data;
+
+	if (minor > ARRAY_SIZE(snd_oss_minors))
+		return NULL;
+	down(&sound_oss_mutex);
+	mreg = snd_oss_minors[minor];
+	if (mreg && mreg->type == type)
+		private_data = mreg->private_data;
+	else
+		private_data = NULL;
+	up(&sound_oss_mutex);
+	return private_data;
+}
+
 static int snd_oss_kernel_minor(int type, struct snd_card *card, int dev)
 {
 	int minor;
@@ -78,7 +94,8 @@
 }
 
 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 minor = snd_oss_kernel_minor(type, card, dev);
 	int minor_unit;
@@ -97,6 +114,7 @@
 	preg->card = card ? card->number : -1;
 	preg->device = dev;
 	preg->f_ops = f_ops;
+	preg->private_data = private_data;
 	down(&sound_oss_mutex);
 	snd_oss_minors[minor] = preg;
 	minor_unit = SNDRV_MINOR_OSS_DEVICE(minor);
@@ -121,6 +139,7 @@
 							  carddev);
 		if (register2 != track2)
 			goto __end;
+		snd_oss_minors[track2] = preg;
 	}
 	up(&sound_oss_mutex);
 	return 0;
@@ -163,8 +182,10 @@
 		track2 = SNDRV_MINOR_OSS(cidx, SNDRV_MINOR_OSS_DMMIDI1);
 		break;
 	}
-	if (track2 >= 0)
+	if (track2 >= 0) {
 		unregister_sound_special(track2);
+		snd_oss_minors[track2] = NULL;
+	}
 	snd_oss_minors[minor] = NULL;
 	up(&sound_oss_mutex);
 	kfree(mptr);