From nobody Mon Apr 6 21:55:45 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 A2AF42F0680; Wed, 18 Mar 2026 02:40:29 +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=1773801631; cv=none; b=YcsYM9/qJB7MuwlQ9bGZaFEq2xdNx652pLAdf/lYzVFBydzJW2Rg6Yl4u599uk5a9zjNXePpATGQCunzz0sw9KoR0gF0Mjswkk++hkqeKr/CtF3JdtAs0/TjAQG5JhnJqrGBIggAFBVW/1mWkBrPWdl+dsHwNoR4TOuup6NcfqE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773801631; c=relaxed/simple; bh=PA0Aa/yo/ydOf6x5Zu7oOW3WJKcsq6liviB0MUtAb1M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DqXXC7FuygR2rSld6XI9DbYaj7ai+0ihsKv58aV2IB36dIwGW7+AyZB/aHHbxQ+dqnl71iz9pPjVf70bmJaGGmKEE1nKFCGTgg4X+sAOKViRJGjKU424KrUpAHHsZmf3iezriqh+NzfHjhEpjyOfU+7i478i83CxKaAglD288qY= 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: cbf09958227311f1a21c59e7364eecb8-20260318 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.11,REQID:8a30965e-9f1a-4620-8640-3b754d2d0986,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:b0aa196b703edc31140b64ea06567652,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: cbf09958227311f1a21c59e7364eecb8-20260318 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 1231776879; Wed, 18 Mar 2026 10:40:16 +0800 From: Pei Xiao To: 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 v4 13/17] spi: stm32: Simplify clock handling with devm_clk_get_enabled() Date: Wed, 18 Mar 2026 10:40:03 +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" Replace devm_clk_get() followed by clk_prepare_enable() with devm_clk_get_enabled() for the clock. This removes the need for explicit clock enable and disable calls, as the managed API automatically handles clock disabling on device removal or probe failure. Remove the now-unnecessary clk_disable_unprepare() calls from the probe error paths and the remove callback. Also simplify error handling by using dev_err_probe(). Signed-off-by: Pei Xiao --- drivers/spi/spi-stm32.c | 61 ++++++++++++----------------------------- 1 file changed, 18 insertions(+), 43 deletions(-) diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c index 8a7f5a10d4af..ee5092bc5956 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; } @@ -2610,9 +2588,6 @@ static void stm32_spi_remove(struct platform_device *= pdev) gen_pool_free(spi->sram_pool, (unsigned long)spi->sram_rx_buf, spi->sram_rx_buf_size); =20 - clk_disable_unprepare(spi->clk); - - pinctrl_pm_select_sleep_state(&pdev->dev); } =20 --=20 2.25.1