From patchwork Sun Dec 10 17:19:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuan-Wei Chiu X-Patchwork-Id: 13486474 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A222FC4167B for ; Sun, 10 Dec 2023 17:19:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=hGH7Y+OiBaoO34olcW6/cTw0qq4UoOL+5W3XxEzrgHk=; b=lDop4Uj6bQ9oVw VSfqQgbas20ni1ioPxD9abs+VqkM93h/7tg5TuYdm1dVh/HXEVJ7CNT7agAXC4Oj24elPbYMLqTuR JlvHeAZg8gj5H9UO4TOxpwwxRta6fr+gJRARfLAK/4RcA8ogQOiEOpBZx8cgTazFv11+wZd9Rvz/f 5lBec+KiiNmL879lG0mtnOzeFwp1a2LmMxIXQ3AMHcxWBZ3vM7wqe9YQU8VG4K0TFEHWqgtzdf2x0 iHBthxtEeP7JWDnpaOcmONVsFRrSJFOQwIsEmvDbWxDKrkElMPMzP4J3CEIFfwk2DcYnj3qI9Qm2F wq+tOHNWuk50Ttiyp2iQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rCNSi-003Gv6-2O; Sun, 10 Dec 2023 17:19:28 +0000 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rCNSf-003GuB-15 for linux-arm-kernel@lists.infradead.org; Sun, 10 Dec 2023 17:19:27 +0000 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-55b5a37acb6so640129a12.0 for ; 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=lists.infradead.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=e4azy+aLmttals8j59LiQH8dOLfUmQ0antrS/FmKWqJP1j98ldED36OZefGGiBVG5Q j3GWvOSN85gUqp7Ky7QmLuT5e6+OV7Bk/MoKpsKSD5dDPSxKZ5+oPJ47Ph6JzVvVefh6 +XTraZxn7Q8OW3MgD9bj90NsMmKET71UDP1xu+w5XdfW2D+D4o4M6BqmiyPPQwpPIh3J w1mJ/V9NZ2alAnCsck1zamPHIcpgVt6l3hklJJB52dm1rGe8uVWnU++BKlGHxRFToc8y ZqnDe3x831nnKKAWP97xMRk1OAEyPGNfJYKKmpskfRfnfsFrzNAkohl6QgSWOklR3I19 HJbg== 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=qrubHQ/JGwP/j0EMBABTp9lCz4tYqARU29/0QkOzT0wslxykL5/k3lcYOuQxSoxbcm MN92s3sSCEVZESZE12RYOsry/5ykxylhAZkzgukZlCl91MC3k62tA3oTMB9tkfDh8yL5 C++PthfGbOQSzTcHJ2ggx9X10HhQ0sFxBwMHYB338CF88Az+pqfVzK+1ICh4/xBg4sGQ tppZra0YZ+6LZkiXyRkV8OqljNYuyzNzvJMbiMl+nrzeqSbcwPBnAfL07ljUgC8xjI+8 B339UDM3EKBdyvjdeOcQ7gA+PLmffNOgueeFg5mlJiLLjZLcAaGzOi3EWqs5KKtujiXP cvPg== X-Gm-Message-State: AOJu0Ywj9xKJVulwa69S/l68yeiMAs31MEIGQqme5t118lrFNMkkh3W5 +VKPuwvXFEvHdH4QF57WEsI= X-Google-Smtp-Source: AGHT+IHQb332XOYEfPhZRtEl4QLywKUOti5zdZlXfbGfGxO0RUFtNeJgzLpREEUN2NkCaiuK6oK9Cg== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231210_091925_404722_7DB33012 X-CRM114-Status: GOOD ( 11.48 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Reviewed-by: Peng Fan --- 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) {