From patchwork Fri Jan 22 05:46:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinod Koul X-Patchwork-Id: 8087751 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 170FCBEEE5 for ; Fri, 22 Jan 2016 05:43:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4E2DE2043C for ; Fri, 22 Jan 2016 05:43:36 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id BADAC203F7 for ; Fri, 22 Jan 2016 05:43:34 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 0D49F26070F; Fri, 22 Jan 2016 06:43:33 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id B2DDE2606B8; Fri, 22 Jan 2016 06:43:25 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 374E32606C1; Fri, 22 Jan 2016 06:43:24 +0100 (CET) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by alsa0.perex.cz (Postfix) with ESMTP id B479A26061E for ; Fri, 22 Jan 2016 06:43:14 +0100 (CET) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 21 Jan 2016 21:43:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,329,1449561600"; d="scan'208";a="895870532" Received: from vkoul-udesk7.iind.intel.com ([10.223.84.34]) by orsmga002.jf.intel.com with ESMTP; 21 Jan 2016 21:43:10 -0800 From: Vinod Koul To: alsa-devel@alsa-project.org Date: Fri, 22 Jan 2016 11:16:52 +0530 Message-Id: <1453441612-29902-1-git-send-email-vinod.koul@intel.com> X-Mailer: git-send-email 1.9.1 Cc: liam.r.girdwood@linux.intel.com, tiwai@suse.de, broonie@kernel.org, Vinod Koul , patches.audio@intel.com Subject: [alsa-devel] [PATCH] amixer: add support for TLV byte control read X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP TLV byte control are new type of byte controls added in kernel where controls can have large sizes. For these controls querying with 4096 size fails, so use the queried size to read the control This fixes the crash with current cget/contents on these type of controls Signed-off-by: Vinod Koul --- amixer/amixer.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/amixer/amixer.c b/amixer/amixer.c index db1849333da3..cfe13592347f 100644 --- a/amixer/amixer.c +++ b/amixer/amixer.c @@ -588,7 +588,7 @@ static int show_control(const char *space, snd_hctl_elem_t *elem, int level) { int err; - unsigned int item, idx, count, *tlv; + unsigned int item, idx, count, *tlv, tlv_sz; snd_ctl_elem_type_t type; snd_ctl_elem_id_t *id; snd_ctl_elem_info_t *info; @@ -682,13 +682,20 @@ static int show_control(const char *space, snd_hctl_elem_t *elem, __skip_read: if (!snd_ctl_elem_info_is_tlv_readable(info)) goto __skip_tlv; - tlv = malloc(4096); - if ((err = snd_hctl_elem_tlv_read(elem, tlv, 4096)) < 0) { + + if (type == SND_CTL_ELEM_TYPE_BYTES) + tlv_sz = count + 2 * sizeof(unsigned int); + else + tlv_sz = 4096; + + tlv = malloc(tlv_sz); + + if ((err = snd_hctl_elem_tlv_read(elem, tlv, tlv_sz)) < 0) { error("Control %s element TLV read error: %s\n", card, snd_strerror(err)); free(tlv); return err; } - decode_tlv(strlen(space), tlv, 4096); + decode_tlv(strlen(space), tlv, tlv_sz); free(tlv); } __skip_tlv: