From patchwork Wed Mar 14 20:42:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Girdwood X-Patchwork-Id: 10283555 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CBCF660621 for ; Wed, 14 Mar 2018 20:42:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA20522701 for ; Wed, 14 Mar 2018 20:42:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AEA7F27C0B; Wed, 14 Mar 2018 20:42:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B10422701 for ; Wed, 14 Mar 2018 20:42:56 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 173BC26718B; Wed, 14 Mar 2018 21:42:55 +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 6030F267196; Wed, 14 Mar 2018 21:42:53 +0100 (CET) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by alsa0.perex.cz (Postfix) with ESMTP id BED31266EBE for ; Wed, 14 Mar 2018 21:42:47 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Mar 2018 13:42:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,307,1517904000"; d="scan'208";a="24573252" Received: from inhetel-mobl.amr.corp.intel.com (HELO sif.ger.corp.intel.com) ([10.252.3.21]) by fmsmga008.fm.intel.com with ESMTP; 14 Mar 2018 13:42:44 -0700 From: Liam Girdwood To: Date: Wed, 14 Mar 2018 20:42:40 +0000 Message-Id: <20180314204240.13848-1-liam.r.girdwood@linux.intel.com> X-Mailer: git-send-email 2.14.1 Cc: Liam Girdwood , Mark Brown Subject: [alsa-devel] [PATCH] ASoC: topology: Check widget kcontrols before deref. 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 Validate the topology input before we dereference the pointer. Signed-off-by: Liam Girdwood --- sound/soc/soc-topology.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index 4616286869a8..78197e82fc4f 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -508,6 +508,9 @@ static void remove_widget(struct snd_soc_component *comp, if (dobj->ops && dobj->ops->widget_unload) dobj->ops->widget_unload(comp, dobj); + if (!w->kcontrols) + goto free_news; + /* * Dynamic Widgets either have 1..N enum kcontrols or mixers. * The enum may either have an array of values or strings. @@ -528,7 +531,6 @@ static void remove_widget(struct snd_soc_component *comp, kfree(se); } - kfree(w->kcontrol_news); } else { /* volume mixer or bytes controls */ for (i = 0; i < w->num_kcontrols; i++) { @@ -545,8 +547,11 @@ static void remove_widget(struct snd_soc_component *comp, kfree((void *)kcontrol->private_value); snd_ctl_remove(card, kcontrol); } - kfree(w->kcontrol_news); } + +free_news: + kfree(w->kcontrol_news); + /* widget w is freed by soc-dapm.c */ }