Received: by 10.223.176.46 with SMTP id f43csp2793320wra; Mon, 22 Jan 2018 03:34:04 -0800 (PST) X-Google-Smtp-Source: AH8x225eKqjyJpePe7TVR92YyKq6qIQYRd7AFOX3X+Av7ZMe2kJnwBO9UhNSnykIpQgoaqyiuBjp X-Received: by 10.99.111.11 with SMTP id k11mr6966472pgc.414.1516620843967; Mon, 22 Jan 2018 03:34:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516620843; cv=none; d=google.com; s=arc-20160816; b=BY3bDm61uIwurvqYQlCjTlyhlZrevSHLMVu2+bxLBKhRDX7vhv7WEYVTuf7qXK/oj5 77x++tUememQ0WTsw9spajA1D+Vl3OsNIAHdiaIfSTiJPnE6bU6F94y88R4bEjDc5T8S dqXo0Y9r9YTNukeE9BIAHzcE/Nlx46PGtB/fRASBsTd76FFxL/XYOwcKrEvWBBp4Rknj 1yuktPg/rb3Hdir1za65ccpYNrOBquqL6u5jcan40kDBfhwKt1mKPBNTOAmgWS9CA2Cg 9MG5YLryGdUedWXQ13HiinGUqGs/51dfGLvHv81GrKyFhV3ZI99oEQdtUokCa6mWrlm1 z+3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=55DOsQQbtqP9++3tsGY8UBZ9q1mRJeH/exwMv9NBKBA=; b=I9QkuJneuBDggejnCnwxoABl0oAPawU232b7qvHGPqSn+C/gC+fElncUyJRH3UwdJo VOCO3mBoONnaVfx/G5MUDV7+Vb360hovUrYsJzHA9MFtt5NSKWQ2SatqpoEnow7iIJkN XToVccaR32K60WJwdqHANOZowV9swjg2M5hTNYS1ZIonB9sVZM50vBe6Isg86DOtQx2s CXlE5zLx+FWTVAQI/2XWmCwLT0L2pkl5FhmPzGDVTzU16+NldePL17waZyfw6qVARV45 BHj7FE03lSceNI4ey+1CenF3vAhGgBDoe/iQbaUEqoixqdcMrHV+wndDRda5FUhfyEak um4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s11si11978818pgq.75.2018.01.22.03.33.49; Mon, 22 Jan 2018 03:34:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751157AbeAVLdU (ORCPT + 99 others); Mon, 22 Jan 2018 06:33:20 -0500 Received: from mailgw01.mediatek.com ([210.61.82.183]:65404 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750886AbeAVLdR (ORCPT ); Mon, 22 Jan 2018 06:33:17 -0500 X-UUID: be728da7f0c94e98b6b93474149136c9-20180122 Received: from mtkcas08.mediatek.inc [(172.21.101.126)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 361564029; Mon, 22 Jan 2018 19:33:14 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs08n1.mediatek.inc (172.21.101.55) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Mon, 22 Jan 2018 19:33:07 +0800 Received: from mtkslt306.mediatek.inc (10.21.14.136) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Mon, 22 Jan 2018 19:33:07 +0800 From: Ryder Lee To: Mark Brown CC: , , , , "Ryder Lee" Subject: [PATCH] ASoC: mediatek: fix double free in mt2701_afe_pcm_dev_probe() Date: Mon, 22 Jan 2018 19:33:05 +0800 Message-ID: <2fd34b71f3c940186b99f799c3ed14a83ccc4bba.1516620578.git.ryder.lee@mediatek.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The commit dfa3cbb8(ASoC: mediatek: modify MT2701 AFE driver to adapt mfd device) leads to the following static checker warning: sound/soc/mediatek/mt2701/mt2701-afe-pcm.c:1535 mt2701_afe_pcm_dev_probe() error: double free of 'component' This patch fixes that and adds a helper mt2701_afe_add_component() to setup component. Reported-by: Dan Carpenter Signed-off-by: Ryder Lee --- sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 32 +++++++++++++++++------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c index f0cd08f..ff15537 100644 --- a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c +++ b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c @@ -1405,9 +1405,24 @@ static int mt2701_afe_runtime_resume(struct device *dev) return mt2701_afe_enable_clock(afe); } -static int mt2701_afe_pcm_dev_probe(struct platform_device *pdev) +static int mt2701_afe_add_component(struct mtk_base_afe *afe) { struct snd_soc_component *component; + + component = kzalloc(sizeof(*component), GFP_KERNEL); + if (!component) + return -ENOMEM; + + component->regmap = afe->regmap; + + return snd_soc_add_component(afe->dev, component, + &mt2701_afe_pcm_dai_component, + mt2701_afe_pcm_dais, + ARRAY_SIZE(mt2701_afe_pcm_dais)); +} + +static int mt2701_afe_pcm_dev_probe(struct platform_device *pdev) +{ struct mtk_base_afe *afe; struct mt2701_afe_private *afe_priv; struct device *dev; @@ -1477,12 +1492,6 @@ static int mt2701_afe_pcm_dev_probe(struct platform_device *pdev) = &mt2701_i2s_data[i][I2S_IN]; } - component = kzalloc(sizeof(*component), GFP_KERNEL); - if (!component) - return -ENOMEM; - - component->regmap = afe->regmap; - afe->mtk_afe_hardware = &mt2701_afe_hardware; afe->memif_fs = mt2701_memif_fs; afe->irq_fs = mt2701_irq_fs; @@ -1495,7 +1504,7 @@ static int mt2701_afe_pcm_dev_probe(struct platform_device *pdev) ret = mt2701_init_clock(afe); if (ret) { dev_err(dev, "init clock error\n"); - goto err_init_clock; + return ret; } platform_set_drvdata(pdev, afe); @@ -1514,10 +1523,7 @@ static int mt2701_afe_pcm_dev_probe(struct platform_device *pdev) goto err_platform; } - ret = snd_soc_add_component(dev, component, - &mt2701_afe_pcm_dai_component, - mt2701_afe_pcm_dais, - ARRAY_SIZE(mt2701_afe_pcm_dais)); + ret = mt2701_afe_add_component(afe); if (ret) { dev_warn(dev, "err_dai_component\n"); goto err_dai_component; @@ -1531,8 +1537,6 @@ static int mt2701_afe_pcm_dev_probe(struct platform_device *pdev) pm_runtime_put_sync(dev); err_pm_disable: pm_runtime_disable(dev); -err_init_clock: - kfree(component); return ret; } -- 1.9.1