Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5650617img; Wed, 27 Mar 2019 12:27:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqzePZl6kum4J/LcbYdr/KK+XyYdjE8ba2a1B+yQHap+rVmKuTLnaqMYqqgInwiNlh35ckn2 X-Received: by 2002:a62:7042:: with SMTP id l63mr36339901pfc.1.1553714831194; Wed, 27 Mar 2019 12:27:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553714831; cv=none; d=google.com; s=arc-20160816; b=cGoecyMPKUehrTt1W63o4aqfFc9wVcf0lSoOhsLnAyL9RUFfOqBuXeUA1KYTbuxkvK cCj8V5Jt57YD42kWUTtzaNYb0e1jclLwC0CaeVBtYDQoTCVkr0VkGPDq/A1dqJGPbd8d ZW65f0MSSPd8txww60YkLpyIifc2AktkWIN1GvOr6eCghuUFIoFk2M+OpL+3RqzNw63j 7bsjlKSzGmRfGUQYXQVCeIdhUPo8d8tXKum+4qUk6DislivcOt9SIrK+MUy6dTWBcfcy PwASkjlnPrk3/Hf4pkKdRHROoZNqYiQL5RFW3uEbvSdyPiZMqAYDrQ+sueyfFUc72HVZ Z+Ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+mqEFbuQrpbwN8qyn9zu3Y//PZm/QJSA8VRAo5MOcyk=; b=B9RZHgOL1izSJ0AsMUW6iq5kEAmZ1N0Jrih1wHdhjv3zNmQsDja6hRlHOo72m355Cq VDYqCzc5B5FRL/KhZoIhD7T+H7g0EXMNnlv4j8vbHUCHsAl7/EiD42IVUyAK9y4eg+3n fKuYWCP65WJir7Tlk9n5HvfwMnSnR8LcO18u7KznqLWxf6m72OcAc8qvkSz67RvVRNTv 8MRHtyZgXZkX8zP1eOuDyOSqRAyObrlrKcRQdgLdBIlvLkDSFp3cMTvY3RC+NAoIynRW Ps/nnt3CB8wBWKwhqVXKKJ8z5iSwncSvm7i0VKDPpB8lU3LAN+pfVzZNC7nTshlxY2Y1 YVcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rf2ZN2fw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m2si19634683plt.394.2019.03.27.12.26.56; Wed, 27 Mar 2019 12:27:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rf2ZN2fw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387656AbfC0SFR (ORCPT + 99 others); Wed, 27 Mar 2019 14:05:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:46282 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387618AbfC0SFN (ORCPT ); Wed, 27 Mar 2019 14:05:13 -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 37A5221738; Wed, 27 Mar 2019 18:05:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553709913; bh=nwtcJiy1x6Yub+yReLQSqksrZ2yXAUeHHdwgOl5CP2Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rf2ZN2fwb7UFjcTQ3Zoak3ABeEn6rbdgV00wOIV+byn/HX0rq8/mzs4e545tuHfnO 6MQ7K5wt2vzI1TnQYsMe9kzZ/M5TG7BK/AwJQB1XCwkKDSL3kGn7Fg/+Tk/uIg++mG HuqTF5Vz6n7KQMZ7tzFuaxpvKxtASwxEXRsUIJhs= 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 5.0 108/262] ASoC: qcom: Fix of-node refcount unbalance in qcom_snd_parse_of() Date: Wed, 27 Mar 2019 13:59:23 -0400 Message-Id: <20190327180158.10245-108-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-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