linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: rockchip: i2s: simplify clock handling and error cleanup in probe
@ 2025-07-12 13:54 Troy Mitchell
  2025-07-12 17:56 ` kernel test robot
  0 siblings, 1 reply; 2+ messages in thread
From: Troy Mitchell @ 2025-07-12 13:54 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Heiko Stuebner
  Cc: linux-sound, linux-arm-kernel, linux-rockchip, linux-kernel,
	Troy Mitchell

Replace devm_clk_get + clk_prepare_enable with devm_clk_get_enabled
to simplify clock acquisition and enabling.

Use dev_err_probe for concise error logging and return handling,
reducing boilerplate code and improving readability.

Signed-off-by: Troy Mitchell <troy.mitchell@linux.dev>
---
 sound/soc/rockchip/rockchip_i2s.c | 51 +++++++++++----------------------------
 1 file changed, 14 insertions(+), 37 deletions(-)

diff --git a/sound/soc/rockchip/rockchip_i2s.c b/sound/soc/rockchip/rockchip_i2s.c
index 0a0a95b4f5204701b52ca924683d51c29992015d..bd1b5771ae7c6f91e57c0fe3579a3d9974839f8e 100644
--- a/sound/soc/rockchip/rockchip_i2s.c
+++ b/sound/soc/rockchip/rockchip_i2s.c
@@ -31,7 +31,6 @@ struct rk_i2s_pins {
 struct rk_i2s_dev {
 	struct device *dev;
 
-	struct clk *hclk;
 	struct clk *mclk;
 
 	struct snd_dmaengine_dai_dma_data capture_dma_data;
@@ -739,6 +738,7 @@ static int rockchip_i2s_probe(struct platform_device *pdev)
 	struct snd_soc_dai_driver *dai;
 	struct resource *res;
 	void __iomem *regs;
+	struct clk *clk;
 	int ret;
 
 	i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL);
@@ -757,38 +757,23 @@ static int rockchip_i2s_probe(struct platform_device *pdev)
 	}
 
 	/* try to prepare related clocks */
-	i2s->hclk = devm_clk_get(&pdev->dev, "i2s_hclk");
-	if (IS_ERR(i2s->hclk)) {
-		dev_err(&pdev->dev, "Can't retrieve i2s bus clock\n");
-		return PTR_ERR(i2s->hclk);
-	}
-	ret = clk_prepare_enable(i2s->hclk);
-	if (ret) {
-		dev_err(i2s->dev, "hclock enable failed %d\n", ret);
-		return ret;
-	}
+	clk = devm_clk_get_enabled(&pdev->dev, "i2s_hclk");
+	if (IS_ERR(clk))
+		return dev_err_probe(&pdev->dev, PTR_ERR(clk), "hclock enable failed");
 
 	i2s->mclk = devm_clk_get(&pdev->dev, "i2s_clk");
-	if (IS_ERR(i2s->mclk)) {
-		dev_err(&pdev->dev, "Can't retrieve i2s master clock\n");
-		ret = PTR_ERR(i2s->mclk);
-		goto err_clk;
-	}
+	if (IS_ERR(i2s->mclk))
+		return dev_err_probe(&pdev->dev, PTR_ERR(i2s->mclk),
+				     "Can't retrieve i2s master clock");
 
 	regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
-	if (IS_ERR(regs)) {
-		ret = PTR_ERR(regs);
-		goto err_clk;
-	}
+	if (IS_ERR(regs))
+		dev_err_probe(&pdev->dev, PTR_ERR(regs), "Can't ioremap registers");
 
 	i2s->regmap = devm_regmap_init_mmio(&pdev->dev, regs,
 					    &rockchip_i2s_regmap_config);
-	if (IS_ERR(i2s->regmap)) {
-		dev_err(&pdev->dev,
-			"Failed to initialise managed register map\n");
-		ret = PTR_ERR(i2s->regmap);
-		goto err_clk;
-	}
+	if (IS_ERR(i2s->regmap))
+		return dev_err_probe(&pdev->dev, ret, "Failed to initialise managed register map");
 
 	i2s->bclk_ratio = 64;
 	i2s->pinctrl = devm_pinctrl_get(&pdev->dev);
@@ -796,11 +781,9 @@ static int rockchip_i2s_probe(struct platform_device *pdev)
 		i2s->bclk_on = pinctrl_lookup_state(i2s->pinctrl, "bclk_on");
 		if (!IS_ERR_OR_NULL(i2s->bclk_on)) {
 			i2s->bclk_off = pinctrl_lookup_state(i2s->pinctrl, "bclk_off");
-			if (IS_ERR_OR_NULL(i2s->bclk_off)) {
-				dev_err(&pdev->dev, "failed to find i2s bclk_off\n");
-				ret = -EINVAL;
-				goto err_clk;
-			}
+			if (IS_ERR_OR_NULL(i2s->bclk_off))
+				return dev_err_probe(&pdev->dev, -EINVAL,
+						     "failed to find i2s bclk_off");
 		}
 	} else {
 		dev_dbg(&pdev->dev, "failed to find i2s pinctrl\n");
@@ -843,20 +826,14 @@ static int rockchip_i2s_probe(struct platform_device *pdev)
 		i2s_runtime_suspend(&pdev->dev);
 err_pm_disable:
 	pm_runtime_disable(&pdev->dev);
-err_clk:
-	clk_disable_unprepare(i2s->hclk);
 	return ret;
 }
 
 static void rockchip_i2s_remove(struct platform_device *pdev)
 {
-	struct rk_i2s_dev *i2s = dev_get_drvdata(&pdev->dev);
-
 	pm_runtime_disable(&pdev->dev);
 	if (!pm_runtime_status_suspended(&pdev->dev))
 		i2s_runtime_suspend(&pdev->dev);
-
-	clk_disable_unprepare(i2s->hclk);
 }
 
 static const struct dev_pm_ops rockchip_i2s_pm_ops = {

---
base-commit: 733923397fd95405a48f165c9b1fbc8c4b0a4681
change-id: 20250712-rockchip-i2s-simplify-clk-e070457fdb31

Best regards,
-- 
Troy Mitchell <troy.mitchell@linux.dev>


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ASoC: rockchip: i2s: simplify clock handling and error cleanup in probe
  2025-07-12 13:54 [PATCH] ASoC: rockchip: i2s: simplify clock handling and error cleanup in probe Troy Mitchell
@ 2025-07-12 17:56 ` kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2025-07-12 17:56 UTC (permalink / raw)
  To: Troy Mitchell, Liam Girdwood, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, Heiko Stuebner
  Cc: llvm, oe-kbuild-all, linux-sound, linux-arm-kernel,
	linux-rockchip, linux-kernel, Troy Mitchell

Hi Troy,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 733923397fd95405a48f165c9b1fbc8c4b0a4681]

url:    https://github.com/intel-lab-lkp/linux/commits/Troy-Mitchell/ASoC-rockchip-i2s-simplify-clock-handling-and-error-cleanup-in-probe/20250712-215647
base:   733923397fd95405a48f165c9b1fbc8c4b0a4681
patch link:    https://lore.kernel.org/r/20250712-rockchip-i2s-simplify-clk-v1-1-3b23fd1b3e26%40linux.dev
patch subject: [PATCH] ASoC: rockchip: i2s: simplify clock handling and error cleanup in probe
config: x86_64-buildonly-randconfig-003-20250712 (https://download.01.org/0day-ci/archive/20250713/202507130140.HxI37WQ3-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250713/202507130140.HxI37WQ3-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202507130140.HxI37WQ3-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> sound/soc/rockchip/rockchip_i2s.c:776:36: warning: variable 'ret' is uninitialized when used here [-Wuninitialized]
     776 |                 return dev_err_probe(&pdev->dev, ret, "Failed to initialise managed register map");
         |                                                  ^~~
   sound/soc/rockchip/rockchip_i2s.c:742:9: note: initialize the variable 'ret' to silence this warning
     742 |         int ret;
         |                ^
         |                 = 0
   1 warning generated.


vim +/ret +776 sound/soc/rockchip/rockchip_i2s.c

   733	
   734	static int rockchip_i2s_probe(struct platform_device *pdev)
   735	{
   736		struct device_node *node = pdev->dev.of_node;
   737		struct rk_i2s_dev *i2s;
   738		struct snd_soc_dai_driver *dai;
   739		struct resource *res;
   740		void __iomem *regs;
   741		struct clk *clk;
   742		int ret;
   743	
   744		i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL);
   745		if (!i2s)
   746			return -ENOMEM;
   747	
   748		spin_lock_init(&i2s->lock);
   749		i2s->dev = &pdev->dev;
   750	
   751		i2s->grf = syscon_regmap_lookup_by_phandle(node, "rockchip,grf");
   752		if (!IS_ERR(i2s->grf)) {
   753			i2s->pins = device_get_match_data(&pdev->dev);
   754			if (!i2s->pins)
   755				return -EINVAL;
   756	
   757		}
   758	
   759		/* try to prepare related clocks */
   760		clk = devm_clk_get_enabled(&pdev->dev, "i2s_hclk");
   761		if (IS_ERR(clk))
   762			return dev_err_probe(&pdev->dev, PTR_ERR(clk), "hclock enable failed");
   763	
   764		i2s->mclk = devm_clk_get(&pdev->dev, "i2s_clk");
   765		if (IS_ERR(i2s->mclk))
   766			return dev_err_probe(&pdev->dev, PTR_ERR(i2s->mclk),
   767					     "Can't retrieve i2s master clock");
   768	
   769		regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
   770		if (IS_ERR(regs))
   771			dev_err_probe(&pdev->dev, PTR_ERR(regs), "Can't ioremap registers");
   772	
   773		i2s->regmap = devm_regmap_init_mmio(&pdev->dev, regs,
   774						    &rockchip_i2s_regmap_config);
   775		if (IS_ERR(i2s->regmap))
 > 776			return dev_err_probe(&pdev->dev, ret, "Failed to initialise managed register map");
   777	
   778		i2s->bclk_ratio = 64;
   779		i2s->pinctrl = devm_pinctrl_get(&pdev->dev);
   780		if (!IS_ERR(i2s->pinctrl)) {
   781			i2s->bclk_on = pinctrl_lookup_state(i2s->pinctrl, "bclk_on");
   782			if (!IS_ERR_OR_NULL(i2s->bclk_on)) {
   783				i2s->bclk_off = pinctrl_lookup_state(i2s->pinctrl, "bclk_off");
   784				if (IS_ERR_OR_NULL(i2s->bclk_off))
   785					return dev_err_probe(&pdev->dev, -EINVAL,
   786							     "failed to find i2s bclk_off");
   787			}
   788		} else {
   789			dev_dbg(&pdev->dev, "failed to find i2s pinctrl\n");
   790		}
   791	
   792		i2s_pinctrl_select_bclk_off(i2s);
   793	
   794		dev_set_drvdata(&pdev->dev, i2s);
   795	
   796		pm_runtime_enable(&pdev->dev);
   797		if (!pm_runtime_enabled(&pdev->dev)) {
   798			ret = i2s_runtime_resume(&pdev->dev);
   799			if (ret)
   800				goto err_pm_disable;
   801		}
   802	
   803		ret = rockchip_i2s_init_dai(i2s, res, &dai);
   804		if (ret)
   805			goto err_pm_disable;
   806	
   807		ret = devm_snd_soc_register_component(&pdev->dev,
   808						      &rockchip_i2s_component,
   809						      dai, 1);
   810	
   811		if (ret) {
   812			dev_err(&pdev->dev, "Could not register DAI\n");
   813			goto err_suspend;
   814		}
   815	
   816		ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0);
   817		if (ret) {
   818			dev_err(&pdev->dev, "Could not register PCM\n");
   819			goto err_suspend;
   820		}
   821	
   822		return 0;
   823	
   824	err_suspend:
   825		if (!pm_runtime_status_suspended(&pdev->dev))
   826			i2s_runtime_suspend(&pdev->dev);
   827	err_pm_disable:
   828		pm_runtime_disable(&pdev->dev);
   829		return ret;
   830	}
   831	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-07-12 17:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-12 13:54 [PATCH] ASoC: rockchip: i2s: simplify clock handling and error cleanup in probe Troy Mitchell
2025-07-12 17:56 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).