From nobody Thu Oct 2 20:44:48 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 F173F2DECA5 for ; Thu, 11 Sep 2025 21:56:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757627818; cv=none; b=qMJcKHROJldkhdFDYd8hjnTVT2zU8I//m8PCkrum8Hi9J2aSB/vEFMqbiPZGdnA+UJh8YeVsZoaWKj/q/BK9QY7dNqf6SMWDFaQx7Y8adpml/aNjXMbnmckzDAESi6JCjRhu41InmJyuDlwEUdBj5sxh9hOD1S4u+rsSlMb226U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757627818; c=relaxed/simple; bh=HJggFXsaK9sz5oEWiS9Gu/aCotSecUTWXBCVj5P5gxg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=boDds+IgwPIh0XhQamVIIQ13JpC601+drmBohKjeKXCfQpMcJ1uzKyhKs6oPvz8jzKNGJy7MJX9zsPTZD4CtF8D1sl+IK0kuMUiOsk/P0Lk1Ew0WQ5HnUipLWBG60zJJeD+SH+B4A8Mf9I0afNibqbCBAP82uix47u3/2U5TqVU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from dude02.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::28]) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1uwpHe-0004g5-9F; Thu, 11 Sep 2025 23:56:50 +0200 From: Marco Felsch Date: Thu, 11 Sep 2025 23:56:47 +0200 Subject: [PATCH v2 06/10] dmaengine: imx-sdma: make use of devm_kzalloc for script_addrs Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250911-v6-16-topic-sdma-v2-6-d315f56343b5@pengutronix.de> References: <20250911-v6-16-topic-sdma-v2-0-d315f56343b5@pengutronix.de> In-Reply-To: <20250911-v6-16-topic-sdma-v2-0-d315f56343b5@pengutronix.de> To: Vinod Koul , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Jiada Wang Cc: dmaengine@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Marco Felsch , Frank Li X-Mailer: b4 0.14.2 X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::28 X-SA-Exim-Mail-From: m.felsch@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Shuffle the allocation of script_addrs and make use of devm_kzalloc() to drop the local error handling as well as the kfree() during the remove. Reviewed-by: Frank Li Signed-off-by: Marco Felsch Reviewed-by: Peng Fan --- drivers/dma/imx-sdma.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c index b0def2bde77fe53b0805bddc0c5d6116c9cefcbe..d6239900ba12063bdb7d807db1b= dbdc2b446a94c 100644 --- a/drivers/dma/imx-sdma.c +++ b/drivers/dma/imx-sdma.c @@ -2283,6 +2283,10 @@ static int sdma_probe(struct platform_device *pdev) if (!sdma) return -ENOMEM; =20 + sdma->script_addrs =3D devm_kzalloc(dev, sizeof(*sdma->script_addrs), GFP= _KERNEL); + if (!sdma->script_addrs) + return -ENOMEM; + spin_lock_init(&sdma->channel_0_lock); =20 sdma->dev =3D dev; @@ -2319,12 +2323,6 @@ static int sdma_probe(struct platform_device *pdev) =20 sdma->irq =3D irq; =20 - sdma->script_addrs =3D kzalloc(sizeof(*sdma->script_addrs), GFP_KERNEL); - if (!sdma->script_addrs) { - ret =3D -ENOMEM; - goto err_irq; - } - /* initially no scripts available */ saddr_arr =3D (s32 *)sdma->script_addrs; for (i =3D 0; i < sizeof(*sdma->script_addrs) / sizeof(s32); i++) @@ -2362,11 +2360,11 @@ static int sdma_probe(struct platform_device *pdev) =20 ret =3D sdma_init(sdma); if (ret) - goto err_init; + goto err_irq; =20 ret =3D sdma_event_remap(sdma); if (ret) - goto err_init; + goto err_irq; =20 if (sdma->drvdata->script_addrs) sdma_add_scripts(sdma, sdma->drvdata->script_addrs); @@ -2395,7 +2393,7 @@ static int sdma_probe(struct platform_device *pdev) ret =3D dma_async_device_register(&sdma->dma_device); if (ret) { dev_err(dev, "unable to register\n"); - goto err_init; + goto err_irq; } =20 ret =3D of_dma_controller_register(np, sdma_xlate, sdma); @@ -2423,8 +2421,6 @@ static int sdma_probe(struct platform_device *pdev) =20 err_register: dma_async_device_unregister(&sdma->dma_device); -err_init: - kfree(sdma->script_addrs); err_irq: clk_unprepare(sdma->clk_ahb); err_clk: @@ -2440,7 +2436,6 @@ static void sdma_remove(struct platform_device *pdev) of_dma_controller_free(sdma->dev->of_node); devm_free_irq(&pdev->dev, sdma->irq, sdma); dma_async_device_unregister(&sdma->dma_device); - kfree(sdma->script_addrs); clk_unprepare(sdma->clk_ahb); clk_unprepare(sdma->clk_ipg); /* Kill the tasklet */ --=20 2.47.3