Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp658549pxb; Tue, 5 Apr 2022 17:37:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy85SNyoQregzD1SLNd0U2XBmZ2aQ+WoZOvhgGPVa/be/z4H1b4T4ZTECS9NkD+JLHuPYny X-Received: by 2002:a17:902:eb8f:b0:154:c7a4:937c with SMTP id q15-20020a170902eb8f00b00154c7a4937cmr5931935plg.111.1649205341846; Tue, 05 Apr 2022 17:35:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649205341; cv=none; d=google.com; s=arc-20160816; b=0Lct6+EL53QiyrU2OAHyC6zT6pTp8sOmUx11aF+KoHMM94SwkbYv4rL9OaietdYz2r 4v/E01LKni8+hFXrRU/h/APmpK3pyQgBVKTxLEfpgNXvEworJSt38rfM3b8UAbNRT/wJ CGeZ9B3onwX3FdyBjvolhN+AzvA4z5BKnPsFLPBH5G/OmJsmJrG75bmoQR0q+8CGavgy aZy5FMmMx6z9hh2pXUnv48f0FCOSklQvMcztVAlZkwj6RMjJjcLLsozhx/Btfs4GaeCK xOg8WNO0SFKxwgigMeTsI9XuaF0jBdbZtv/eXvU2TV/MDjX5a0LSDxM9wpFtFTept6n/ d1Dw== 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=GK3w60Z3sIEu/4nREpUDAkgJC0bAp7DX/XfG2O+vd+A=; b=efPLdyYrCLI8WlyCLANUaVrXC6uPKXY1R/s+6K7qaAzyEY0pJSRS6bFemKO1xtgQqb FSRzd3Zc2XKHTOIZYfUOPpnoNb56usruNsF/LIr/HNHAZQF6DnX89s1kzYni8OXZamyP PIjsvDVqOjJMBb6XJXqflSuPYsd2R7PR6NN58iU228xcksXrs22Kdpqs62ob/mvPVHx9 H+Y0krSEznLJfVRUbJ02GZgdYP109AL30d9MAh1vwShOdzrQEggCNJJZW9OvYPo6cuJP Yi6PbhbQz1khE20EQlojmSYvJ6fu87LrO2krwHbToKbFzWTAtG0uXxMwhLcjEBOXAoJx b0MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Fn8c0hM4; 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 s12-20020a170902ea0c00b00153b2d16445si4422342plg.77.2022.04.05.17.35.25; Tue, 05 Apr 2022 17:35:41 -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=Fn8c0hM4; 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 S1350800AbiDENGZ (ORCPT + 99 others); Tue, 5 Apr 2022 09:06:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343990AbiDEJQo (ORCPT ); Tue, 5 Apr 2022 05:16:44 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEB95D8F7D; Tue, 5 Apr 2022 02:02:23 -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 ams.source.kernel.org (Postfix) with ESMTPS id 828F3B81C19; Tue, 5 Apr 2022 09:02:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0B68C385A0; Tue, 5 Apr 2022 09:02:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149341; bh=vW3aZppNUsxHLSbPNy/WFu/pdlhv+bbciT+wAcuOJ0I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fn8c0hM4sV1Bf38A/GxvceNaD6jVmvZEHPxNBEPL0nhNJGOgFZMxaf6AgpCoNYVD7 tWTrSXgOayS+lZX1Pk4cgpLke++1sN+5PGa21/p9IdVC1cpyoJNuw1+G3ywLbi1m7R 5vnMWkRixctOXYpYl7iGCQzTMEpltBW1ssZ/6RnI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Miaoqian Lin , Bjorn Andersson , Sasha Levin Subject: [PATCH 5.16 0682/1017] remoteproc: qcom_q6v5_mss: Fix some leaks in q6v5_alloc_memory_region Date: Tue, 5 Apr 2022 09:26:35 +0200 Message-Id: <20220405070414.521899117@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 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: Miaoqian Lin [ Upstream commit 07a5dcc4bed9d7cae54adf5aa10ff9f037a3204b ] The device_node pointer is returned by of_parse_phandle() or of_get_child_by_name() with refcount incremented. We should use of_node_put() on it when done. This function only call of_node_put(node) when of_address_to_resource succeeds, missing error cases. Fixes: 278d744c46fd ("remoteproc: qcom: Fix potential device node leaks") Fixes: 051fb70fd4ea ("remoteproc: qcom: Driver for the self-authenticating Hexagon v5") Signed-off-by: Miaoqian Lin Signed-off-by: Bjorn Andersson Link: https://lore.kernel.org/r/20220308064522.13804-1-linmq006@gmail.com Signed-off-by: Sasha Levin --- drivers/remoteproc/qcom_q6v5_mss.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c index 43ea8455546c..b9ab91540b00 100644 --- a/drivers/remoteproc/qcom_q6v5_mss.c +++ b/drivers/remoteproc/qcom_q6v5_mss.c @@ -1806,18 +1806,20 @@ static int q6v5_alloc_memory_region(struct q6v5 *qproc) * reserved memory regions from device's memory-region property. */ child = of_get_child_by_name(qproc->dev->of_node, "mba"); - if (!child) + if (!child) { node = of_parse_phandle(qproc->dev->of_node, "memory-region", 0); - else + } else { node = of_parse_phandle(child, "memory-region", 0); + of_node_put(child); + } ret = of_address_to_resource(node, 0, &r); + of_node_put(node); if (ret) { dev_err(qproc->dev, "unable to resolve mba region\n"); return ret; } - of_node_put(node); qproc->mba_phys = r.start; qproc->mba_size = resource_size(&r); @@ -1828,14 +1830,15 @@ static int q6v5_alloc_memory_region(struct q6v5 *qproc) } else { child = of_get_child_by_name(qproc->dev->of_node, "mpss"); node = of_parse_phandle(child, "memory-region", 0); + of_node_put(child); } ret = of_address_to_resource(node, 0, &r); + of_node_put(node); if (ret) { dev_err(qproc->dev, "unable to resolve mpss region\n"); return ret; } - of_node_put(node); qproc->mpss_phys = qproc->mpss_reloc = r.start; qproc->mpss_size = resource_size(&r); -- 2.34.1