From patchwork Tue Jul 25 21:49:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Borneo X-Patchwork-Id: 9863965 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1C330601A1 for ; Tue, 25 Jul 2017 21:50:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D0EA1FF1F for ; Tue, 25 Jul 2017 21:50:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0065328712; Tue, 25 Jul 2017 21:50:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8B3311FF1F for ; Tue, 25 Jul 2017 21:50:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=ie66KhB5JtZgWAiVj5rTNXgIJqcuI2lFXD5723/kDb0=; b=p74 fYb8k/JXWeIz3lmKEZ04HbMbGSvuo734T9iGNl8QM01iCdbDXK+Xro3ncIt0yU2cNg9k3EUnFjceh uGM1W2RDvLIDP6tplJ3Sijt4qYQtqZyjpHIFJkLbRVUwNGVG9hIBIK+Bv3tSB4Lmep2YGSkescX9D DnZiGr6SCL8bcVqvKHVMjAXEyNXr9bKuFdM0nwbdWUPYnEjEx3RiuViwd4viPpoEhFYFDUh3fRzLv piftzbxeJSkia5GVx88X1egLRaMm5xzW2AuxN9wRmiFz2IUZlvB9ut59HQf0G7s36zi7Z50/Lbfmi 2bgaO93vZzIHqr+IBdtRA2zgsGDkiUA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1da7iq-0003at-2g; Tue, 25 Jul 2017 21:50:32 +0000 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1da7im-0003E9-DM for linux-arm-kernel@lists.infradead.org; Tue, 25 Jul 2017 21:50:30 +0000 Received: by mail-wr0-x242.google.com with SMTP id o33so13298611wrb.1 for ; Tue, 25 Jul 2017 14:50:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=eIb8XB6mFQeVg/ajBbIWVEVa9BCd7PcQX8vCW7MLvFw=; b=aSUsm68l0+w7zsfST9rtMUFOaYnxuSTwB54mpBqW/ZEvJVDuuN2Vt02vrG0G2uIP8r rFJyx/Jvq7lfe9HnKPjrhCmmh9RoBhqwusmu0ia53eCZUe7sWawta+kjQq2uqHMHPcm8 kYItsFoPSrCi8n3bopDLNThetPD1FWMN73T8QF/wWh5ziq2Z9WhALKD5Z/JoVcN3dDrw DMwB/VQqjCETFBaja+nBB1+uubtMkWybIJwvOhVl7CAysc3jRVeLMhASmwRJT2HFxHkI ON8Uvwljb52JR7KZH5hWAZ24dDDVQWRXzMGBh0UCczqcVCN2kwqMCFyBA5MMYoC0uvhy C8fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=eIb8XB6mFQeVg/ajBbIWVEVa9BCd7PcQX8vCW7MLvFw=; b=rsxL7YvFiPx4GZkYyiz7DB5Lg292oxObMb9t491FS0cvgrNh4VxgPv1QpWSYofBSY7 k7A1DJ06ZOcOnnLFoqCWOXP+aDbif9HMvOw3xe+T2aG2h9a5BfJF+OIimWP4QYWdY5hz xKp2PGFSI6G0Z868HGqZ2xkGa8EEROlY+Agda/U39v8v4SK5aISbbhNNjqpvK3b1P5k3 Aj4HyMRBXsma2vMjgJD6YkuVgcF5acDWPNmM1D63379ZF4IivEscEKs4HRX3BEKSPTv4 47JJPR9yeoLsd8krfyMODwh0D9wz4YBeOXMFqslEmMg1KbVFg7JHSSYA6ypxXqfqaIJS 3dvQ== X-Gm-Message-State: AIVw1128Kabq572mVMjp1F01Sqc80tMbRmwQKB/nT9kL8G0PyZ3N5wpf /KzbWjQ+kPiO6Q== X-Received: by 10.223.166.173 with SMTP id t42mr17043721wrc.272.1501019405406; Tue, 25 Jul 2017 14:50:05 -0700 (PDT) Received: from localhost.localdomain ([2a01:e34:edb8:72e0:f7c2:bbb1:de32:ba2a]) by smtp.gmail.com with ESMTPSA id v44sm19364958wrb.53.2017.07.25.14.50.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Jul 2017 14:50:03 -0700 (PDT) From: Antonio Borneo To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org Subject: [PATCH] ASoC: fix balance of of_node_get()/of_node_put() Date: Tue, 25 Jul 2017 23:49:52 +0200 Message-Id: <20170725214952.6491-1-borneo.antonio@gmail.com> X-Mailer: git-send-email 2.13.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170725_145028_634100_B16816C8 X-CRM114-Status: GOOD ( 14.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Antonio Borneo , John Stultz , linux-kernel@vger.kernel.org, Wei Xu , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On Hikey target board, enabling CONFIG_OF_DYNAMIC triggers several errors at kernel boot, like the following one OF: ERROR: Bad of_node_put() on /soc/i2s@f7118000/ports/port@0/endpoint each followed by stack dump. Fixed by: - removing of_node_put() in the body of of_for_each_phandle(){}, since already provided at each iteration. Add it in case the loop is break out; - adding of_node_get() before calling of_graph_get_port_parent() or asoc_graph_card_dai_link_of(). Tested with kernel v4.13-rc1 with hikey_defconfig taken from https://git.linaro.org/people/john.stultz/android-dev.git branch dev/hikey-mainline-WIP Signed-off-by: Antonio Borneo Tested-by: Kuninori Morimoto --- To: Liam Girdwood To: Mark Brown To: Jaroslav Kysela To: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org Cc: Wei Xu Cc: John Stultz Cc: linux-arm-kernel@lists.infradead.org --- sound/soc/generic/audio-graph-card.c | 14 +++++++++----- sound/soc/generic/simple-card-utils.c | 5 +++++ sound/soc/soc-core.c | 5 +++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/sound/soc/generic/audio-graph-card.c b/sound/soc/generic/audio-graph-card.c index c0f08a6..7574c5f 100644 --- a/sound/soc/generic/audio-graph-card.c +++ b/sound/soc/generic/audio-graph-card.c @@ -228,10 +228,16 @@ static int asoc_graph_card_parse_of(struct graph_card_data *priv) */ of_for_each_phandle(&it, rc, node, "dais", NULL, 0) { + /* + * asoc_graph_card_dai_link_of() will call + * of_node_put(). So, call of_node_get() here + */ + of_node_get(it.node); ret = asoc_graph_card_dai_link_of(it.node, priv, idx++); - of_node_put(it.node); - if (ret < 0) + if (ret < 0) { + of_node_put(it.node); return ret; + } } return asoc_simple_card_parse_card_name(card, NULL); @@ -244,10 +250,8 @@ static int asoc_graph_get_dais_count(struct device *dev) int count = 0; int rc; - of_for_each_phandle(&it, rc, node, "dais", NULL, 0) { + of_for_each_phandle(&it, rc, node, "dais", NULL, 0) count++; - of_node_put(it.node); - } return count; } diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c index 26d64fa..144954b 100644 --- a/sound/soc/generic/simple-card-utils.c +++ b/sound/soc/generic/simple-card-utils.c @@ -250,6 +250,11 @@ static int asoc_simple_card_get_dai_id(struct device_node *ep) if (ret != -ENOTSUPP) return ret; + /* + * of_graph_get_port_parent() will call + * of_node_put(). So, call of_node_get() here + */ + of_node_get(ep); node = of_graph_get_port_parent(ep); /* diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 921622a..a0f39de 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -4087,6 +4087,11 @@ int snd_soc_get_dai_id(struct device_node *ep) struct device_node *node; int ret; + /* + * of_graph_get_port_parent() will call + * of_node_put(). So, call of_node_get() here + */ + of_node_get(ep); node = of_graph_get_port_parent(ep); /*