summaryrefslogtreecommitdiff
path: root/sound/core/timer.c
diff options
context:
space:
mode:
authorClemens Ladisch <clemens@ladisch.de>2005-10-12 17:10:35 +0200
committerJaroslav Kysela <perex@suse.cz>2005-11-04 13:18:38 +0100
commit2fd43d1159d22395aae01836c4b13ee5265a9b6b (patch)
treefcbbd9af8033f992a0ff30a4dc689e3e3e42b932 /sound/core/timer.c
parent2dfbeca9e9b3857e005afc9b933e2e1be07a9ea0 (diff)
[ALSA] timer: fix timer instance memory allocation checks
Modules: Timer Midlevel Add checks to return -ENOMEM in case snd_timer_instance_new() fails. Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Diffstat (limited to 'sound/core/timer.c')
-rw-r--r--sound/core/timer.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/sound/core/timer.c b/sound/core/timer.c
index 8ecec9134acd..b02681eaea75 100644
--- a/sound/core/timer.c
+++ b/sound/core/timer.c
@@ -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;