@@ -133,29 +133,34 @@ void *snd_lookup_minor_data(unsigned int minor, int type)
133133
134134static int snd_open (struct inode * inode , struct file * file )
135135{
136- int minor = iminor (inode );
137- int card = SNDRV_MINOR_CARD (minor );
138- int dev = SNDRV_MINOR_DEVICE (minor );
136+ unsigned int minor = iminor (inode );
139137 struct snd_minor * mptr = NULL ;
140138 struct file_operations * old_fops ;
141139 int err = 0 ;
142140
143- if (dev != SNDRV_MINOR_GLOBAL ) {
144- if (snd_cards [card ] == NULL ) {
141+ if (minor > ARRAY_SIZE (snd_minors ))
142+ return - ENODEV ;
143+ mptr = snd_minors [minor ];
144+ if (mptr == NULL ) {
145145#ifdef CONFIG_KMOD
146- snd_request_card (card );
146+ int dev = SNDRV_MINOR_DEVICE (minor );
147+ if (dev == SNDRV_MINOR_CONTROL ) {
148+ /* /dev/aloadC? */
149+ int card = SNDRV_MINOR_CARD (minor );
147150 if (snd_cards [card ] == NULL )
148- #endif
149- return - ENODEV ;
150- }
151- } else {
152- #ifdef CONFIG_KMOD
153- if ((mptr = snd_minors [minor ]) == NULL )
151+ snd_request_card (card );
152+ } else if (dev == SNDRV_MINOR_GLOBAL ) {
153+ /* /dev/aloadSEQ */
154154 snd_request_other (minor );
155+ }
156+ #ifndef CONFIG_SND_DYNAMIC_MINORS
157+ /* /dev/snd/{controlC?,seq} */
158+ mptr = snd_minors [minor ];
159+ if (mptr == NULL )
160+ #endif
155161#endif
162+ return - ENODEV ;
156163 }
157- if (mptr == NULL && (mptr = snd_minors [minor ]) == NULL )
158- return - ENODEV ;
159164 old_fops = file -> f_op ;
160165 file -> f_op = fops_get (mptr -> f_ops );
161166 if (file -> f_op -> open )
@@ -174,6 +179,22 @@ static struct file_operations snd_fops =
174179 .open = snd_open
175180};
176181
182+ #ifdef CONFIG_SND_DYNAMIC_MINORS
183+ static int snd_find_free_minor (void )
184+ {
185+ int minor ;
186+
187+ for (minor = 0 ; minor < ARRAY_SIZE (snd_minors ); ++ minor ) {
188+ /* skip minors still used statically for autoloading devices */
189+ if (SNDRV_MINOR_DEVICE (minor ) == SNDRV_MINOR_CONTROL ||
190+ minor == SNDRV_MINOR_SEQUENCER )
191+ continue ;
192+ if (!snd_minors [minor ])
193+ return minor ;
194+ }
195+ return - EBUSY ;
196+ }
197+ #else
177198static int snd_kernel_minor (int type , struct snd_card * card , int dev )
178199{
179200 int minor ;
@@ -200,6 +221,7 @@ static int snd_kernel_minor(int type, struct snd_card *card, int dev)
200221 snd_assert (minor >= 0 && minor < SNDRV_OS_MINORS , return - EINVAL );
201222 return minor ;
202223}
224+ #endif
203225
204226/**
205227 * snd_register_device - Register the ALSA device file for the card
@@ -219,12 +241,10 @@ int snd_register_device(int type, struct snd_card *card, int dev,
219241 struct file_operations * f_ops , void * private_data ,
220242 const char * name )
221243{
222- int minor = snd_kernel_minor ( type , card , dev ) ;
244+ int minor ;
223245 struct snd_minor * preg ;
224246 struct device * device = NULL ;
225247
226- if (minor < 0 )
227- return minor ;
228248 snd_assert (name , return - EINVAL );
229249 preg = kmalloc (sizeof (struct snd_minor ) + strlen (name ) + 1 , GFP_KERNEL );
230250 if (preg == NULL )
@@ -236,10 +256,17 @@ int snd_register_device(int type, struct snd_card *card, int dev,
236256 preg -> private_data = private_data ;
237257 strcpy (preg -> name , name );
238258 down (& sound_mutex );
239- if (snd_minors [minor ]) {
259+ #ifdef CONFIG_SND_DYNAMIC_MINORS
260+ minor = snd_find_free_minor ();
261+ #else
262+ minor = snd_kernel_minor (type , card , dev );
263+ if (minor >= 0 && snd_minors [minor ])
264+ minor = - EBUSY ;
265+ #endif
266+ if (minor < 0 ) {
240267 up (& sound_mutex );
241268 kfree (preg );
242- return - EBUSY ;
269+ return minor ;
243270 }
244271 snd_minors [minor ] = preg ;
245272 if (type != SNDRV_DEVICE_TYPE_CONTROL || preg -> card >= cards_limit )
0 commit comments