diff options
author | Clemens Ladisch <clemens@ladisch.de> | 2005-10-12 11:10:35 -0400 |
---|---|---|
committer | Jaroslav Kysela <perex@suse.cz> | 2005-11-04 07:18:38 -0500 |
commit | 2fd43d1159d22395aae01836c4b13ee5265a9b6b (patch) | |
tree | fcbbd9af8033f992a0ff30a4dc689e3e3e42b932 /sound/core/timer.c | |
parent | 2dfbeca9e9b3857e005afc9b933e2e1be07a9ea0 (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.c | 42 |
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, | |||
251 | } | 251 | } |
252 | down(®ister_mutex); | 252 | down(®ister_mutex); |
253 | timeri = snd_timer_instance_new(owner, NULL); | 253 | timeri = snd_timer_instance_new(owner, NULL); |
254 | if (!timeri) { | ||
255 | up(®ister_mutex); | ||
256 | return -ENOMEM; | ||
257 | } | ||
254 | timeri->slave_class = tid->dev_sclass; | 258 | timeri->slave_class = tid->dev_sclass; |
255 | timeri->slave_id = tid->device; | 259 | timeri->slave_id = tid->device; |
256 | timeri->flags |= SNDRV_TIMER_IFLG_SLAVE; | 260 | timeri->flags |= SNDRV_TIMER_IFLG_SLAVE; |
@@ -272,27 +276,29 @@ int snd_timer_open(snd_timer_instance_t **ti, | |||
272 | timer = snd_timer_find(tid); | 276 | timer = snd_timer_find(tid); |
273 | } | 277 | } |
274 | #endif | 278 | #endif |
275 | if (timer) { | 279 | if (!timer) { |
276 | if (!list_empty(&timer->open_list_head)) { | ||
277 | timeri = (snd_timer_instance_t *)list_entry(timer->open_list_head.next, snd_timer_instance_t, open_list); | ||
278 | if (timeri->flags & SNDRV_TIMER_IFLG_EXCLUSIVE) { | ||
279 | up(®ister_mutex); | ||
280 | return -EBUSY; | ||
281 | } | ||
282 | } | ||
283 | timeri = snd_timer_instance_new(owner, timer); | ||
284 | if (timeri) { | ||
285 | timeri->slave_class = tid->dev_sclass; | ||
286 | timeri->slave_id = slave_id; | ||
287 | if (list_empty(&timer->open_list_head) && timer->hw.open) | ||
288 | timer->hw.open(timer); | ||
289 | list_add_tail(&timeri->open_list, &timer->open_list_head); | ||
290 | snd_timer_check_master(timeri); | ||
291 | } | ||
292 | } else { | ||
293 | up(®ister_mutex); | 280 | up(®ister_mutex); |
294 | return -ENODEV; | 281 | return -ENODEV; |
295 | } | 282 | } |
283 | if (!list_empty(&timer->open_list_head)) { | ||
284 | timeri = list_entry(timer->open_list_head.next, | ||
285 | snd_timer_instance_t, open_list); | ||
286 | if (timeri->flags & SNDRV_TIMER_IFLG_EXCLUSIVE) { | ||
287 | up(®ister_mutex); | ||
288 | return -EBUSY; | ||
289 | } | ||
290 | } | ||
291 | timeri = snd_timer_instance_new(owner, timer); | ||
292 | if (!timeri) { | ||
293 | up(®ister_mutex); | ||
294 | return -ENOMEM; | ||
295 | } | ||
296 | timeri->slave_class = tid->dev_sclass; | ||
297 | timeri->slave_id = slave_id; | ||
298 | if (list_empty(&timer->open_list_head) && timer->hw.open) | ||
299 | timer->hw.open(timer); | ||
300 | list_add_tail(&timeri->open_list, &timer->open_list_head); | ||
301 | snd_timer_check_master(timeri); | ||
296 | up(®ister_mutex); | 302 | up(®ister_mutex); |
297 | *ti = timeri; | 303 | *ti = timeri; |
298 | return 0; | 304 | return 0; |