From 98c1f16cbd8fd2e94a6be0db492b378d34a29310 Mon Sep 17 00:00:00 2001 From: Simon Wilson Date: Tue, 7 Jun 2011 16:12:32 -0700 Subject: Fix error cases and some spurious whitespace --- mixer.c | 28 ++++++++++++---------------- pcm.c | 1 + 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/mixer.c b/mixer.c index 2bb37a1..0c2e233 100644 --- a/mixer.c +++ b/mixer.c @@ -169,7 +169,7 @@ unsigned int mixer_get_num_ctls(struct mixer *mixer) { if (!mixer) { errno = EINVAL; - return -1; + return 0; } return mixer->count; @@ -177,14 +177,10 @@ unsigned int mixer_get_num_ctls(struct mixer *mixer) struct mixer_ctl *mixer_get_ctl(struct mixer *mixer, unsigned int id) { - if (!mixer) { - errno = EINVAL; - return NULL; - } - - if (id < mixer->count) + if (mixer && (id < mixer->count)) return mixer->ctl + id; + errno = EINVAL; return NULL; } @@ -192,15 +188,15 @@ struct mixer_ctl *mixer_get_ctl_by_name(struct mixer *mixer, const char *name) { unsigned int n; - if (!mixer) { - errno = EINVAL; - return NULL; - } + if (!mixer) + goto error; for (n = 0; n < mixer->count; n++) if (!strcmp(name, (char*) mixer->info[n].id.name)) return mixer->ctl + n; +error: + errno = EINVAL; return NULL; } @@ -264,24 +260,24 @@ unsigned int mixer_ctl_get_num_values(struct mixer_ctl *ctl) static int percent_to_int(struct snd_ctl_elem_info *ei, int percent) { int range; - + if (percent > 100) percent = 100; else if (percent < 0) percent = 0; - + range = (ei->value.integer.max - ei->value.integer.min); - + return ei->value.integer.min + (range * percent) / 100; } static int int_to_percent(struct snd_ctl_elem_info *ei, int value) { int range = (ei->value.integer.max - ei->value.integer.min); - + if (range == 0) return 0; - + return ((value - ei->value.integer.min) / range) * 100; } diff --git a/pcm.c b/pcm.c index 2933dec..1fab6f4 100644 --- a/pcm.c +++ b/pcm.c @@ -111,6 +111,7 @@ static void param_set_int(struct snd_pcm_hw_params *p, int n, unsigned int val) static void param_init(struct snd_pcm_hw_params *p) { int n; + memset(p, 0, sizeof(*p)); for (n = SNDRV_PCM_HW_PARAM_FIRST_MASK; n <= SNDRV_PCM_HW_PARAM_LAST_MASK; n++) { -- cgit v1.2.3