From patchwork Sun Jul 6 07:08:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: HIMANGI SARAOGI X-Patchwork-Id: 4489391 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 64444BEEAA for ; Sun, 6 Jul 2014 07:08:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7FB7520263 for ; Sun, 6 Jul 2014 07:08:32 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 33C642024C for ; Sun, 6 Jul 2014 07:08:31 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 06F76265551; Sun, 6 Jul 2014 09:08:28 +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.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NO_DNS_FOR_FROM, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 5AABA265055; Sun, 6 Jul 2014 09:08:18 +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 E6FBD26509D; Sun, 6 Jul 2014 09:08:17 +0200 (CEST) Received: from mail-pa0-f49.google.com (mail-pa0-f49.google.com [209.85.220.49]) by alsa0.perex.cz (Postfix) with ESMTP id 91DF0265044 for ; Sun, 6 Jul 2014 09:08:09 +0200 (CEST) Received: by mail-pa0-f49.google.com with SMTP id lj1so3782926pab.36 for ; Sun, 06 Jul 2014 00:08:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=COsgevz4HKa+VCsAzeZSQ1puNMJABYp4QDxCLXxm5ow=; b=PpGUUCU3UpjDz524BuERaHfTPN0faDHOfcoXR/RO5TAXdRGHis+2iKf3n/l7dmsCgw A6Ot5YPkSOZcR1vsZgRfFbO4oiuvbfiOSTsQYBJ8ad7oLcuCmRQ+qXh98Kz9pmLUm+fB 4KBmyJQ4jaHaVhgxVgyj0BkHbudN4suKPgSHnHh6s44edbfHvAGWxYDkLdcdvpmGcPZ+ 0H++9vzv5lFaxckiFh2G44iiHv6qfWopFObCq9I88HQBlqDBy0pLI0KPSH4VOjT84WUg VdBI9KNzXDEiNfjWjwe7eYm6pLZPjzVLob9A1z20hbexKmQs0uwJGCZ1BYa4LHcVYTEa b/bA== X-Received: by 10.70.43.43 with SMTP id t11mr20611028pdl.49.1404630487775; Sun, 06 Jul 2014 00:08:07 -0700 (PDT) Received: from localhost ([122.178.76.19]) by mx.google.com with ESMTPSA id ey10sm15335000pdb.50.2014.07.06.00.08.04 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 06 Jul 2014 00:08:06 -0700 (PDT) Date: Sun, 6 Jul 2014 12:38:00 +0530 From: Himangi Saraogi To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Message-ID: <20140706070800.GA2927@himangi-Dell> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Cc: julia.lawall@lip6.fr Subject: [alsa-devel] [PATCH] ASoC: sgtl5000: Use devm_ functions 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP This patch introduces the use of managed interfaces like devm_kzalloc, devm_kstrdup and devm_regulator_register and does avay with the calls to the functions to free the allocated memory in ldo_regulator_register and ldo_regulator_remove. The ldo_regulator_remove function is completely removed as it is no longer required. ldo_regulator_register is called from a probe function and on failure its value is returned as the result. Signed-off-by: Himangi Saraogi --- To send to: Liam Girdwood ,Mark Brown ,Jaroslav Kysela ,Takashi Iwai ,alsa-devel@alsa-project.org,linux-kernel@vger.kernel.org sound/soc/codecs/sgtl5000.c | 46 +++++++-------------------------------------- 1 file changed, 7 insertions(+), 39 deletions(-) diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c index 249fadb..0efd6d6 100644 --- a/sound/soc/codecs/sgtl5000.c +++ b/sound/soc/codecs/sgtl5000.c @@ -841,14 +841,15 @@ static int ldo_regulator_register(struct snd_soc_codec *codec, struct sgtl5000_priv *sgtl5000 = snd_soc_codec_get_drvdata(codec); struct regulator_config config = { }; - ldo = kzalloc(sizeof(struct ldo_regulator), GFP_KERNEL); + ldo = devm_kzalloc(codec->dev, sizeof(struct ldo_regulator), + GFP_KERNEL); if (!ldo) return -ENOMEM; - ldo->desc.name = kstrdup(dev_name(codec->dev), GFP_KERNEL); + ldo->desc.name = devm_kstrdup(codec->dev, dev_name(codec->dev), + GFP_KERNEL); if (!ldo->desc.name) { - kfree(ldo); dev_err(codec->dev, "failed to allocate decs name memory\n"); return -ENOMEM; } @@ -865,35 +866,17 @@ static int ldo_regulator_register(struct snd_soc_codec *codec, config.driver_data = ldo; config.init_data = init_data; - ldo->dev = regulator_register(&ldo->desc, &config); + ldo->dev = devm_regulator_register(codec->dev, &ldo->desc, &config); if (IS_ERR(ldo->dev)) { int ret = PTR_ERR(ldo->dev); dev_err(codec->dev, "failed to register regulator\n"); - kfree(ldo->desc.name); - kfree(ldo); - return ret; } sgtl5000->ldo = ldo; return 0; } - -static int ldo_regulator_remove(struct snd_soc_codec *codec) -{ - struct sgtl5000_priv *sgtl5000 = snd_soc_codec_get_drvdata(codec); - struct ldo_regulator *ldo = sgtl5000->ldo; - - if (!ldo) - return 0; - - regulator_unregister(ldo->dev); - kfree(ldo->desc.name); - kfree(ldo); - - return 0; -} #else static int ldo_regulator_register(struct snd_soc_codec *codec, struct regulator_init_data *init_data, @@ -902,11 +885,6 @@ static int ldo_regulator_register(struct snd_soc_codec *codec, dev_err(codec->dev, "this setup needs regulator support in the kernel\n"); return -EINVAL; } - -static int ldo_regulator_remove(struct snd_soc_codec *codec) -{ - return 0; -} #endif /* @@ -1278,23 +1256,17 @@ static int sgtl5000_enable_regulators(struct snd_soc_codec *codec) ret = devm_regulator_bulk_get(codec->dev, ARRAY_SIZE(sgtl5000->supplies), sgtl5000->supplies); if (ret) - goto err_ldo_remove; + return ret; ret = regulator_bulk_enable(ARRAY_SIZE(sgtl5000->supplies), sgtl5000->supplies); if (ret) - goto err_ldo_remove; + return ret; /* wait for all power rails bring up */ udelay(10); return 0; - -err_ldo_remove: - if (!external_vddd) - ldo_regulator_remove(codec); - return ret; - } static int sgtl5000_probe(struct snd_soc_codec *codec) @@ -1359,8 +1331,6 @@ static int sgtl5000_probe(struct snd_soc_codec *codec) err: regulator_bulk_disable(ARRAY_SIZE(sgtl5000->supplies), sgtl5000->supplies); - ldo_regulator_remove(codec); - return ret; } @@ -1372,8 +1342,6 @@ static int sgtl5000_remove(struct snd_soc_codec *codec) regulator_bulk_disable(ARRAY_SIZE(sgtl5000->supplies), sgtl5000->supplies); - ldo_regulator_remove(codec); - return 0; }