From patchwork Mon Jul 13 10:26:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lars-Peter Clausen X-Patchwork-Id: 6777811 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7C23C9F2E8 for ; Mon, 13 Jul 2015 10:28:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A6D3D20571 for ; Mon, 13 Jul 2015 10:28:47 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 4B2B0205B5 for ; Mon, 13 Jul 2015 10:28:46 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 42C9C261B23; Mon, 13 Jul 2015 12:28:45 +0200 (CEST) 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,NO_DNS_FOR_FROM, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id D8CB52616C9; Mon, 13 Jul 2015 12:27:08 +0200 (CEST) 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 305802605CD; Mon, 13 Jul 2015 12:27:06 +0200 (CEST) Received: from smtp-out-236.synserver.de (smtp-out-236.synserver.de [212.40.185.236]) by alsa0.perex.cz (Postfix) with ESMTP id B6A852605A9 for ; Mon, 13 Jul 2015 12:26:56 +0200 (CEST) Received: (qmail 10444 invoked by uid 0); 13 Jul 2015 10:26:56 -0000 X-SynServer-TrustedSrc: 1 X-SynServer-AuthUser: lars@metafoo.de X-SynServer-PPID: 10289 Received: from ppp-188-174-59-27.dynamic.mnet-online.de (HELO lars-laptop.fritz.box) [188.174.59.27] by 217.119.54.77 with SMTP; 13 Jul 2015 10:26:55 -0000 From: Lars-Peter Clausen To: Mark Brown , Liam Girdwood Date: Mon, 13 Jul 2015 12:26:45 +0200 Message-Id: <1436783208-1529-2-git-send-email-lars@metafoo.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1436783208-1529-1-git-send-email-lars@metafoo.de> References: <1436783208-1529-1-git-send-email-lars@metafoo.de> Cc: alsa-devel@alsa-project.org, Lars-Peter Clausen Subject: [alsa-devel] [PATCH 2/5] ASoC: uda134x: Move state struct allocation to bus probe 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 Resource allocations should be done in the bus probe rather than the CODEC probe. Move the allocation of the drivers state struct there. Signed-off-by: Lars-Peter Clausen --- sound/soc/codecs/uda134x.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/sound/soc/codecs/uda134x.c b/sound/soc/codecs/uda134x.c index 913edf2..a89f98a 100644 --- a/sound/soc/codecs/uda134x.c +++ b/sound/soc/codecs/uda134x.c @@ -478,8 +478,8 @@ static struct snd_soc_dai_driver uda134x_dai = { static int uda134x_soc_probe(struct snd_soc_codec *codec) { struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); - struct uda134x_priv *uda134x; struct uda134x_platform_data *pd = codec->component.card->dev->platform_data; + struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec); const struct snd_soc_dapm_widget *widgets; unsigned num_widgets; @@ -506,10 +506,6 @@ static int uda134x_soc_probe(struct snd_soc_codec *codec) return -EINVAL; } - uda134x = kzalloc(sizeof(struct uda134x_priv), GFP_KERNEL); - if (uda134x == NULL) - return -ENOMEM; - snd_soc_codec_set_drvdata(codec, uda134x); codec->control_data = pd; @@ -530,7 +526,6 @@ static int uda134x_soc_probe(struct snd_soc_codec *codec) if (ret) { printk(KERN_ERR "%s failed to register dapm controls: %d", __func__, ret); - kfree(uda134x); return ret; } @@ -551,31 +546,19 @@ static int uda134x_soc_probe(struct snd_soc_codec *codec) default: printk(KERN_ERR "%s unknown codec type: %d", __func__, pd->model); - kfree(uda134x); return -EINVAL; } if (ret < 0) { printk(KERN_ERR "UDA134X: failed to register controls\n"); - kfree(uda134x); return ret; } return 0; } -/* power down chip */ -static int uda134x_soc_remove(struct snd_soc_codec *codec) -{ - struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec); - - kfree(uda134x); - return 0; -} - static struct snd_soc_codec_driver soc_codec_dev_uda134x = { .probe = uda134x_soc_probe, - .remove = uda134x_soc_remove, .reg_cache_size = sizeof(uda134x_reg), .reg_word_size = sizeof(u8), .reg_cache_default = uda134x_reg, @@ -592,6 +575,14 @@ static struct snd_soc_codec_driver soc_codec_dev_uda134x = { static int uda134x_codec_probe(struct platform_device *pdev) { + struct uda134x_priv *uda134x; + + uda134x = devm_kzalloc(&pdev->dev, sizeof(*uda134x), GFP_KERNEL); + if (!uda134x) + return -ENOMEM; + + platform_set_drvdata(pdev, uda134x); + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_uda134x, &uda134x_dai, 1); }