Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3258544rwb; Mon, 15 Aug 2022 22:31:54 -0700 (PDT) X-Google-Smtp-Source: AA6agR7dDoIKl1/Dbn7jK0FjBfyrGkWE6gsWOvzOPbQQPZXFDpXDPH+EPiWkTGMQcKvJM0dFPFGe X-Received: by 2002:a05:6402:3514:b0:440:5538:3a97 with SMTP id b20-20020a056402351400b0044055383a97mr17460488edd.165.1660627914098; Mon, 15 Aug 2022 22:31:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660627914; cv=none; d=google.com; s=arc-20160816; b=KnqUmxK8szaDfdvauY2RrwaYOhm4pbxNhZaT77LAUgGpFq1aaZx3p60p1Pr0itZaIe NctsZaVYPhPKm7P1PkF9u9ZuuvKiV3MNu2zHrBgEhkm619MLnDbWmxQDvTK4GlaU79sn Swq02Jr/mbhhrg2VnewupZcwKPsGAe21jV8BKWAukvyfh+wCBzMPppfG+46WSMP6Gyjv iQekoeIJ+5hLywO20A/3VkGNBdSxEUgMlzdZdbwnyE+NrHODbR3oo5Tsx+rllJ5Y8mSO NtV4U1jDdED5Vq61fMcBRMKdlECOpMoDtQSOLSuGva4q33Aww12QdzKffQ2gFFrziaKR pXDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PpXAN/RQlYT+xlUnvYw9m0gfJR/smO8lSzlXOwQp+qA=; b=N6tZQF47p5nYTq3OewSkOpRd1FnNihMk56Cmb07nKhspTMYzp3QVmGT8WzVCHiMM4P /hu+SOreCggbkMihRyEIDVloPD8Us2Ggvcjauch7j+e8taZurOSHxaP0BAs2ACm+Ir1z JujLJQ3D4FHQfo1TNdM140rx5n9qn3jFmrFHfDDCv2OcM+EE0WHMtBczZa82x6A147K5 zwmWZDeeuCncbphMnUc6noyj33+/0qsrkwoI6Unt3XMmumlOhX1jZqzRa2RVGUCOABo8 7kmiug0PZCfRzq1dSiqH4o69QkFpYgW5F6wQiuuJzNbm98nEIzcpyUHUAngLQNzJvhAd q/WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iwHRhsuX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x42-20020a50baad000000b0043c8997b44dsi9210443ede.384.2022.08.15.22.31.29; Mon, 15 Aug 2022 22:31:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iwHRhsuX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231633AbiHPEr2 (ORCPT + 99 others); Tue, 16 Aug 2022 00:47:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232242AbiHPEoo (ORCPT ); Tue, 16 Aug 2022 00:44:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B31A19233F; Mon, 15 Aug 2022 13:40:38 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 271AE60F60; Mon, 15 Aug 2022 20:40:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB0F5C433C1; Mon, 15 Aug 2022 20:40:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660596037; bh=4j6xLiki7RQu8w3xPjg3bkrLFoXDa/GsticP4t84mxA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iwHRhsuXlWA2gZMnSMTJXUyX+kq9Aujkhrk1XgITagAjjLyKSH+yQqaBtlml193ZE vP6TQoorTGAUo2Mygtnkq8w0j9D0I98snQHGEFz8n9PEFD5RMlhRiGFAVpRtnZvOwX FWiakMwm0lBmHDryKTROg8fRiVveHQDgS7kBPIDs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liang He , Mark Brown , Sasha Levin Subject: [PATCH 5.19 0953/1157] ASoc: audio-graph-card2: Fix refcount leak bug in __graph_get_type() Date: Mon, 15 Aug 2022 20:05:09 +0200 Message-Id: <20220815180517.721567538@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Liang He [ Upstream commit eda26893dabfc6da7a1e1ff5f8628ed9faab3ab9 ] We should call of_node_put() for the reference before its replacement as it returned by of_get_parent() which has increased the refcount. Besides, we should also call of_node_put() before return. Fixes: c8c74939f791 ("ASoC: audio-graph-card2: add Multi CPU/Codec support") Signed-off-by: Liang He Link: https://lore.kernel.org/r/20220713071200.366729-1-windhl@126.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/generic/audio-graph-card2.c | 35 +++++++++++++++++++-------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/sound/soc/generic/audio-graph-card2.c b/sound/soc/generic/audio-graph-card2.c index 8e0628e6f2a0..5dba7c89007d 100644 --- a/sound/soc/generic/audio-graph-card2.c +++ b/sound/soc/generic/audio-graph-card2.c @@ -229,7 +229,8 @@ enum graph_type { static enum graph_type __graph_get_type(struct device_node *lnk) { - struct device_node *np; + struct device_node *np, *parent_np; + enum graph_type ret; /* * target { @@ -240,19 +241,33 @@ static enum graph_type __graph_get_type(struct device_node *lnk) * }; */ np = of_get_parent(lnk); - if (of_node_name_eq(np, "ports")) - np = of_get_parent(np); + if (of_node_name_eq(np, "ports")) { + parent_np = of_get_parent(np); + of_node_put(np); + np = parent_np; + } - if (of_node_name_eq(np, GRAPH_NODENAME_MULTI)) - return GRAPH_MULTI; + if (of_node_name_eq(np, GRAPH_NODENAME_MULTI)) { + ret = GRAPH_MULTI; + goto out_put; + } - if (of_node_name_eq(np, GRAPH_NODENAME_DPCM)) - return GRAPH_DPCM; + if (of_node_name_eq(np, GRAPH_NODENAME_DPCM)) { + ret = GRAPH_DPCM; + goto out_put; + } - if (of_node_name_eq(np, GRAPH_NODENAME_C2C)) - return GRAPH_C2C; + if (of_node_name_eq(np, GRAPH_NODENAME_C2C)) { + ret = GRAPH_C2C; + goto out_put; + } + + ret = GRAPH_NORMAL; + +out_put: + of_node_put(np); + return ret; - return GRAPH_NORMAL; } static enum graph_type graph_get_type(struct asoc_simple_priv *priv, -- 2.35.1