From nobody Mon Apr 27 03:18:09 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9501EC43334 for ; Sat, 18 Jun 2022 07:15:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234042AbiFRHPA (ORCPT ); Sat, 18 Jun 2022 03:15:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229755AbiFRHO6 (ORCPT ); Sat, 18 Jun 2022 03:14:58 -0400 Received: from m15114.mail.126.com (m15114.mail.126.com [220.181.15.114]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 24929E032 for ; Sat, 18 Jun 2022 00:14:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=yUGvi HoDuaYWc3NS2cFfqUOpZuOBhcDVFg5fEUfO50k=; b=Z8hMvxqr2n6DWaX01Dqgs N8xvqKxQPOHDuees4IkR4vaAqWNlFZHhfH4V3tdtGjQlP+7sHnSqd4u1RITTh65j 3WoGSBbPMFGDBaU70sqqfPHMHAqOy4YKHgAgoGfZzYpTm5k3HRivJp+FrSDPSnKz iFXdhpW6rMK8iBoKm/Lbxo= Received: from localhost.localdomain (unknown [124.16.139.61]) by smtp7 (Coremail) with SMTP id DsmowAD3Ovoxe61i4dmmDg--.41080S2; Sat, 18 Jun 2022 15:13:54 +0800 (CST) From: Liang He To: mpe@ellerman.id.au, benh@kernel.crashing.org, paulus@samba.org, atrajeev@linux.vnet.ibm.com, christophe.leroy@csgroup.eu Cc: windhl@126.com, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH] powerpc: perf: Fix refcount leak bug in imc-pmu.c Date: Sat, 18 Jun 2022 15:13:53 +0800 Message-Id: <20220618071353.4059000-1-windhl@126.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: DsmowAD3Ovoxe61i4dmmDg--.41080S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Zr4UXry5Xw4xKrW3uF4fuFg_yoW8WFy5pr WkCayFgr48tw1xu34SqFsFvrZ5t340gr4qqrW7W39FvFnrZr1ktF48Ar1rZryFyFyfJa4x Xw4Yqw47Ka4akaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziZYF_UUUUU= X-Originating-IP: [124.16.139.61] X-CM-SenderInfo: hzlqvxbo6rjloofrz/xtbBGgokF1-HZUrvjAABs2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In update_events_in_group(), of_find_node_by_phandle() will return a node pointer with refcount incremented. We should use of_node_put() in fail path or when it is not used anymore. Signed-off-by: Liang He Reviewed-by: Athira Rajeev --- arch/powerpc/perf/imc-pmu.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/perf/imc-pmu.c b/arch/powerpc/perf/imc-pmu.c index d7976ab40d38..d517aba94d1b 100644 --- a/arch/powerpc/perf/imc-pmu.c +++ b/arch/powerpc/perf/imc-pmu.c @@ -240,8 +240,10 @@ static int update_events_in_group(struct device_node *= node, struct imc_pmu *pmu) ct =3D of_get_child_count(pmu_events); =20 /* Get the event prefix */ - if (of_property_read_string(node, "events-prefix", &prefix)) + if (of_property_read_string(node, "events-prefix", &prefix)) { + of_node_put(pmu_events); return 0; + } =20 /* Get a global unit and scale data if available */ if (of_property_read_string(node, "scale", &g_scale)) @@ -255,8 +257,10 @@ static int update_events_in_group(struct device_node *= node, struct imc_pmu *pmu) =20 /* Allocate memory for the events */ pmu->events =3D kcalloc(ct, sizeof(struct imc_events), GFP_KERNEL); - if (!pmu->events) + if (!pmu->events) { + of_node_put(pmu_events); return -ENOMEM; + } =20 ct =3D 0; /* Parse the events and update the struct */ @@ -266,6 +270,8 @@ static int update_events_in_group(struct device_node *n= ode, struct imc_pmu *pmu) ct++; } =20 + of_node_put(pmu_events); + /* Allocate memory for attribute group */ attr_group =3D kzalloc(sizeof(*attr_group), GFP_KERNEL); if (!attr_group) { --=20 2.25.1