@@ -35,18 +35,27 @@ MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
3535MODULE_DESCRIPTION ("Hardware dependent layer" );
3636MODULE_LICENSE ("GPL" );
3737
38- static struct snd_hwdep * snd_hwdep_devices [SNDRV_CARDS * SNDRV_MINOR_HWDEPS ];
39-
38+ static LIST_HEAD (snd_hwdep_devices );
4039static DECLARE_MUTEX (register_mutex );
4140
4241static int snd_hwdep_free (struct snd_hwdep * hwdep );
4342static int snd_hwdep_dev_free (struct snd_device * device );
4443static int snd_hwdep_dev_register (struct snd_device * device );
4544static int snd_hwdep_dev_unregister (struct snd_device * device );
4645
47- /*
4846
49- */
47+ static struct snd_hwdep * snd_hwdep_search (struct snd_card * card , int device )
48+ {
49+ struct list_head * p ;
50+ struct snd_hwdep * hwdep ;
51+
52+ list_for_each (p , & snd_hwdep_devices ) {
53+ hwdep = list_entry (p , struct snd_hwdep , list );
54+ if (hwdep -> card == card && hwdep -> device == device )
55+ return hwdep ;
56+ }
57+ return NULL ;
58+ }
5059
5160static loff_t snd_hwdep_llseek (struct file * file , loff_t offset , int orig )
5261{
@@ -77,34 +86,25 @@ static ssize_t snd_hwdep_write(struct file * file, const char __user *buf,
7786static int snd_hwdep_open (struct inode * inode , struct file * file )
7887{
7988 int major = imajor (inode );
80- int cardnum ;
81- int device ;
8289 struct snd_hwdep * hw ;
8390 int err ;
8491 wait_queue_t wait ;
8592
8693 if (major == snd_major ) {
87- cardnum = SNDRV_MINOR_CARD (iminor (inode ));
88- device = SNDRV_MINOR_DEVICE ( iminor ( inode )) - SNDRV_MINOR_HWDEP ;
94+ hw = snd_lookup_minor_data (iminor (inode ),
95+ SNDRV_DEVICE_TYPE_HWDEP ) ;
8996#ifdef CONFIG_SND_OSSEMUL
9097 } else if (major == SOUND_MAJOR ) {
91- cardnum = SNDRV_MINOR_OSS_CARD (iminor (inode ));
92- device = 0 ;
98+ hw = snd_lookup_oss_minor_data (iminor (inode ),
99+ SNDRV_OSS_DEVICE_TYPE_DMFM ) ;
93100#endif
94101 } else
95102 return - ENXIO ;
96- cardnum %= SNDRV_CARDS ;
97- device %= SNDRV_MINOR_HWDEPS ;
98- hw = snd_hwdep_devices [(cardnum * SNDRV_MINOR_HWDEPS ) + device ];
99103 if (hw == NULL )
100104 return - ENODEV ;
101105
102106 if (!hw -> ops .open )
103107 return - ENXIO ;
104- #ifdef CONFIG_SND_OSSEMUL
105- if (major == SOUND_MAJOR && hw -> oss_type < 0 )
106- return - ENXIO ;
107- #endif
108108
109109 if (!try_module_get (hw -> card -> module ))
110110 return - EFAULT ;
@@ -265,42 +265,43 @@ static int snd_hwdep_control_ioctl(struct snd_card *card,
265265 struct snd_ctl_file * control ,
266266 unsigned int cmd , unsigned long arg )
267267{
268- unsigned int tmp ;
269-
270- tmp = card -> number * SNDRV_MINOR_HWDEPS ;
271268 switch (cmd ) {
272269 case SNDRV_CTL_IOCTL_HWDEP_NEXT_DEVICE :
273270 {
274271 int device ;
275272
276273 if (get_user (device , (int __user * )arg ))
277274 return - EFAULT ;
275+ down (& register_mutex );
278276 device = device < 0 ? 0 : device + 1 ;
279277 while (device < SNDRV_MINOR_HWDEPS ) {
280- if (snd_hwdep_devices [ tmp + device ] )
278+ if (snd_hwdep_search ( card , device ) )
281279 break ;
282280 device ++ ;
283281 }
284282 if (device >= SNDRV_MINOR_HWDEPS )
285283 device = -1 ;
284+ up (& register_mutex );
286285 if (put_user (device , (int __user * )arg ))
287286 return - EFAULT ;
288287 return 0 ;
289288 }
290289 case SNDRV_CTL_IOCTL_HWDEP_INFO :
291290 {
292291 struct snd_hwdep_info __user * info = (struct snd_hwdep_info __user * )arg ;
293- int device ;
292+ int device , err ;
294293 struct snd_hwdep * hwdep ;
295294
296295 if (get_user (device , & info -> device ))
297296 return - EFAULT ;
298- if (device < 0 || device >= SNDRV_MINOR_HWDEPS )
299- return - ENXIO ;
300- hwdep = snd_hwdep_devices [tmp + device ];
301- if (hwdep == NULL )
302- return - ENXIO ;
303- return snd_hwdep_info (hwdep , info );
297+ down (& register_mutex );
298+ hwdep = snd_hwdep_search (card , device );
299+ if (hwdep )
300+ err = snd_hwdep_info (hwdep , info );
301+ else
302+ err = - ENXIO ;
303+ up (& register_mutex );
304+ return err ;
304305 }
305306 }
306307 return - ENOIOCTLCMD ;
@@ -397,23 +398,22 @@ static int snd_hwdep_dev_free(struct snd_device *device)
397398static int snd_hwdep_dev_register (struct snd_device * device )
398399{
399400 struct snd_hwdep * hwdep = device -> device_data ;
400- int idx , err ;
401+ int err ;
401402 char name [32 ];
402403
403404 down (& register_mutex );
404- idx = (hwdep -> card -> number * SNDRV_MINOR_HWDEPS ) + hwdep -> device ;
405- if (snd_hwdep_devices [idx ]) {
405+ if (snd_hwdep_search (hwdep -> card , hwdep -> device )) {
406406 up (& register_mutex );
407407 return - EBUSY ;
408408 }
409- snd_hwdep_devices [ idx ] = hwdep ;
409+ list_add_tail ( & hwdep -> list , & snd_hwdep_devices ) ;
410410 sprintf (name , "hwC%iD%i" , hwdep -> card -> number , hwdep -> device );
411411 if ((err = snd_register_device (SNDRV_DEVICE_TYPE_HWDEP ,
412412 hwdep -> card , hwdep -> device ,
413- & snd_hwdep_f_ops , name )) < 0 ) {
413+ & snd_hwdep_f_ops , hwdep , name )) < 0 ) {
414414 snd_printk (KERN_ERR "unable to register hardware dependent device %i:%i\n" ,
415415 hwdep -> card -> number , hwdep -> device );
416- snd_hwdep_devices [ idx ] = NULL ;
416+ list_del ( & hwdep -> list ) ;
417417 up (& register_mutex );
418418 return err ;
419419 }
@@ -425,7 +425,7 @@ static int snd_hwdep_dev_register(struct snd_device *device)
425425 } else {
426426 if (snd_register_oss_device (hwdep -> oss_type ,
427427 hwdep -> card , hwdep -> device ,
428- & snd_hwdep_f_ops ,
428+ & snd_hwdep_f_ops , hwdep ,
429429 hwdep -> oss_dev ) < 0 ) {
430430 snd_printk (KERN_ERR "unable to register OSS compatibility device %i:%i\n" ,
431431 hwdep -> card -> number , hwdep -> device );
@@ -441,12 +441,10 @@ static int snd_hwdep_dev_register(struct snd_device *device)
441441static int snd_hwdep_dev_unregister (struct snd_device * device )
442442{
443443 struct snd_hwdep * hwdep = device -> device_data ;
444- int idx ;
445444
446445 snd_assert (hwdep != NULL , return - ENXIO );
447446 down (& register_mutex );
448- idx = (hwdep -> card -> number * SNDRV_MINOR_HWDEPS ) + hwdep -> device ;
449- if (snd_hwdep_devices [idx ] != hwdep ) {
447+ if (snd_hwdep_search (hwdep -> card , hwdep -> device ) != hwdep ) {
450448 up (& register_mutex );
451449 return - EINVAL ;
452450 }
@@ -455,7 +453,7 @@ static int snd_hwdep_dev_unregister(struct snd_device *device)
455453 snd_unregister_oss_device (hwdep -> oss_type , hwdep -> card , hwdep -> device );
456454#endif
457455 snd_unregister_device (SNDRV_DEVICE_TYPE_HWDEP , hwdep -> card , hwdep -> device );
458- snd_hwdep_devices [ idx ] = NULL ;
456+ list_del ( & hwdep -> list ) ;
459457 up (& register_mutex );
460458 return snd_hwdep_free (hwdep );
461459}
@@ -467,18 +465,14 @@ static int snd_hwdep_dev_unregister(struct snd_device *device)
467465static void snd_hwdep_proc_read (struct snd_info_entry * entry ,
468466 struct snd_info_buffer * buffer )
469467{
470- int idx ;
468+ struct list_head * p ;
471469 struct snd_hwdep * hwdep ;
472470
473471 down (& register_mutex );
474- for (idx = 0 ; idx < SNDRV_CARDS * SNDRV_MINOR_HWDEPS ; idx ++ ) {
475- hwdep = snd_hwdep_devices [idx ];
476- if (hwdep == NULL )
477- continue ;
472+ list_for_each (p , & snd_hwdep_devices ) {
473+ hwdep = list_entry (p , struct snd_hwdep , list );
478474 snd_iprintf (buffer , "%02i-%02i: %s\n" ,
479- idx / SNDRV_MINOR_HWDEPS ,
480- idx % SNDRV_MINOR_HWDEPS ,
481- hwdep -> name );
475+ hwdep -> card -> number , hwdep -> device , hwdep -> name );
482476 }
483477 up (& register_mutex );
484478}
@@ -493,9 +487,8 @@ static int __init alsa_hwdep_init(void)
493487{
494488 struct snd_info_entry * entry ;
495489
496- memset (snd_hwdep_devices , 0 , sizeof (snd_hwdep_devices ));
497490 if ((entry = snd_info_create_module_entry (THIS_MODULE , "hwdep" , NULL )) != NULL ) {
498- entry -> c .text .read_size = 512 ;
491+ entry -> c .text .read_size = PAGE_SIZE ;
499492 entry -> c .text .read = snd_hwdep_proc_read ;
500493 if (snd_info_register (entry ) < 0 ) {
501494 snd_info_free_entry (entry );
0 commit comments