From 9698d03a63b89fd5a2a2d775bcfc542812da54d9 Mon Sep 17 00:00:00 2001 From: Pankaj Bharadiya Date: Mon, 9 Jan 2017 12:23:14 +0530 Subject: mixer: Add support for TLV RW access check api Tinyalsa doesn't expose an api to check TLV RW access Add mixer_ctl_is_access_tlv_rw(). This api will get used by tinymix and audio HALs for checking TLV RW access before managing the byte related mixer controls. Change-Id: Ib5707fabf479de638e1c7abd4cd149e7637ff9c2 Signed-off-by: Pankaj Bharadiya --- src/mixer.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/mixer.c') diff --git a/src/mixer.c b/src/mixer.c index 66881e9..daa04f7 100644 --- a/src/mixer.c +++ b/src/mixer.c @@ -381,6 +381,17 @@ void mixer_ctl_update(struct mixer_ctl *ctl) ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_INFO, ctl->info); } +/** Checks the control for TLV Read/Write access. + * @param ctl An initialized control handle. + * @returns On success, non-zero. + * On failure, zero. + * @ingroup libtinyalsa-mixer + */ +int mixer_ctl_is_access_tlv_rw(const struct mixer_ctl *ctl) +{ + return (ctl->info.access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE); +} + /** Gets the control's ID. * @param ctl An initialized control handle. * @returns On success, the control's ID is returned. @@ -598,7 +609,7 @@ int mixer_ctl_get_array(const struct mixer_ctl *ctl, void *array, size_t count) case SNDRV_CTL_ELEM_TYPE_BYTES: /* check if this is new bytes TLV */ - if (ctl->info.access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE) { + if (mixer_ctl_is_access_tlv_rw(ctl)) { struct snd_ctl_tlv *tlv; int ret; @@ -719,7 +730,7 @@ int mixer_ctl_set_array(struct mixer_ctl *ctl, const void *array, size_t count) case SNDRV_CTL_ELEM_TYPE_BYTES: /* check if this is new bytes TLV */ - if (ctl->info.access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE) { + if (mixer_ctl_is_access_tlv_rw(ctl)) { struct snd_ctl_tlv *tlv; int ret = 0; if (count > SIZE_MAX - sizeof(*tlv)) -- cgit v1.2.3 From 3f813e47784674a3909fe1277bc10b70d03791e2 Mon Sep 17 00:00:00 2001 From: Pankaj Bharadiya Date: Mon, 9 Jan 2017 13:42:14 +0530 Subject: Fix the byte control set/get method The TLV byte controls expect a TLV header as well. Check for TLV access and add TLV header size before invoking mixer API. Change-Id: I12ba129e5bbc0676e80eb920e85b3683decfe0db Signed-off-by: Pawse, GuruprasadX Signed-off-by: Pankaj Bharadiya --- src/mixer.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'src/mixer.c') diff --git a/src/mixer.c b/src/mixer.c index daa04f7..b7239fd 100644 --- a/src/mixer.c +++ b/src/mixer.c @@ -590,8 +590,20 @@ int mixer_ctl_get_array(const struct mixer_ctl *ctl, void *array, size_t count) int ret = 0; size_t size; void *source; + size_t total_count; - if (!ctl || (count > ctl->info.count) || !count || !array) + if ((!ctl) || !count || !array) + return -EINVAL; + + total_count = ctl->info.count; + + if ((ctl->info.type == SNDRV_CTL_ELEM_TYPE_BYTES) && + (mixer_ctl_is_access_tlv_rw(ctl))) { + /* Additional two words is for the TLV header */ + total_count += TLV_HEADER_SIZE; + } + + if (count > total_count) return -EINVAL; memset(&ev, 0, sizeof(ev)); @@ -714,8 +726,20 @@ int mixer_ctl_set_array(struct mixer_ctl *ctl, const void *array, size_t count) struct snd_ctl_elem_value ev; size_t size; void *dest; + size_t total_count; + + if ((!ctl) || !count || !array) + return -EINVAL; + + total_count = ctl->info.count; + + if ((ctl->info.type == SNDRV_CTL_ELEM_TYPE_BYTES) && + (mixer_ctl_is_access_tlv_rw(ctl))) { + /* Additional TLV header */ + total_count += TLV_HEADER_SIZE; + } - if (!ctl || (count > ctl->info.count) || !count || !array) + if (count > total_count) return -EINVAL; memset(&ev, 0, sizeof(ev)); -- cgit v1.2.3