diff options
author | Simon Wilson <simonwilson@google.com> | 2011-06-07 16:12:32 -0700 |
---|---|---|
committer | Simon Wilson <simonwilson@google.com> | 2011-06-07 16:14:21 -0700 |
commit | 98c1f16cbd8fd2e94a6be0db492b378d34a29310 (patch) | |
tree | 05b0eb2a0c1dfabe875aacca853d28a4c835d024 | |
parent | b9d4f6bfee008efe1c38eea80fdabf1886c26cf0 (diff) |
Fix error cases and some spurious whitespace
-rw-r--r-- | mixer.c | 28 | ||||
-rw-r--r-- | pcm.c | 1 |
2 files changed, 13 insertions, 16 deletions
@@ -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; } @@ -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++) { |