From nobody Tue Apr 7 14:39:55 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (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 59C77349AE1; Fri, 13 Mar 2026 06:09:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773382158; cv=none; b=Upd1yxSQdD4B7TOqBsVwmDBdp/fMYJx46++hLrJUB0CT/xQ/sYZgGzO0SHmhr19qBBIGWyYvLnSVRGbswd+0CYcR+uuaesXwJpP/UVmwD1mhiwiMXvEUBiRNhjx/RgvI9bi2UbStrXYZADdl5GM47bKGD0gu5OWSbWwGmbyB7mg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773382158; c=relaxed/simple; bh=syMl89U/VOtX46W15gQB3Kk1cxli0i/sXw5iif4T+hc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QyZsgRgwj6L/ZfK4Cmch0XFMHAHBZW1/Frz8eJHPo49tvPmNXEdYwSoQaedXdVY868NLfEp6J6kJsMJ3+uRtjdKxMeWK6VygxnKeV3unzCcO8cDDfPJhoceLEumUUhZU+kdwz6T2QyFGYrLyzkRzPvsSgWHanLTQwn90Sh9PAjs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 22b22a4c1ea311f1a21c59e7364eecb8-20260313 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.11,REQID:827087d2-ade9-479e-8493-7e361b886a57,IP:0,U RL:0,TC:0,Content:-25,EDM:25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:0 X-CID-META: VersionHash:89c9d04,CLOUDID:664ae7357f27d91fc3eac90dfa8f844d,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:81|82|102|850|898,TC:nil,Content:0|15|50 ,EDM:5,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OS A:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 22b22a4c1ea311f1a21c59e7364eecb8-20260313 X-User: xiaopei01@kylinos.cn Received: from localhost.localdomain [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 718982642; Fri, 13 Mar 2026 14:09:03 +0800 From: Pei Xiao To: broonie@kernel.org, linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, openbmc@lists.ozlabs.org, linux-rockchip@lists.infradead.org, linux-riscv@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com Cc: Pei Xiao Subject: [PATCH v2 13/17] spi: stm32: Use helper function devm_clk_get_enabled() Date: Fri, 13 Mar 2026 14:08:29 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: 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 Content-Type: text/plain; charset="utf-8" devm_clk_get() and clk_prepare_enable() can now be replaced by devm_clk_get_enabled() when driver enables the clocks. Moreover, it is no longer necessary to unprepare and disable the clocks explicitly. Simplify code. Signed-off-by: Pei Xiao --- drivers/spi/spi-stm32.c | 58 +++++++++++++---------------------------- 1 file changed, 18 insertions(+), 40 deletions(-) diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c index 8a7f5a10d4af..9f82540a582c 100644 --- a/drivers/spi/spi-stm32.c +++ b/drivers/spi/spi-stm32.c @@ -2360,25 +2360,21 @@ static int stm32_spi_probe(struct platform_device *= pdev) int ret; =20 cfg =3D of_device_get_match_data(&pdev->dev); - if (!cfg) { - dev_err(&pdev->dev, "Failed to get match data for platform\n"); - return -ENODEV; - } + if (!cfg) + return dev_err_probe(&pdev->dev, -ENODEV, + "Failed to get match data for platform\n"); =20 device_mode =3D of_property_read_bool(np, "spi-slave"); - if (!cfg->has_device_mode && device_mode) { - dev_err(&pdev->dev, "spi-slave not supported\n"); - return -EPERM; - } + if (!cfg->has_device_mode && device_mode) + return dev_err_probe(&pdev->dev, -EPERM, "spi-slave not supported\n"); =20 if (device_mode) ctrl =3D devm_spi_alloc_target(&pdev->dev, sizeof(struct stm32_spi)); else ctrl =3D devm_spi_alloc_host(&pdev->dev, sizeof(struct stm32_spi)); - if (!ctrl) { - dev_err(&pdev->dev, "spi controller allocation failed\n"); - return -ENOMEM; - } + if (!ctrl) + return dev_err_probe(&pdev->dev, -ENOMEM, + "spi controller allocation failed\n"); platform_set_drvdata(pdev, ctrl); =20 spi =3D spi_controller_get_devdata(ctrl); @@ -2409,32 +2405,19 @@ static int stm32_spi_probe(struct platform_device *= pdev) return ret; } =20 - spi->clk =3D devm_clk_get(&pdev->dev, NULL); - if (IS_ERR(spi->clk)) { - ret =3D PTR_ERR(spi->clk); - dev_err(&pdev->dev, "clk get failed: %d\n", ret); - return ret; - } + spi->clk =3D devm_clk_get_enabled(&pdev->dev, NULL); + if (IS_ERR(spi->clk)) + return dev_err_probe(&pdev->dev, PTR_ERR(spi->clk), "clk enabled failed\= n"); =20 - ret =3D clk_prepare_enable(spi->clk); - if (ret) { - dev_err(&pdev->dev, "clk enable failed: %d\n", ret); - return ret; - } spi->clk_rate =3D clk_get_rate(spi->clk); - if (!spi->clk_rate) { - dev_err(&pdev->dev, "clk rate =3D 0\n"); - ret =3D -EINVAL; - goto err_clk_disable; - } + if (!spi->clk_rate) + return dev_err_probe(&pdev->dev, -EINVAL, "clk rate =3D 0\n"); =20 rst =3D devm_reset_control_get_optional_exclusive(&pdev->dev, NULL); if (rst) { - if (IS_ERR(rst)) { + if (IS_ERR(rst)) ret =3D dev_err_probe(&pdev->dev, PTR_ERR(rst), "failed to get reset\n"); - goto err_clk_disable; - } =20 reset_control_assert(rst); udelay(2); @@ -2461,11 +2444,9 @@ static int stm32_spi_probe(struct platform_device *p= dev) dev_dbg(spi->dev, "one message max size %d\n", spi->t_size_max); =20 ret =3D spi->cfg->config(spi); - if (ret) { - dev_err(&pdev->dev, "controller configuration failed: %d\n", - ret); - goto err_clk_disable; - } + if (ret) + return dev_err_probe(&pdev->dev, ret, + "controller configuration failed: %d\n", ret); =20 ctrl->auto_runtime_pm =3D true; ctrl->bus_num =3D pdev->id; @@ -2490,8 +2471,7 @@ static int stm32_spi_probe(struct platform_device *pd= ev) dev_info(&pdev->dev, "tx dma disabled\n"); spi->dma_tx =3D NULL; } else { - dev_err_probe(&pdev->dev, ret, "failed to request tx dma channel\n"); - goto err_clk_disable; + return dev_err_probe(&pdev->dev, ret, "failed to request tx dma channel= \n"); } } else { ctrl->dma_tx =3D spi->dma_tx; @@ -2579,8 +2559,6 @@ static int stm32_spi_probe(struct platform_device *pd= ev) err_dma_tx_release: if (spi->dma_tx) dma_release_channel(spi->dma_tx); -err_clk_disable: - clk_disable_unprepare(spi->clk); =20 return ret; } --=20 2.25.1