summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlavio Ceolin <flavio.ceolin@gmail.com>2015-05-22 22:13:59 -0300
committerFlavio Ceolin <flavio.ceolin@gmail.com>2015-05-22 22:13:59 -0300
commit86f5c49cd0dd118479d0f32999f77fe8720d2488 (patch)
treebfb486cb6df5519188936a04b2e2af7e7b91e1d1
parent53226da61f7dc66daff0aa5793e90786654cc505 (diff)
alsa: Add sanity checks
-rw-r--r--src/lib/backends/alsa/alsa.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/lib/backends/alsa/alsa.c b/src/lib/backends/alsa/alsa.c
index 8ea974d..3640068 100644
--- a/src/lib/backends/alsa/alsa.c
+++ b/src/lib/backends/alsa/alsa.c
@@ -333,9 +333,12 @@ _alsa_cards_refresh(void)
333static Eina_Bool 333static Eina_Bool
334_alsa_init(Emix_Event_Cb cb, const void *data) 334_alsa_init(Emix_Event_Cb cb, const void *data)
335{ 335{
336 EINA_SAFETY_ON_NULL_RETURN_VAL(cb, EINA_FALSE);
336 if (!ctx) 337 if (!ctx)
337 ctx = calloc(1, sizeof(Context)); 338 ctx = calloc(1, sizeof(Context));
338 339
340 EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, EINA_FALSE);
341
339 ctx->cb = cb; 342 ctx->cb = cb;
340 ctx->userdata = data; 343 ctx->userdata = data;
341 _alsa_cards_refresh(); 344 _alsa_cards_refresh();
@@ -353,6 +356,8 @@ _alsa_shutdown(void)
353 Alsa_Emix_Source *source; 356 Alsa_Emix_Source *source;
354 snd_mixer_t *mixer; 357 snd_mixer_t *mixer;
355 358
359 EINA_SAFETY_ON_NULL_RETURN(ctx);
360
356 EINA_LIST_FREE(ctx->sinks, sink) 361 EINA_LIST_FREE(ctx->sinks, sink)
357 _alsa_device_sink_free(sink); 362 _alsa_device_sink_free(sink);
358 EINA_LIST_FREE(ctx->sources, source) 363 EINA_LIST_FREE(ctx->sources, source)
@@ -367,6 +372,7 @@ _alsa_shutdown(void)
367static const Eina_List* 372static const Eina_List*
368_alsa_sources_get(void) 373_alsa_sources_get(void)
369{ 374{
375 EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, NULL);
370 return ctx->sources; 376 return ctx->sources;
371} 377}
372 378
@@ -377,6 +383,8 @@ _alsa_sources_mute_set(Emix_Source *source, Eina_Bool mute)
377 Eina_List *node; 383 Eina_List *node;
378 snd_mixer_elem_t *elem; 384 snd_mixer_elem_t *elem;
379 385
386 EINA_SAFETY_ON_FALSE_RETURN((ctx && source));
387
380 EINA_LIST_FOREACH(s->channels, node, elem) 388 EINA_LIST_FOREACH(s->channels, node, elem)
381 { 389 {
382 if (!snd_mixer_selem_has_capture_switch(elem)) 390 if (!snd_mixer_selem_has_capture_switch(elem))
@@ -398,6 +406,8 @@ _alsa_sources_volume_set(Emix_Source *source, Emix_Volume v)
398 unsigned int i; 406 unsigned int i;
399 snd_mixer_elem_t *elem; 407 snd_mixer_elem_t *elem;
400 408
409 EINA_SAFETY_ON_FALSE_RETURN((ctx && source));
410
401 if (v.channel_count != eina_list_count(s->channels)) 411 if (v.channel_count != eina_list_count(s->channels))
402 { 412 {
403 ERR("Volume struct doesnt have the same length than the channels"); 413 ERR("Volume struct doesnt have the same length than the channels");
@@ -415,6 +425,7 @@ _alsa_sources_volume_set(Emix_Source *source, Emix_Volume v)
415static const Eina_List* 425static const Eina_List*
416_alsa_sinks_get(void) 426_alsa_sinks_get(void)
417{ 427{
428 EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, NULL);
418 //FIXME fork or just return? 429 //FIXME fork or just return?
419/* Eina_List *result = NULL; 430/* Eina_List *result = NULL;
420 Eina_List *node; 431 Eina_List *node;
@@ -439,6 +450,8 @@ _alsa_sink_mute_set(Emix_Sink *sink, Eina_Bool mute)
439 Eina_List *node; 450 Eina_List *node;
440 snd_mixer_elem_t *elem; 451 snd_mixer_elem_t *elem;
441 452
453 EINA_SAFETY_ON_FALSE_RETURN((ctx && sink));
454
442 EINA_LIST_FOREACH(as->channels, node, elem) 455 EINA_LIST_FOREACH(as->channels, node, elem)
443 { 456 {
444 if (!snd_mixer_selem_has_playback_switch(elem)) 457 if (!snd_mixer_selem_has_playback_switch(elem))
@@ -461,6 +474,8 @@ _alsa_sink_volume_set(Emix_Sink *sink, Emix_Volume v)
461 unsigned int i; 474 unsigned int i;
462 snd_mixer_elem_t *elem; 475 snd_mixer_elem_t *elem;
463 476
477 EINA_SAFETY_ON_FALSE_RETURN((ctx && sink));
478
464 if (v.channel_count != eina_list_count(s->channels)) 479 if (v.channel_count != eina_list_count(s->channels))
465 { 480 {
466 ERR("Volume struct doesnt have the same length than the channels"); 481 ERR("Volume struct doesnt have the same length than the channels");