]> err.no Git - linux-2.6/commitdiff
[ALSA] timer: fix timer instance memory allocation checks
authorClemens Ladisch <clemens@ladisch.de>
Wed, 12 Oct 2005 15:10:35 +0000 (17:10 +0200)
committerJaroslav Kysela <perex@suse.cz>
Fri, 4 Nov 2005 12:18:38 +0000 (13:18 +0100)
Modules: Timer Midlevel

Add checks to return -ENOMEM in case snd_timer_instance_new() fails.

Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
sound/core/timer.c

index 8ecec9134acdd389aa20949ddcbe92813d8468ac..b02681eaea75668883ee6fb7050d3ce9fcd7487b 100644 (file)
@@ -251,6 +251,10 @@ int snd_timer_open(snd_timer_instance_t **ti,
                }
                down(&register_mutex);
                timeri = snd_timer_instance_new(owner, NULL);
+               if (!timeri) {
+                       up(&register_mutex);
+                       return -ENOMEM;
+               }
                timeri->slave_class = tid->dev_sclass;
                timeri->slave_id = tid->device;
                timeri->flags |= SNDRV_TIMER_IFLG_SLAVE;
@@ -272,27 +276,29 @@ int snd_timer_open(snd_timer_instance_t **ti,
                timer = snd_timer_find(tid);
        }
 #endif
-       if (timer) {
-               if (!list_empty(&timer->open_list_head)) {
-                       timeri = (snd_timer_instance_t *)list_entry(timer->open_list_head.next, snd_timer_instance_t, open_list);
-                       if (timeri->flags & SNDRV_TIMER_IFLG_EXCLUSIVE) {
-                               up(&register_mutex);
-                               return -EBUSY;
-                       }
-               }
-               timeri = snd_timer_instance_new(owner, timer);
-               if (timeri) {
-                       timeri->slave_class = tid->dev_sclass;
-                       timeri->slave_id = slave_id;
-                       if (list_empty(&timer->open_list_head) && timer->hw.open)
-                               timer->hw.open(timer);
-                       list_add_tail(&timeri->open_list, &timer->open_list_head);
-                       snd_timer_check_master(timeri);
-               }
-       } else {
+       if (!timer) {
                up(&register_mutex);
                return -ENODEV;
        }
+       if (!list_empty(&timer->open_list_head)) {
+               timeri = list_entry(timer->open_list_head.next,
+                                   snd_timer_instance_t, open_list);
+               if (timeri->flags & SNDRV_TIMER_IFLG_EXCLUSIVE) {
+                       up(&register_mutex);
+                       return -EBUSY;
+               }
+       }
+       timeri = snd_timer_instance_new(owner, timer);
+       if (!timeri) {
+               up(&register_mutex);
+               return -ENOMEM;
+       }
+       timeri->slave_class = tid->dev_sclass;
+       timeri->slave_id = slave_id;
+       if (list_empty(&timer->open_list_head) && timer->hw.open)
+               timer->hw.open(timer);
+       list_add_tail(&timeri->open_list, &timer->open_list_head);
+       snd_timer_check_master(timeri);
        up(&register_mutex);
        *ti = timeri;
        return 0;