From patchwork Mon Oct 24 11:30:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8926 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp434670wru; Mon, 24 Oct 2022 05:52:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6m3HfOhqTb+/xM859qGDjfn+bd9naq4SXfpprh1x9sm8XHSd5yC9pC7V3aBpjvTHj+uL5r X-Received: by 2002:a17:907:dac:b0:78e:17a0:d1cb with SMTP id go44-20020a1709070dac00b0078e17a0d1cbmr27755782ejc.618.1666615961242; Mon, 24 Oct 2022 05:52:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615961; cv=none; d=google.com; s=arc-20160816; b=j6FB/mHAtjSosTY8sNF6sRPQaOx1QScXoJ8FNVBitCCnlCGUVUtZnE363MwSaZ/+jJ z9ub4X/fJv9RlkqbYbra/HGp+G3zjKZos9O3DjVLMBkd6CSYz7a+50GrGUSgeGJ0laYw L6uTP4UlUjBAsC6xTs4AjywGkDjZRWCaRYCoopbmzgLV9QrsB4s6KIe7U6MbEbMyFnQY QZcKnN+aBq0BPigKmzUnt8sB8OGJy2cOF1MhVHmAuxyAXlsNTvIfD/VmQqdYpXVRyapR TUWVcnRtDh5VPiQ3cgnGYwRfurwyt8VW2thAjE8Pn6B5W4nGXoExkHAcZcKuZYV/DGdD 8jYQ== 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=XXkRnNRnS71n76ApnkrnNyCg0eJtwia58A4rfORHHxk=; b=AJgyuDIHvz+sNMYIIiOSsI8GaYPSye0SLZhL0jiU2rExZpTSRHgnyd43gLXFQRpcgL KWK6RhQ1p7jNy0ZlYLokOXKJQqe/W655vgoChlg7Si18dAx01ysGCSYYPh7SZOr4XZJD mcPf5Bim4hqee4LzQ59z6db85MEEcEVSIhh4G6z9GVSvgy4nFPRPmiJNM7NM19UzGez5 CCf4G9ZaU8cxe8u23xNSlfkuQVAhlcrXMLYYyqR0gxIoIEKF5/EGNK5+54vOoXEAUJcu deP1a+3iMDi1wlKbWInkMJZPFhzG0GVqLJlDV9ZukLOctCWLbMsHL9W7T9eZ0zvk6TwH 5dhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wxuh472X; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r18-20020a05640251d200b004593895fb89si1213903edd.390.2022.10.24.05.52.16; Mon, 24 Oct 2022 05:52: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=wxuh472X; 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 S234464AbiJXMvN (ORCPT + 99 others); Mon, 24 Oct 2022 08:51:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234712AbiJXMpd (ORCPT ); Mon, 24 Oct 2022 08:45:33 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A01A31EFA; Mon, 24 Oct 2022 05:09:58 -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 DB9256127C; Mon, 24 Oct 2022 12:09:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0A11C433C1; Mon, 24 Oct 2022 12:09:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613369; bh=Uhl66iM0KuPXimYo3oJQbWlMZPTK9qOjxrbDCHLHOMs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wxuh472XpSxQa10UbbXejG5ln65nRlpLA3p4XKsfQQM2h9vRuYn2Rnc4AnVE/am0K 8QWCd8SQbhnygq7eI0ygvVtjdHCLIMlhcXhEp0mCXbKaakQEpOgJ06QCipOGwY2Z40 v7HNtbVRi5VdVeNoZFuK3AuFMkWv+xO6Don6fpME= 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.4 110/255] soc: qcom: smsm: Fix refcount leak bugs in qcom_smsm_probe() Date: Mon, 24 Oct 2022 13:30:20 +0200 Message-Id: <20221024113006.146074628@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747573498127910262?= X-GMAIL-MSGID: =?utf-8?q?1747573498127910262?= 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 6564f15c5319..acba67dfbc85 100644 --- a/drivers/soc/qcom/smsm.c +++ b/drivers/soc/qcom/smsm.c @@ -511,7 +511,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 */ @@ -519,13 +519,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 */ @@ -533,13 +534,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 */ @@ -550,7 +552,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. */ @@ -580,16 +583,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; }