Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6738781rwi; Mon, 24 Oct 2022 05:37:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM63DYgek4u3Du9RoT5O5BVwjVt99vsosjKcK6VMG4TXj9J+3PLiFOsZ19L8D6BUfkXooewm X-Received: by 2002:a17:903:110f:b0:178:a07e:e643 with SMTP id n15-20020a170903110f00b00178a07ee643mr32554700plh.41.1666615050924; Mon, 24 Oct 2022 05:37:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615050; cv=none; d=google.com; s=arc-20160816; b=lSiQ549smBRZPN3WhgIWkn0y+DVjjicLJCj+/9qDATwFER3FgNNafKXdWiyUT+DrDg sXQ6pE/rXp1vwdkJ18Y+3PDitl8U/clZf15LbmpBUM5twUxcdYEkl2aSs8geEMeY5Cyh C2ytde3ysY1RQ6Z50ZGfUNhYNSUA2GqtzSy12KpqPBORMJPQ9OeKgL260inKiDRnFeIL a4hGDZBm71yZ72R8WiDUbO4K91wwfrRnlMLQj8r0urhtbdliZ0yAxEolNZvFdniO9C70 8Rq9Ez27NZp2uIpECgCC+C+S/0aNaFEyzTfu++lHWP0c85h110qW/Ll+2PQcxrso1H9g CxgQ== 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=K4+VndfIWmggfbtbdKj/IiplDjs0HJZUmty7SKKJxJI=; b=P5kHBj7GFQjy+PFqLrQI/DtYXr710u1CP5HdTX5znTQtBXcSXp7d1JXlALnEaok3u7 XMN7nnoZz9rXurk8m+sFOHXxD9AetgMnKWCA5r5vJNgWG3cT1WDtlFzcoaiIR/X2ieo8 cvH35SH1dRs+iMkZlFENaEGBs6kENRn01YP/Zg/0Sc6Qtrd5CNMNa/FoSarjnR6CiNHa A8ncuiJy6KmxD37AQQG51BggMbC4PVL2MGCDVC258DjTY/E5OSozseJ95DbzoykZFaNQ TkFKqfAS470js2NLEOQC8AkZfEJFegzepHxDe09NJD/b4GzcXYO7a/3HbtkbLtjSF7ZV a4mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=i3cI1W+8; 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 mz21-20020a17090b379500b00200ab48e149si7906230pjb.72.2022.10.24.05.37.19; Mon, 24 Oct 2022 05:37:30 -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=i3cI1W+8; 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 S231969AbiJXLw7 (ORCPT + 99 others); Mon, 24 Oct 2022 07:52:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231922AbiJXLwO (ORCPT ); Mon, 24 Oct 2022 07:52:14 -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 1EB8C193CC; Mon, 24 Oct 2022 04:44:41 -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 06D6461254; Mon, 24 Oct 2022 11:43:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A4C6C433C1; Mon, 24 Oct 2022 11:43:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611786; bh=+Ub/dlT9bc0ho4n4CTPaoj1vtKAy4tRTp1Z1r8ySh94=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i3cI1W+8+MacI7D8XIHvCV6w/IPmcuOy6YqbV2sSA7/w8Uwq/mw6Nw8Dk1c2rsTin jp2OpRk2a9L11Wzl/Qha0QSDBSMkzHV7dNddP1co6fAWQPF6gqpMA078hFokVipIfu RDmplrV3DuEk7Vm3+XvfciwHRfyU7aLXx1exifL4= 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.9 083/159] soc: qcom: smsm: Fix refcount leak bugs in qcom_smsm_probe() Date: Mon, 24 Oct 2022 13:30:37 +0200 Message-Id: <20221024112952.448915558@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112949.358278806@linuxfoundation.org> References: <20221024112949.358278806@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.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 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 01bc8528f24d..87ab37807e3f 100644 --- a/drivers/soc/qcom/smsm.c +++ b/drivers/soc/qcom/smsm.c @@ -515,7 +515,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 */ @@ -523,13 +523,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 */ @@ -537,13 +538,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 */ @@ -554,7 +556,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. */ @@ -584,16 +587,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