Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3920304rwi; Sat, 22 Oct 2022 02:13:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Vp2xSionm/GCIOUlDx5M2y21yyvepMmI3RJ/sQGaFVCWFzBACCBE4QpC3UjmCVBAkWejB X-Received: by 2002:a63:1f13:0:b0:455:80ce:6d36 with SMTP id f19-20020a631f13000000b0045580ce6d36mr20149023pgf.111.1666430008583; Sat, 22 Oct 2022 02:13:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666430008; cv=none; d=google.com; s=arc-20160816; b=rulHmgPp81u+h2FtalaqUXPVekfnRtmMezOw2D1aZkegdBvR2KSQMFYiS4+/0mey5z 12js2DkOlK/HWuVeCn98atV8VXugKfaqLL4G2V3l92vhJikuFOzdfwIQc50sHu0XJr76 tYpupNdmMm6RhGycUDmvp6Q2tXkDdtu/ljLbXme2EVO4GPhtyIRMY36wb0yD9D96f8cM M7l23ciA4pcnFXWcrmSN94z63cF+Kveq20Ix2ulG13GjocZKOW8zBHcYqZM0jrA3m0Ij IQBMTaVF97jA8zkWqdLbpONEc7ens7ab2dydScTIkkEwPHIfIHX5kdPESJF2zZPc9zmV jbmA== 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=FzmyfoUN3jOwm5ugmT9vrDIPu7CJRmVoV+4TDNIdZg4=; b=CxW39PYa8mEiJGhila/lGnzrLSNrXNgG9jkplQemR7urK8Yp8sDV7P5W2RBVq3LR/Z 57WqH+tXmo6rq76dy2/suHJLGuMU9hJcOZ6iCtzDksEk+0qaJAFbwDniAMpYzweC39oR vJuW1FTzPtd6bna2fkuAcPDOi0wcLrmzqsiwEa85B0kzhHNWCxDJfTrLqOpuBKCAm0P6 n5pjNO5seUD3tZ2p5HCn81eeO+ID8RYvmp9WrXn+YxSODVe63LF3CQnHrCbL2tuGGq0R +qr//zWbxDPr2Gv9t6DcwRXyk/eI7GGgZVRuAkSf5m+0p1j6+mkZc24lHrp1VN40A4ZE 1E0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kkGVWq0P; 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 f1-20020a637541000000b0045a2b6e23b6si28898561pgn.290.2022.10.22.02.13.16; Sat, 22 Oct 2022 02:13:28 -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=kkGVWq0P; 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 S229913AbiJVIbN (ORCPT + 99 others); Sat, 22 Oct 2022 04:31:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230000AbiJVI2T (ORCPT ); Sat, 22 Oct 2022 04:28:19 -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 56B552D6540; Sat, 22 Oct 2022 01:01:17 -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 8D657B82E17; Sat, 22 Oct 2022 07:49:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0214CC433D7; Sat, 22 Oct 2022 07:49:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424993; bh=XQAYMWo06//zIHjMBtnXreMiMDYguIyBbLd57r3zYXE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kkGVWq0PBZxzGX55+9eD9Y8tpyoeZJ2TTrVc0HiS+qJ4uVJhskW4EiFFW2rLVBhWx XjGDckeXtZwu908LZ3vTpDLsvshFC8xCLF7fP8yqXMJoWuipiHbzELpSNYTbuJ9vpF HX/d/3Qp/VK6xoCLLhIbWhZ5utNIKpyDMwv7sR6M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liang He , Bjorn Andersson , Sasha Levin Subject: [PATCH 5.19 352/717] soc: qcom: smsm: Fix refcount leak bugs in qcom_smsm_probe() Date: Sat, 22 Oct 2022 09:23:51 +0200 Message-Id: <20221022072511.394210487@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@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.3 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 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 af8f6f39b8afd772fda4f8e61823ef8c021bf382 ] There are two refcount leak bugs in qcom_smsm_probe(): (1) The 'local_node' is escaped out from for_each_child_of_node() as the break of iteration, we should call of_node_put() for it in error path or when it is not used anymore. (2) The 'node' is escaped out from for_each_available_child_of_node() as the 'goto', we should call of_node_put() for it in goto target. Fixes: c97c4090ff72 ("soc: qcom: smsm: Add driver for Qualcomm SMSM") Signed-off-by: Liang He Signed-off-by: Bjorn Andersson Link: https://lore.kernel.org/r/20220721135217.1301039-1-windhl@126.com Signed-off-by: Sasha Levin --- drivers/soc/qcom/smsm.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/soc/qcom/smsm.c b/drivers/soc/qcom/smsm.c index 9df9bba242f3..3e8994d6110e 100644 --- a/drivers/soc/qcom/smsm.c +++ b/drivers/soc/qcom/smsm.c @@ -526,7 +526,7 @@ static int qcom_smsm_probe(struct platform_device *pdev) for (id = 0; id < smsm->num_hosts; id++) { ret = smsm_parse_ipc(smsm, id); if (ret < 0) - return ret; + goto out_put; } /* Acquire the main SMSM state vector */ @@ -534,13 +534,14 @@ static int qcom_smsm_probe(struct platform_device *pdev) smsm->num_entries * sizeof(u32)); if (ret < 0 && ret != -EEXIST) { dev_err(&pdev->dev, "unable to allocate shared state entry\n"); - return ret; + goto out_put; } states = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_SMSM_SHARED_STATE, NULL); if (IS_ERR(states)) { dev_err(&pdev->dev, "Unable to acquire shared state entry\n"); - return PTR_ERR(states); + ret = PTR_ERR(states); + goto out_put; } /* Acquire the list of interrupt mask vectors */ @@ -548,13 +549,14 @@ static int qcom_smsm_probe(struct platform_device *pdev) ret = qcom_smem_alloc(QCOM_SMEM_HOST_ANY, SMEM_SMSM_CPU_INTR_MASK, size); if (ret < 0 && ret != -EEXIST) { dev_err(&pdev->dev, "unable to allocate smsm interrupt mask\n"); - return ret; + goto out_put; } intr_mask = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_SMSM_CPU_INTR_MASK, NULL); if (IS_ERR(intr_mask)) { dev_err(&pdev->dev, "unable to acquire shared memory interrupt mask\n"); - return PTR_ERR(intr_mask); + ret = PTR_ERR(intr_mask); + goto out_put; } /* Setup the reference to the local state bits */ @@ -565,7 +567,8 @@ static int qcom_smsm_probe(struct platform_device *pdev) smsm->state = qcom_smem_state_register(local_node, &smsm_state_ops, smsm); if (IS_ERR(smsm->state)) { dev_err(smsm->dev, "failed to register qcom_smem_state\n"); - return PTR_ERR(smsm->state); + ret = PTR_ERR(smsm->state); + goto out_put; } /* Register handlers for remote processor entries of interest. */ @@ -595,16 +598,19 @@ static int qcom_smsm_probe(struct platform_device *pdev) } platform_set_drvdata(pdev, smsm); + of_node_put(local_node); return 0; unwind_interfaces: + of_node_put(node); for (id = 0; id < smsm->num_entries; id++) if (smsm->entries[id].domain) irq_domain_remove(smsm->entries[id].domain); qcom_smem_state_unregister(smsm->state); - +out_put: + of_node_put(local_node); return ret; } -- 2.35.1