From patchwork Mon Oct 24 11:30:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8639 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp421358wru; Mon, 24 Oct 2022 05:20:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6XBEyx038/ZXMjoEWX+9v7pqrAm7EtTiu92uu8A7eTfLH5krc5aukemPioi3ZaR2BXlw3t X-Received: by 2002:a17:907:a42c:b0:7aa:97e5:fac6 with SMTP id sg44-20020a170907a42c00b007aa97e5fac6mr1229092ejc.378.1666614020903; Mon, 24 Oct 2022 05:20:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666614020; cv=none; d=google.com; s=arc-20160816; b=GjSgUrvWdy1kWaWKMohGqWAUzO/nxvJ7FHMeITK6z0i/D7bj9NTNFQqurpdM/od6t2 yegzGzncp73q+/C9lM59HAUzKqldti2jG34adsLNWJ+YuGtE2aDmwxn4rwi6RorEg9PP T5gxc15em6CN1WkSBis/imRoAoM8r9F3QEDrBu113u5rYoHeKRtPhcbbQCs8bru3uvVA QxRs842NmSYgQe3cZQ+UoXf8EXnfBFLEK8JUreBcJAV7U+VSQ+O0iow4Q00ceK60L2y0 pCSZxiWdL72ssJXlEDFDzU0IcUsVddUYegUjpZfT80lbImfeSRL0TRLmIP1mtVTOfOgl k+Zw== 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=0l1UCfchiAOYZ9txbsQM9R2PKLiaKHIkWJKFIVeVXIU=; b=F7li1hABkL+UrF0R8p/Bg7vKBK73/9TIV+p1RCSfOsIlaE4bV/GvMBK4y0iz6MGXt1 G1Az0ahq+L0dVuGvNKjgm5tUZeifdpC75h/S10fc43/RpPy6hpjA2zeJWlN2SLNxTIf/ XEGS9vp5Zz1r5QBCid9s2mb16f4U+iAwuiJWKcAUc8vzBoKuxARDv+9KqpZ3DBXh0ZBg 3sQj0DLm5MfsdVuNG1uhBxIjPKB7K4hzAWYwlbMPJDvtByWiN+JSHIWpqI7nS6GC6v7Z aq4cWQzqI2OATdYRK7Qdzsam1cQnF9LB/Kui1Lk1rYvz3Wi7VtOhacYLqHzKl6sKm8fA QWiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jqqWLrMx; 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 ne21-20020a1709077b9500b007a8c58b51a3si2603126ejc.725.2022.10.24.05.19.57; Mon, 24 Oct 2022 05:20:20 -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=jqqWLrMx; 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 S232909AbiJXMNa (ORCPT + 99 others); Mon, 24 Oct 2022 08:13:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232903AbiJXMMf (ORCPT ); Mon, 24 Oct 2022 08:12:35 -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 DCC21BC8D; Mon, 24 Oct 2022 04:54:25 -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 44ED6612B2; Mon, 24 Oct 2022 11:51:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54708C433D6; Mon, 24 Oct 2022 11:51:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612281; bh=qKvP4bmsphMKHgqIDzfbkKxyiFWTwXsEYkyhH5HCDMQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jqqWLrMxIXsNYEZ8bTFfvDy+3uz8uLfR039xXRiF55o3YugPi555Q+NrZLbk2GLDS f8ycMJW9LV3cwoyQqVI+eydgKVPbbV/aWAaQXfr7cnPXFlMfGtjkG4Q4h4T0feG3Wq EXPuqMe9kX7nNnFosQlpJRbdZ7UBhGIk9WzU+VfI= 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 4.14 107/210] soc: qcom: smsm: Fix refcount leak bugs in qcom_smsm_probe() Date: Mon, 24 Oct 2022 13:30:24 +0200 Message-Id: <20221024113000.486304399@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112956.797777597@linuxfoundation.org> References: <20221024112956.797777597@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?1747571463495685920?= X-GMAIL-MSGID: =?utf-8?q?1747571463495685920?= 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 5304529b41c9..a8a1dc49519e 100644 --- a/drivers/soc/qcom/smsm.c +++ b/drivers/soc/qcom/smsm.c @@ -519,7 +519,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 */ @@ -527,13 +527,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 */ @@ -541,13 +542,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 */ @@ -558,7 +560,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. */ @@ -588,16 +591,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; }