Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp3532716rdb; Sun, 10 Dec 2023 09:19:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IEdgxzt6Ta5uW0Rd8+j0d5tSZyaDj15Wxs/fKF3i1u83njLytrjF/u26xZM2pQFnrJ35h6d X-Received: by 2002:a05:6a20:430f:b0:18f:97c:b9f1 with SMTP id h15-20020a056a20430f00b0018f097cb9f1mr1375207pzk.75.1702228767756; Sun, 10 Dec 2023 09:19:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702228767; cv=none; d=google.com; s=arc-20160816; b=U8QFeRo5nYW+XPp21F4aqxt+BZDJm1zrzled0ejoYiScyR6WStzgBU754BzFQ2d6GZ tCH0GKls43dBvz6KGTrFwPYRwO1m6D88613kaYG7/7bljXBBo0IceSz7jA4cLjtpVEIb y2EwJUysDca1aHzgsB0IL682tcetyfBR9Bb1NziMl/O1qeeMJ/C5zDvyxkyb3IKbYezY 3nx8kOp1oCdk3mJHCq8WxzxFJWpL3S8PianbJwkhpj/YvnVRsZhi0OZdtgApopS+DbN8 kTIUhFaIxiODOAT57UmdfI79AEOQb/2hNIKOAzaFXtnfxLoFkUuoNjtdMDM0iqGncFfz nMdw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=IJ/wf0TFY3jIklXy55GzkHPDNA98SpFq1MQxY2HzAuY=; fh=7fdFUGdfNKuZqDvx4RoaXnrER/PYxNqNow14wUF2QxU=; b=eVz3lS5Hw+YNMDhxO/bWA1eGvytp0y+MunjngKpmpF4QpGeoenffTYEuvwuS+3BHKa F5WWmSwyaK4hFqaQwUV+6p94yqSv77EF6SC9+kjljPXIyTm1N0ghRFrnLuvbonm/oKUe 4UhlIaBrETj1H/ExhMPAzH5JeX1KYG/8Y5tcHYfr9ShSMAnvxZ04NrCUWwSkbBPIp33f kBVYtdql3QFmJ/mPWuNbrk2FgeIgXFz1REUfASDHs3/yE/m4efR4Tei8H1/F0iiRE+s/ 5vMLyT7Qn6qwgvVEHKrrD07nYiTD1CPzE30d4vOUPb80JxFW7PKASow8QDZz9uL8PPb7 /h+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=TUUpOrdg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id c18-20020a056a000ad200b006cba60de063si4806106pfl.22.2023.12.10.09.19.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 09:19:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=TUUpOrdg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 6415B807DEE3; Sun, 10 Dec 2023 09:19:25 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231844AbjLJRTL (ORCPT + 99 others); Sun, 10 Dec 2023 12:19:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229550AbjLJRTK (ORCPT ); Sun, 10 Dec 2023 12:19:10 -0500 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 498A0BD; Sun, 10 Dec 2023 09:19:17 -0800 (PST) Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-55b5a37acb6so640128a12.0; Sun, 10 Dec 2023 09:19:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702228756; x=1702833556; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=IJ/wf0TFY3jIklXy55GzkHPDNA98SpFq1MQxY2HzAuY=; b=TUUpOrdguyBa9IdyXb6l2rYyGQKtb2Rlvx9P7R7h7pyTTxFEKuHpP5nqQ7Y5p3mgs2 BLG30TblO/UjCt/Nvj9giWCyMps0Ff91vgSkvfJKqSIWDmXfEB8Jq861/IGigwTZijtv Gx2TgJf0YmHqZLdev2ueNapy7qlRF616wuCb1ScA640C0MRdgOJ9VoD1U9e5Eu3U5by/ cF7elkJ8SPX2pFgdxsbXLY9/MuwHk3GT7iQJGp5/r9KfZ9IBlsErv00TPSUlm0WjBQrN zjwqNEVOpvqezKfIGd4qiQzvC3iFN7/MUbfpLvmcdAx9C3C7r1WAfT17krdilRCqSfZY R6ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702228756; x=1702833556; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IJ/wf0TFY3jIklXy55GzkHPDNA98SpFq1MQxY2HzAuY=; b=RKDDfHpv9ogjnr3Ql6fEMHTFKxAc0in/OzhFA/Q+Z2Pj6r9wR5bM4t+PhugtzuQDCZ k1HBZTQKlZ3oxCZOffS1ZUYFtUwjbXJIQP5K1PWmXWXaCBOGfJrvTrAHAkUtzakSZFSi wfyaJUReiOaA3U1/1sIhqz3/KugKsAaA30cLyrLvQ7fP5oFms85/lMCJf6ZG6GhXMngU lMLAVSyWCqfc9UFUA7hvkkrx5JSMDNXi4Xzl30KV+RosVrQ5wp/ODUSgCF5Z/348DXL0 GYUkGPF5/DIV/tWin7and4jelPs8OpcbHzMlPMcePb7bjVKUxNSPtX6ZIY8bDHY/uj8h NpQw== X-Gm-Message-State: AOJu0YzUqPtqZE4ifCwed3CCrYmFceltHZchO6bM9S8KVhgdxS1oH1UW bp8AQ1SfpoBHgS3bXrDmq8Y= X-Received: by 2002:a17:902:ee81:b0:1d0:5efd:35cf with SMTP id a1-20020a170902ee8100b001d05efd35cfmr5966163pld.4.1702228756529; Sun, 10 Dec 2023 09:19:16 -0800 (PST) Received: from localhost.localdomain ([140.116.154.65]) by smtp.gmail.com with ESMTPSA id m2-20020a170902bb8200b001c62b9a51a4sm4976264pls.239.2023.12.10.09.19.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 09:19:15 -0800 (PST) From: Kuan-Wei Chiu To: abelvesa@kernel.org Cc: peng.fan@nxp.com, mturquette@baylibre.com, sboyd@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Kuan-Wei Chiu Subject: [PATCH] clk: imx: scu: Fix memory leak in __imx_clk_gpr_scu() Date: Mon, 11 Dec 2023 01:19:07 +0800 Message-Id: <20231210171907.3410922-1-visitorckw@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Sun, 10 Dec 2023 09:19:25 -0800 (PST) In cases where imx_clk_is_resource_owned() returns false, the code path does not handle the failure gracefully, potentially leading to a memory leak. This fix ensures proper cleanup by freeing the allocated memory for 'clk_node' before returning. Signed-off-by: Kuan-Wei Chiu --- drivers/clk/imx/clk-scu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/clk/imx/clk-scu.c b/drivers/clk/imx/clk-scu.c index be89180dd19c..e48a904c0013 100644 --- a/drivers/clk/imx/clk-scu.c +++ b/drivers/clk/imx/clk-scu.c @@ -886,8 +886,10 @@ struct clk_hw *__imx_clk_gpr_scu(const char *name, const char * const *parent_na return ERR_PTR(-EINVAL); } - if (!imx_clk_is_resource_owned(rsrc_id)) + if (!imx_clk_is_resource_owned(rsrc_id)) { + kfree(clk_node); return NULL; + } clk = kzalloc(sizeof(*clk), GFP_KERNEL); if (!clk) { -- 2.25.1