From patchwork Fri Aug 29 09:19:33 2014
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Xiubo Li
X-Patchwork-Id: 4813041
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 6F047C0338
for ;
Sat, 30 Aug 2014 00:03:19 +0000 (UTC)
Received: from mail.kernel.org (localhost [127.0.0.1])
by mail.kernel.org (Postfix) with ESMTP id 885132011D
for ;
Sat, 30 Aug 2014 00:03:18 +0000 (UTC)
Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243])
by mail.kernel.org (Postfix) with ESMTP id 608542010E
for ;
Sat, 30 Aug 2014 00:03:17 +0000 (UTC)
Received: by alsa0.perex.cz (Postfix, from userid 1000)
id 651B52661A5; Sat, 30 Aug 2014 02:03:16 +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 73222265605;
Fri, 29 Aug 2014 22:04:14 +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 8AC4E265600; Fri, 29 Aug 2014 22:04:11 +0200 (CEST)
Received: from na01-bn1-obe.outbound.protection.outlook.com
(mail-bn1lp0141.outbound.protection.outlook.com [207.46.163.141])
by alsa0.perex.cz (Postfix) with ESMTP id C6C3026563F
for ;
Fri, 29 Aug 2014 11:24:15 +0200 (CEST)
Received: from BN3PR0301CA0014.namprd03.prod.outlook.com (25.160.180.152) by
CY1PR0301MB0619.namprd03.prod.outlook.com (25.160.142.26) with
Microsoft SMTP
Server (TLS) id 15.0.1015.19; Fri, 29 Aug 2014 09:24:13 +0000
Received: from BN1BFFO11FD008.protection.gbl (2a01:111:f400:7c10::1:194) by
BN3PR0301CA0014.outlook.office365.com (2a01:111:e400:4000::24)
with Microsoft
SMTP Server (TLS) id 15.0.1015.19 via Frontend Transport;
Fri, 29 Aug 2014 09:24:13 +0000
Received: from az84smr01.freescale.net (192.88.158.2) by
BN1BFFO11FD008.mail.protection.outlook.com (10.58.144.71) with
Microsoft SMTP
Server (TLS) id 15.0.1010.11 via Frontend Transport; Fri, 29 Aug 2014
09:24:12 +0000
Received: from titan.ap.freescale.net ([10.192.208.233])
by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id
s7T9Nt8L018801; Fri, 29 Aug 2014 02:24:10 -0700
From: Xiubo Li
To: , ,
, ,
Date: Fri, 29 Aug 2014 17:19:33 +0800
Message-ID: <1409303973-1084-3-git-send-email-Li.Xiubo@freescale.com>
X-Mailer: git-send-email 1.8.5
In-Reply-To: <1409303973-1084-1-git-send-email-Li.Xiubo@freescale.com>
References: <1409303973-1084-1-git-send-email-Li.Xiubo@freescale.com>
X-EOPAttributedMessage: 0
X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:CAL; IPV:NLI;
EFV:NLI; SFV:NSPM;
SFS:(6009001)(199003)(189002)(69596002)(6806004)(68736004)(81156004)(20776003)(83322001)(87936001)(79102001)(19580395003)(84676001)(4396001)(77982001)(107046002)(64706001)(19580405001)(62966002)(106466001)(44976005)(81342001)(76176999)(229853001)(80022001)(47776003)(81542001)(88136002)(89996001)(104166001)(105606002)(50986999)(97736001)(74662001)(46102001)(85852003)(104016003)(95666004)(74502001)(77156001)(76482001)(26826002)(86362001)(50466002)(102836001)(31966008)(90102001)(92726001)(99396002)(83072002)(21056001)(87286001)(48376002)(36756003)(93916002)(92566001)(50226001)(85306004)(2201001);
DIR:OUT; SFP:; SCL:1; SRVR:CY1PR0301MB0619; H:az84smr01.freescale.net;
FPR:;
MLV:ovrnspm; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en;
MIME-Version: 1.0
X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;UriScan:;
X-Forefront-PRVS: 0318501FAE
Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not
designate 192.88.158.2 as permitted sender)
receiver=protection.outlook.com;
client-ip=192.88.158.2; helo=az84smr01.freescale.net;
Authentication-Results: spf=fail (sender IP is 192.88.158.2)
smtp.mailfrom=Li.Xiubo@freescale.com;
X-OriginatorOrg: freescale.com
Cc: Xiubo Li , linux-kernel@vger.kernel.org
Subject: [alsa-devel] [PATCH 2/2] ASoC: simple-card: Fix bug of wrong
decrement DT node's refcount
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
DAI links's cpu_of_node's and codec_of_node's refcounts shouldn't
be decremented immediately at the end of the probe() fucntion.
Because we will still use them before the audio card is removed.
Signed-off-by: Xiubo Li
---
sound/soc/generic/simple-card.c | 52 ++++++++++++++++++++++-------------------
1 file changed, 28 insertions(+), 24 deletions(-)
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index 9675bf7..c774dab 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -295,6 +295,22 @@ dai_link_of_err:
return ret;
}
+static inline void
+asoc_simple_card_unref(const struct snd_soc_dai_link *dai_link,
+ int num_links)
+{
+ struct device_node *np;
+
+ while (num_links--) {
+ np = dai_link[num_links].cpu_of_node;
+ if (np)
+ of_node_put(np);
+ np = dai_link[num_links].codec_of_node;
+ if (np)
+ of_node_put(np);
+ }
+}
+
static int asoc_simple_card_parse_of(struct device_node *node,
struct simple_card_data *priv,
struct device *dev,
@@ -340,6 +356,7 @@ static int asoc_simple_card_parse_of(struct device_node *node,
ret = simple_card_dai_link_of(np, dev, dai_link + i,
dai_props + i, false);
if (ret < 0) {
+ asoc_simple_card_unref(dai_link, i + 1);
of_node_put(np);
return ret;
}
@@ -358,27 +375,6 @@ static int asoc_simple_card_parse_of(struct device_node *node,
return 0;
}
-/* update the reference count of the devices nodes at end of probe */
-static int asoc_simple_card_unref(struct platform_device *pdev)
-{
- struct snd_soc_card *card = platform_get_drvdata(pdev);
- struct snd_soc_dai_link *dai_link;
- struct device_node *np;
- int num_links;
-
- for (num_links = 0, dai_link = card->dai_link;
- num_links < card->num_links;
- num_links++, dai_link++) {
- np = (struct device_node *) dai_link->cpu_of_node;
- if (np)
- of_node_put(np);
- np = (struct device_node *) dai_link->codec_of_node;
- if (np)
- of_node_put(np);
- }
- return 0;
-}
-
static int asoc_simple_card_probe(struct platform_device *pdev)
{
struct simple_card_data *priv;
@@ -425,7 +421,7 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
if (ret < 0) {
if (ret != -EPROBE_DEFER)
dev_err(dev, "parse error %d\n", ret);
- goto err;
+ return ret;
}
/*
@@ -483,11 +479,18 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
ret = devm_snd_soc_register_card(&pdev->dev, &priv->snd_card);
-err:
- asoc_simple_card_unref(pdev);
return ret;
}
+static int asoc_simple_card_remove(struct platform_device *pdev)
+{
+ struct snd_soc_card *card = platform_get_drvdata(pdev);
+
+ asoc_simple_card_unref(card->dai_link, card->num_links);
+
+ return 0;
+}
+
static const struct of_device_id asoc_simple_of_match[] = {
{ .compatible = "simple-audio-card", },
{},
@@ -501,6 +504,7 @@ static struct platform_driver asoc_simple_card = {
.of_match_table = asoc_simple_of_match,
},
.probe = asoc_simple_card_probe,
+ .remove = asoc_simple_card_remove,
};
module_platform_driver(asoc_simple_card);