From nobody Mon Feb 9 06:19:20 2026 Received: from mail-m155101.qiye.163.com (mail-m155101.qiye.163.com [101.71.155.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B266292918 for ; Sun, 28 Dec 2025 12:48:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=101.71.155.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766926132; cv=none; b=IxIHcocM1ETo0nbcx2dFuzeD5ZtSc7/Rt3EGHOt+fuSw7pfCd+aLjMBLMHd6/ENu0Hddimuhfh/HvUhlHZhDLyPuZRNVCnnQ8mX4JWmL/ji19il4tZ+ofFckCpQ+ulyKvCC1wQTxkXGJLvc98Ng0ofu5dqc6zG9JfqnTkQFTEBQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766926132; c=relaxed/simple; bh=dMhNZJ2o72C4kJbGNv91B7v6IdjZ4YJWtW2fa0i+Quk=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=DLOkSXRv9YAjFyDvWe+mwNhw/HcFSgeABQyMSZT8Mh3Yr347PYZ4l7WV+6N2reLblzBXnzhZaf+HwFSjw4I1Yi56FMwphclg4wdDokHKJ4fnx4dqW4B3EohxZ5HGHXJKWcXmfxOEzujSTL0lXVKWDHTwOX6xjBxKE4AqtwW6ve4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn; spf=pass smtp.mailfrom=seu.edu.cn; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b=OdFARV9O; arc=none smtp.client-ip=101.71.155.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b="OdFARV9O" Received: from LAPTOP-N070L597.localdomain (unknown [58.241.16.34]) by smtp.qiye.163.com (Hmail) with ESMTP id 2eca68e1d; Sun, 28 Dec 2025 20:48:39 +0800 (GMT+08:00) From: Zilin Guan To: conor.dooley@microchip.com Cc: daire.mcnamara@microchip.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Zilin Guan , Jianhao Xu Subject: [PATCH] soc: microchip: mpfs: Fix memory leak in mpfs_sys_controller_probe() Date: Sun, 28 Dec 2025 12:48:36 +0000 Message-Id: <20251228124836.3681318-1-zilin@seu.edu.cn> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-HM-Tid: 0a9b6500f27803a1kunm8b0da3cda5767 X-HM-MType: 10 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVkZSBofVkhOTk4fT08fQxpKGVYeHw5VEwETFhoSFy QUDg9ZV1kYEgtZQVlOQ1VJT0pVSk1VSE9ZV1kWGg8SFR0UWUFZT0tIVUpLSUJDQ0xVSktLVUtZBg ++ DKIM-Signature: a=rsa-sha256; b=OdFARV9ONvNCho4sAGZiGFcKXEwgjxj5/IH4WU/h95xIMJlezjrviReOHeH3JdyUkpCNGsJCHajH9w8RAfVa+jrzJa57v87ccVVyDXc5rySMdwLKMV1aRvmO6gxG9G7Uo8AtQCiVG/Ry4jg/aa84vOakhELYApx67LNuUmDKZhw=; s=default; c=relaxed/relaxed; d=seu.edu.cn; v=1; bh=8TQHnr3dcefIVDlkuxlro1RTJr9H/RV8WrNYmYPmmtw=; h=date:mime-version:subject:message-id:from; Content-Type: text/plain; charset="utf-8" In mpfs_sys_controller_probe(), if of_get_mtd_device_by_node() fails, the function returns immediately without freeing the allocated memory for sys_controller, leading to a memory leak. Fix this by jumping to the out_free label to ensure the memory is properly freed. Also, consolidate the error handling for the mbox_request_channel() failure case to use the same label. Fixes: 742aa6c563d2 ("soc: microchip: mpfs: enable access to the system con= troller's flash") Co-developed-by: Jianhao Xu Signed-off-by: Jianhao Xu Signed-off-by: Zilin Guan --- drivers/soc/microchip/mpfs-sys-controller.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/soc/microchip/mpfs-sys-controller.c b/drivers/soc/micr= ochip/mpfs-sys-controller.c index 30bc45d17d34..81636cfecd37 100644 --- a/drivers/soc/microchip/mpfs-sys-controller.c +++ b/drivers/soc/microchip/mpfs-sys-controller.c @@ -142,8 +142,10 @@ static int mpfs_sys_controller_probe(struct platform_d= evice *pdev) =20 sys_controller->flash =3D of_get_mtd_device_by_node(np); of_node_put(np); - if (IS_ERR(sys_controller->flash)) - return dev_err_probe(dev, PTR_ERR(sys_controller->flash), "Failed to get= flash\n"); + if (IS_ERR(sys_controller->flash)) { + ret =3D dev_err_probe(dev, PTR_ERR(sys_controller->flash), "Failed to ge= t flash\n"); + goto out_free; + } =20 no_flash: sys_controller->client.dev =3D dev; @@ -155,8 +157,7 @@ static int mpfs_sys_controller_probe(struct platform_de= vice *pdev) if (IS_ERR(sys_controller->chan)) { ret =3D dev_err_probe(dev, PTR_ERR(sys_controller->chan), "Failed to get mbox channel\n"); - kfree(sys_controller); - return ret; + goto out_free; } =20 init_completion(&sys_controller->c); @@ -174,6 +175,10 @@ static int mpfs_sys_controller_probe(struct platform_d= evice *pdev) dev_info(&pdev->dev, "Registered MPFS system controller\n"); =20 return 0; + +out_free: + kfree(sys_controller); + return ret; } =20 static void mpfs_sys_controller_remove(struct platform_device *pdev) --=20 2.34.1