From patchwork Mon Apr 28 12:30:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Nikula X-Patchwork-Id: 4077181 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 18B1D9F38E for ; Mon, 28 Apr 2014 12:31:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2803F202B4 for ; Mon, 28 Apr 2014 12:31:56 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id D8E0B202AE for ; Mon, 28 Apr 2014 12:31:51 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 3C17C261A29; Mon, 28 Apr 2014 14:31:50 +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, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 0301E2619E9; Mon, 28 Apr 2014 14:31:40 +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 01A69261600; Mon, 28 Apr 2014 14:31:38 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by alsa0.perex.cz (Postfix) with ESMTP id 66B492619F3 for ; Mon, 28 Apr 2014 14:31:29 +0200 (CEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 28 Apr 2014 05:31:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,944,1389772800"; d="scan'208";a="529801730" Received: from mylly.fi.intel.com (HELO mylly.fi.intel.com.) ([10.237.72.74]) by fmsmga002.fm.intel.com with ESMTP; 28 Apr 2014 05:30:57 -0700 From: Jarkko Nikula To: alsa-devel@alsa-project.org Date: Mon, 28 Apr 2014 15:30:51 +0300 Message-Id: <1398688251-11374-1-git-send-email-jarkko.nikula@linux.intel.com> X-Mailer: git-send-email 1.9.2 Cc: Mark Brown , Jarkko Nikula , Lars-Peter Clausen , Liam Girdwood Subject: [alsa-devel] [PATCH] ASoC: core: Fix component_list corruption when unloading modules 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 This fixes module unload regressions introduced by commits 98e639fb8a3e ("ASoC: Track which components have been registered with snd_soc_register_component()") and b37f1d123c69 ("ASoC: Let snd_soc_platform subclass snd_soc_component"). First commit causes component_list to be corrupted when removing codec and second when removing platform. Reason for both is that components associated with platform or codec are never removed from the list because for them registered_as_component field in struct snd_soc_component is always false. Now list becomes corrupted when snd_soc_unregister_platform() or snd_soc_unregister_codec() frees the platform or codec structure and where the associated struct snd_soc_component is embedded. Fix these by moving component unregistration and cleanup to a new local function __snd_soc_unregister_component() that takes component as its argument. Since component is known for platforms and codecs the __snd_soc_unregister_component() can be called directly and snd_soc_unregister_component() takes care to find and unregister only components that were registered using snd_soc_register_component(). Signed-off-by: Jarkko Nikula Acked-by: Lars-Peter Clausen --- sound/soc/soc-core.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index f18112a32541..62c3980fad5b 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -4061,6 +4061,18 @@ int snd_soc_register_component(struct device *dev, } EXPORT_SYMBOL_GPL(snd_soc_register_component); +static void __snd_soc_unregister_component(struct snd_soc_component *cmpnt) +{ + snd_soc_unregister_dais(cmpnt); + + mutex_lock(&client_mutex); + list_del(&cmpnt->list); + mutex_unlock(&client_mutex); + + dev_dbg(cmpnt->dev, "ASoC: Unregistered component '%s'\n", cmpnt->name); + kfree(cmpnt->name); +} + /** * snd_soc_unregister_component - Unregister a component from the ASoC core * @@ -4076,14 +4088,7 @@ void snd_soc_unregister_component(struct device *dev) return; found: - snd_soc_unregister_dais(cmpnt); - - mutex_lock(&client_mutex); - list_del(&cmpnt->list); - mutex_unlock(&client_mutex); - - dev_dbg(dev, "ASoC: Unregistered component '%s'\n", cmpnt->name); - kfree(cmpnt->name); + __snd_soc_unregister_component(cmpnt); } EXPORT_SYMBOL_GPL(snd_soc_unregister_component); @@ -4183,7 +4188,7 @@ EXPORT_SYMBOL_GPL(snd_soc_register_platform); */ void snd_soc_remove_platform(struct snd_soc_platform *platform) { - snd_soc_unregister_component(platform->dev); + __snd_soc_unregister_component(&platform->component); mutex_lock(&client_mutex); list_del(&platform->list); @@ -4388,7 +4393,7 @@ void snd_soc_unregister_codec(struct device *dev) return; found: - snd_soc_unregister_component(dev); + __snd_soc_unregister_component(&codec->component); mutex_lock(&client_mutex); list_del(&codec->list);