From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEA16C43381 for ; Wed, 27 Mar 2019 19:06:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 770B8204FD for ; Wed, 27 Mar 2019 19:06:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553713574; bh=nwtcJiy1x6Yub+yReLQSqksrZ2yXAUeHHdwgOl5CP2Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Mk3P/jE488JzxF0HOnakga9XoVGqXrmprFm2p6h5oXJLWPAdoatUdpLt2zq12WPbM g6i2HfncKm9k/UK5uwMkdiVS3SoevHTP17lK5F4XZR8TPnbY8wsavZ+Y5m4m8BJmR9 S52RffezhAc1YsLyfrudS3eO8alR9vDIKVVES9V8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389328AbfC0TGN (ORCPT ); Wed, 27 Mar 2019 15:06:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:54958 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389211AbfC0SMb (ORCPT ); Wed, 27 Mar 2019 14:12:31 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 14A1A2177E; Wed, 27 Mar 2019 18:12:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553710350; bh=nwtcJiy1x6Yub+yReLQSqksrZ2yXAUeHHdwgOl5CP2Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aUMyANZblEAeRnaQHGA2a5MO+d+cjsa/yg3XG4aDalKlwpwCx/XvlzuSJrifp0p7I MAd6z64hZXtjE8VvAzJ9qVWKgKrn1p+h9tQ8UHuH17HyjHpsy74UgCyNKOXmdlvp5R tqoMvtA8TLUNW5zbzg0ugCHkEtJ57QP5wZdd8PGg= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Takashi Iwai , Patrick Lai , Banajit Goswami , Mark Brown , Sasha Levin Subject: [PATCH AUTOSEL 4.19 073/192] ASoC: qcom: Fix of-node refcount unbalance in qcom_snd_parse_of() Date: Wed, 27 Mar 2019 14:08:25 -0400 Message-Id: <20190327181025.13507-73-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327181025.13507-1-sashal@kernel.org> References: <20190327181025.13507-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Takashi Iwai [ Upstream commit 70b773219a32c7b8f3e53e041bc023ad99fd81f4 ] Although qcom_snd_parse_of() tries to manage the of-node refcount, there are still a few places that lead to the unblanced refcount in the error code path. Namely, - for_each_child_of_node() needs to unreference the iterator node if aborting the loop in the middle, - cpu, codec and platform node objects have to be unreferenced at each iteration, - platform and codec node objects have to be referred before jumping to the error handling code that unreference them unconditionally. This patch tries to address these by moving the assignment of platform and codec node objects to the beginning of the loop and adding the of_node_put() calls adequately. Fixes: c25e295cd77b ("ASoC: qcom: Add support to parse common audio device nodes") Cc: Patrick Lai Cc: Banajit Goswami Signed-off-by: Takashi Iwai Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/qcom/common.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sound/soc/qcom/common.c b/sound/soc/qcom/common.c index 4715527054e5..5661025e8cec 100644 --- a/sound/soc/qcom/common.c +++ b/sound/soc/qcom/common.c @@ -42,6 +42,9 @@ int qcom_snd_parse_of(struct snd_soc_card *card) link = card->dai_link; for_each_child_of_node(dev->of_node, np) { cpu = of_get_child_by_name(np, "cpu"); + platform = of_get_child_by_name(np, "platform"); + codec = of_get_child_by_name(np, "codec"); + if (!cpu) { dev_err(dev, "Can't find cpu DT node\n"); ret = -EINVAL; @@ -63,8 +66,6 @@ int qcom_snd_parse_of(struct snd_soc_card *card) goto err; } - platform = of_get_child_by_name(np, "platform"); - codec = of_get_child_by_name(np, "codec"); if (codec && platform) { link->platform_of_node = of_parse_phandle(platform, "sound-dai", @@ -100,10 +101,15 @@ int qcom_snd_parse_of(struct snd_soc_card *card) link->dpcm_capture = 1; link->stream_name = link->name; link++; + + of_node_put(cpu); + of_node_put(codec); + of_node_put(platform); } return 0; err: + of_node_put(np); of_node_put(cpu); of_node_put(codec); of_node_put(platform); -- 2.19.1