From patchwork Mon Nov 10 21:41:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lars-Peter Clausen X-Patchwork-Id: 5269651 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 894F8C11AC for ; Mon, 10 Nov 2014 21:54:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A6FE92010F for ; Mon, 10 Nov 2014 21:54:54 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 7956A20108 for ; Mon, 10 Nov 2014 21:54:53 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 66E1326172B; Mon, 10 Nov 2014 22:54:52 +0100 (CET) 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, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 062B42614A7; Mon, 10 Nov 2014 22:53:12 +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 8FDCE26109C; Mon, 10 Nov 2014 22:53:09 +0100 (CET) Received: from smtp-out-111.synserver.de (smtp-out-111.synserver.de [212.40.185.111]) by alsa0.perex.cz (Postfix) with ESMTP id B0C29261ACD for ; Mon, 10 Nov 2014 22:42:18 +0100 (CET) Received: (qmail 19141 invoked by uid 0); 10 Nov 2014 21:42:18 -0000 X-SynServer-TrustedSrc: 1 X-SynServer-AuthUser: lars@metafoo.de X-SynServer-PPID: 18663 Received: from ppp-46-244-163-23.dynamic.mnet-online.de (HELO lars-adi-laptop.fritz.box) [46.244.163.23] by 217.119.54.77 with SMTP; 10 Nov 2014 21:42:17 -0000 From: Lars-Peter Clausen To: Mark Brown , Liam Girdwood Date: Mon, 10 Nov 2014 22:41:45 +0100 Message-Id: <1415655713-29842-4-git-send-email-lars@metafoo.de> X-Mailer: git-send-email 1.8.0 In-Reply-To: <1415655713-29842-1-git-send-email-lars@metafoo.de> References: <1415655713-29842-1-git-send-email-lars@metafoo.de> Cc: alsa-devel@alsa-project.org, Lars-Peter Clausen , Stephen Warren , Sangbeom Kim , patches@opensource.wolfsonmicro.com, Timur Tabi , Nicolin Chen , Xiubo Li , Markus Pargmann , Charles Keepax Subject: [alsa-devel] [PATCH 03/11] ASoC: Properly handle AC'97 device lifetime management 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 The memory that a struct device is contained in must not be freed except from within the device's release callback. The ASoC code currently does not adhere to this rule for the AC'97 device. This patch fixes it by moving the freeing of the AC'97 to the release callback and splitting up the registration and unregistration of the device into separate steps for getting/putting the reference to the device and adding/removing it to the device hierarchy. Signed-off-by: Lars-Peter Clausen --- sound/soc/soc-core.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 397d00a..076dd36 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -501,13 +501,10 @@ EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime); static int soc_ac97_dev_unregister(struct snd_soc_codec *codec) { if (codec->ac97->dev.bus) - device_unregister(&codec->ac97->dev); + device_del(&codec->ac97->dev); return 0; } -/* stop no dev release warning */ -static void soc_ac97_device_release(struct device *dev){} - /* register ac97 codec to bus */ static int soc_ac97_dev_register(struct snd_soc_codec *codec) { @@ -515,12 +512,11 @@ static int soc_ac97_dev_register(struct snd_soc_codec *codec) codec->ac97->dev.bus = &ac97_bus_type; codec->ac97->dev.parent = codec->component.card->dev; - codec->ac97->dev.release = soc_ac97_device_release; dev_set_name(&codec->ac97->dev, "%d-%d:%s", codec->component.card->snd_card->number, 0, codec->component.name); - err = device_register(&codec->ac97->dev); + err = device_add(&codec->ac97->dev); if (err < 0) { dev_err(codec->dev, "ASoC: Can't register ac97 bus\n"); codec->ac97->dev.bus = NULL; @@ -1913,6 +1909,11 @@ static struct platform_driver soc_driver = { .remove = soc_remove, }; +static void soc_ac97_device_release(struct device *dev) +{ + kfree(to_ac97_t(dev)); +} + /** * snd_soc_new_ac97_codec - initailise AC97 device * @codec: audio codec @@ -1937,12 +1938,14 @@ int snd_soc_new_ac97_codec(struct snd_soc_codec *codec, codec->ac97->bus->ops = ops; codec->ac97->num = num; + codec->ac97->dev.release = soc_ac97_device_release; /* * Mark the AC97 device to be created by us. This way we ensure that the * device will be registered with the device subsystem later on. */ codec->ac97_created = 1; + device_initialize(&codec->ac97->dev); return 0; } @@ -2117,7 +2120,8 @@ void snd_soc_free_ac97_codec(struct snd_soc_codec *codec) soc_unregister_ac97_codec(codec); #endif kfree(codec->ac97->bus); - kfree(codec->ac97); + codec->ac97->bus = NULL; + put_device(&codec->ac97->dev); codec->ac97 = NULL; codec->ac97_created = 0; }