All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Mark Brown <broonie@kernel.org>, Liam Girdwood <lgirdwood@gmail.com>
Cc: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>,
	patches@opensource.wolfsonmicro.com, alsa-devel@alsa-project.org,
	Lars-Peter Clausen <lars@metafoo.de>
Subject: [PATCH 12/14] ASoC: wm9713: Move driver state struct allocation to driver probe
Date: Thu, 30 Oct 2014 21:01:09 +0100	[thread overview]
Message-ID: <1414699271-22797-13-git-send-email-lars@metafoo.de> (raw)
In-Reply-To: <1414699271-22797-1-git-send-email-lars@metafoo.de>

Resources for the device should be allocated in the device driver probe
callback, rather than in the ASoC CODEC probe callback.

E.g. one advantage is that we can use device managed allocations.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 sound/soc/codecs/wm9713.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/sound/soc/codecs/wm9713.c b/sound/soc/codecs/wm9713.c
index ba8c276..2704783 100644
--- a/sound/soc/codecs/wm9713.c
+++ b/sound/soc/codecs/wm9713.c
@@ -1191,17 +1191,11 @@ static int wm9713_soc_resume(struct snd_soc_codec *codec)
 
 static int wm9713_soc_probe(struct snd_soc_codec *codec)
 {
-	struct wm9713_priv *wm9713;
 	int ret = 0, reg;
 
-	wm9713 = kzalloc(sizeof(struct wm9713_priv), GFP_KERNEL);
-	if (wm9713 == NULL)
-		return -ENOMEM;
-	snd_soc_codec_set_drvdata(codec, wm9713);
-
 	ret = snd_soc_new_ac97_codec(codec, soc_ac97_ops, 0);
 	if (ret < 0)
-		goto codec_err;
+		return ret;
 
 	/* do a cold reset for the controller and then try
 	 * a warm reset followed by an optional cold reset for codec */
@@ -1220,16 +1214,12 @@ static int wm9713_soc_probe(struct snd_soc_codec *codec)
 
 reset_err:
 	snd_soc_free_ac97_codec(codec);
-codec_err:
-	kfree(wm9713);
 	return ret;
 }
 
 static int wm9713_soc_remove(struct snd_soc_codec *codec)
 {
-	struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
 	snd_soc_free_ac97_codec(codec);
-	kfree(wm9713);
 	return 0;
 }
 
@@ -1256,6 +1246,14 @@ static struct snd_soc_codec_driver soc_codec_dev_wm9713 = {
 
 static int wm9713_probe(struct platform_device *pdev)
 {
+	struct wm9713_priv *wm9713;
+
+	wm9713 = devm_kzalloc(&pdev->dev, sizeof(*wm9713), GFP_KERNEL);
+	if (wm9713 == NULL)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, wm9713);
+
 	return snd_soc_register_codec(&pdev->dev,
 			&soc_codec_dev_wm9713, wm9713_dai, ARRAY_SIZE(wm9713_dai));
 }
-- 
1.8.0

  parent reply	other threads:[~2014-10-30 20:01 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-30 20:00 [PATCH 00/14] ASoC: AC'97 driver cleanups Lars-Peter Clausen
2014-10-30 20:00 ` [PATCH 01/14] ASoC: ad1980: Remove unused header Lars-Peter Clausen
2014-10-31 17:19   ` Mark Brown
2014-10-30 20:00 ` [PATCH 02/14] ASoC: ad1980: Cleanup printk usage Lars-Peter Clausen
2014-10-31 17:19   ` Mark Brown
2014-10-30 20:01 ` [PATCH 03/14] ASoC: ad1980: Use table based control setup Lars-Peter Clausen
2014-10-31 17:19   ` Mark Brown
2014-10-30 20:01 ` [PATCH 04/14] ASoC: stac9766: Cleanup printk usage Lars-Peter Clausen
2014-10-30 20:01 ` [PATCH 05/14] ASoC: stac9766: Use table based control setup Lars-Peter Clausen
2014-10-30 20:01 ` [PATCH 06/14] ASoC: wm9705: Cleanup printk usage Lars-Peter Clausen
2014-10-30 20:01 ` [PATCH 07/14] ASoC: wm9705: Use table based control setup Lars-Peter Clausen
2014-10-30 20:01 ` [PATCH 08/14] ASoC: wm9712: Cleanup printk usage Lars-Peter Clausen
2014-10-31 17:32   ` Mark Brown
2014-10-30 20:01 ` [PATCH 09/14] ASoC: wm9712: Use table based control setup Lars-Peter Clausen
2014-10-31 17:32   ` Mark Brown
2014-10-30 20:01 ` [PATCH 10/14] ASoC: wm9713: Cleanup printk usage Lars-Peter Clausen
2014-10-30 20:01 ` [PATCH 11/14] ASoC: wm9713: Use table based control setup Lars-Peter Clausen
2014-10-30 20:01 ` Lars-Peter Clausen [this message]
2014-10-30 20:01 ` [PATCH 13/14] ASoC: wm9713: Use virtual control instead of virtual register Lars-Peter Clausen
2014-10-30 20:01 ` [PATCH 14/14] ASoC: wm9712/wm9713: Use shared controls Lars-Peter Clausen
2014-10-31 17:40   ` Mark Brown
2014-10-31 17:55     ` Lars-Peter Clausen
2014-10-31 10:35 ` [PATCH 00/14] ASoC: AC'97 driver cleanups Charles Keepax

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1414699271-22797-13-git-send-email-lars@metafoo.de \
    --to=lars@metafoo.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=ckeepax@opensource.wolfsonmicro.com \
    --cc=lgirdwood@gmail.com \
    --cc=patches@opensource.wolfsonmicro.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.