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: 9863963 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 0A1856038F for ; Tue, 25 Jul 2017 21:50:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F0B4B28649 for ; Tue, 25 Jul 2017 21:50:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E561928712; Tue, 25 Jul 2017 21:50:11 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43F9A28650 for ; Tue, 25 Jul 2017 21:50:11 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 077B3267342; Tue, 25 Jul 2017 23:50:10 +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 031BD267343; Tue, 25 Jul 2017 23:50:08 +0200 (CEST) Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) by alsa0.perex.cz (Postfix) with ESMTP id 94AFD266CD2 for ; Tue, 25 Jul 2017 23:50:05 +0200 (CEST) Received: by mail-wr0-f195.google.com with SMTP id g32so3535277wrd.5 for ; Tue, 25 Jul 2017 14:50:05 -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=W/vFmQU0zwlbrWluyR1PLpQEsaHEmytPfgNQ8NROIApzDVQmf5dYBSysDz5KAsnRBB nKuyGRLwTOaAxe72shPyFx02G8MRw+oEkuLrO+oPY9Smd9QO8wCc2Cvp74wHfdAk25vs SENNMIPIeuCBfcOA5xSvMa+Wsx27HKCUoQ421u+ho5T5W3LWbnCp686grfn8wOQE6xTz fAVQWBE2/b1lFQUCUGmvYcN/FdcOx3+azFo3lJlJSIUM7htRP0Zrb1XU1nURo4EWnG8F i/1AcLeyZJUPbClDU50N8SMfzUF++//QokHY0ZCDUVwr6qXvW3PNIs7/Xy92dHrJufUj lg/Q== X-Gm-Message-State: AIVw113grbFne5zjMPqPPgYsIn1lmRprHYfe7L7hde5osAleWbzk+GPA zaVk9x815CD8Ng== 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 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 Cc: Antonio Borneo , John Stultz , linux-kernel@vger.kernel.org, Wei Xu , linux-arm-kernel@lists.infradead.org Subject: [alsa-devel] [PATCH] ASoC: fix balance of of_node_get()/of_node_put() 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 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); /*