Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

coresight: Appropriately disable trace bus clocks

Some CoreSight components have trace bus clocks 'atclk' and are enabled
using clk_prepare_enable(). These clocks are not disabled when modules
exit.

As atclk is optional, use devm_clk_get_optional_enabled() to manage it.
The benefit is the driver model layer can automatically disable and
release clocks.

Check the returned value with IS_ERR() to detect errors but leave the
NULL pointer case if the clock is not found. And remove the error
handling codes which are no longer needed.

Fixes: d1839e687773 ("coresight: etm: retrieve and handle atclk")
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
Reviewed-by: Yeoreum Yun <yeoreum.yun@arm.com>
Tested-by: James Clark <james.clark@linaro.org>
Signed-off-by: Leo Yan <leo.yan@arm.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Link: https://lore.kernel.org/r/20250731-arm_cs_fix_clock_v4-v6-5-1dfe10bb3f6f@arm.com

authored by

Leo Yan and committed by
Suzuki K Poulose
a8f2d480 1abc1b21

+34 -74
+4 -6
drivers/hwtracing/coresight/coresight-etb10.c
··· 730 730 if (!drvdata) 731 731 return -ENOMEM; 732 732 733 - drvdata->atclk = devm_clk_get(&adev->dev, "atclk"); /* optional */ 734 - if (!IS_ERR(drvdata->atclk)) { 735 - ret = clk_prepare_enable(drvdata->atclk); 736 - if (ret) 737 - return ret; 738 - } 733 + drvdata->atclk = devm_clk_get_optional_enabled(dev, "atclk"); 734 + if (IS_ERR(drvdata->atclk)) 735 + return PTR_ERR(drvdata->atclk); 736 + 739 737 dev_set_drvdata(dev, drvdata); 740 738 741 739 /* validity for the resource is already checked by the AMBA core */
+3 -6
drivers/hwtracing/coresight/coresight-etm3x-core.c
··· 832 832 833 833 spin_lock_init(&drvdata->spinlock); 834 834 835 - drvdata->atclk = devm_clk_get(&adev->dev, "atclk"); /* optional */ 836 - if (!IS_ERR(drvdata->atclk)) { 837 - ret = clk_prepare_enable(drvdata->atclk); 838 - if (ret) 839 - return ret; 840 - } 835 + drvdata->atclk = devm_clk_get_optional_enabled(dev, "atclk"); 836 + if (IS_ERR(drvdata->atclk)) 837 + return PTR_ERR(drvdata->atclk); 841 838 842 839 drvdata->cpu = coresight_get_cpu(dev); 843 840 if (drvdata->cpu < 0)
+11 -25
drivers/hwtracing/coresight/coresight-funnel.c
··· 213 213 214 214 static int funnel_probe(struct device *dev, struct resource *res) 215 215 { 216 - int ret; 217 216 void __iomem *base; 218 217 struct coresight_platform_data *pdata = NULL; 219 218 struct funnel_drvdata *drvdata; ··· 230 231 if (!drvdata) 231 232 return -ENOMEM; 232 233 233 - drvdata->atclk = devm_clk_get(dev, "atclk"); /* optional */ 234 - if (!IS_ERR(drvdata->atclk)) { 235 - ret = clk_prepare_enable(drvdata->atclk); 236 - if (ret) 237 - return ret; 238 - } 234 + drvdata->atclk = devm_clk_get_optional_enabled(dev, "atclk"); 235 + if (IS_ERR(drvdata->atclk)) 236 + return PTR_ERR(drvdata->atclk); 239 237 240 238 drvdata->pclk = coresight_get_enable_apb_pclk(dev); 241 239 if (IS_ERR(drvdata->pclk)) ··· 244 248 */ 245 249 if (res) { 246 250 base = devm_ioremap_resource(dev, res); 247 - if (IS_ERR(base)) { 248 - ret = PTR_ERR(base); 249 - goto out_disable_clk; 250 - } 251 + if (IS_ERR(base)) 252 + return PTR_ERR(base); 251 253 drvdata->base = base; 252 254 desc.groups = coresight_funnel_groups; 253 255 desc.access = CSDEV_ACCESS_IOMEM(base); ··· 255 261 dev_set_drvdata(dev, drvdata); 256 262 257 263 pdata = coresight_get_platform_data(dev); 258 - if (IS_ERR(pdata)) { 259 - ret = PTR_ERR(pdata); 260 - goto out_disable_clk; 261 - } 264 + if (IS_ERR(pdata)) 265 + return PTR_ERR(pdata); 266 + 262 267 dev->platform_data = pdata; 263 268 264 269 raw_spin_lock_init(&drvdata->spinlock); ··· 267 274 desc.pdata = pdata; 268 275 desc.dev = dev; 269 276 drvdata->csdev = coresight_register(&desc); 270 - if (IS_ERR(drvdata->csdev)) { 271 - ret = PTR_ERR(drvdata->csdev); 272 - goto out_disable_clk; 273 - } 277 + if (IS_ERR(drvdata->csdev)) 278 + return PTR_ERR(drvdata->csdev); 274 279 275 - ret = 0; 276 - 277 - out_disable_clk: 278 - if (ret && !IS_ERR_OR_NULL(drvdata->atclk)) 279 - clk_disable_unprepare(drvdata->atclk); 280 - return ret; 280 + return 0; 281 281 } 282 282 283 283 static int funnel_remove(struct device *dev)
+10 -24
drivers/hwtracing/coresight/coresight-replicator.c
··· 219 219 220 220 static int replicator_probe(struct device *dev, struct resource *res) 221 221 { 222 - int ret = 0; 223 222 struct coresight_platform_data *pdata = NULL; 224 223 struct replicator_drvdata *drvdata; 225 224 struct coresight_desc desc = { 0 }; ··· 237 238 if (!drvdata) 238 239 return -ENOMEM; 239 240 240 - drvdata->atclk = devm_clk_get(dev, "atclk"); /* optional */ 241 - if (!IS_ERR(drvdata->atclk)) { 242 - ret = clk_prepare_enable(drvdata->atclk); 243 - if (ret) 244 - return ret; 245 - } 241 + drvdata->atclk = devm_clk_get_optional_enabled(dev, "atclk"); 242 + if (IS_ERR(drvdata->atclk)) 243 + return PTR_ERR(drvdata->atclk); 246 244 247 245 drvdata->pclk = coresight_get_enable_apb_pclk(dev); 248 246 if (IS_ERR(drvdata->pclk)) ··· 251 255 */ 252 256 if (res) { 253 257 base = devm_ioremap_resource(dev, res); 254 - if (IS_ERR(base)) { 255 - ret = PTR_ERR(base); 256 - goto out_disable_clk; 257 - } 258 + if (IS_ERR(base)) 259 + return PTR_ERR(base); 258 260 drvdata->base = base; 259 261 desc.groups = replicator_groups; 260 262 desc.access = CSDEV_ACCESS_IOMEM(base); ··· 266 272 dev_set_drvdata(dev, drvdata); 267 273 268 274 pdata = coresight_get_platform_data(dev); 269 - if (IS_ERR(pdata)) { 270 - ret = PTR_ERR(pdata); 271 - goto out_disable_clk; 272 - } 275 + if (IS_ERR(pdata)) 276 + return PTR_ERR(pdata); 273 277 dev->platform_data = pdata; 274 278 275 279 raw_spin_lock_init(&drvdata->spinlock); ··· 278 286 desc.dev = dev; 279 287 280 288 drvdata->csdev = coresight_register(&desc); 281 - if (IS_ERR(drvdata->csdev)) { 282 - ret = PTR_ERR(drvdata->csdev); 283 - goto out_disable_clk; 284 - } 289 + if (IS_ERR(drvdata->csdev)) 290 + return PTR_ERR(drvdata->csdev); 285 291 286 292 replicator_reset(drvdata); 287 - 288 - out_disable_clk: 289 - if (ret && !IS_ERR_OR_NULL(drvdata->atclk)) 290 - clk_disable_unprepare(drvdata->atclk); 291 - return ret; 293 + return 0; 292 294 } 293 295 294 296 static int replicator_remove(struct device *dev)
+3 -6
drivers/hwtracing/coresight/coresight-stm.c
··· 842 842 if (!drvdata) 843 843 return -ENOMEM; 844 844 845 - drvdata->atclk = devm_clk_get(dev, "atclk"); /* optional */ 846 - if (!IS_ERR(drvdata->atclk)) { 847 - ret = clk_prepare_enable(drvdata->atclk); 848 - if (ret) 849 - return ret; 850 - } 845 + drvdata->atclk = devm_clk_get_optional_enabled(dev, "atclk"); 846 + if (IS_ERR(drvdata->atclk)) 847 + return PTR_ERR(drvdata->atclk); 851 848 852 849 drvdata->pclk = coresight_get_enable_apb_pclk(dev); 853 850 if (IS_ERR(drvdata->pclk))
+3 -7
drivers/hwtracing/coresight/coresight-tpiu.c
··· 128 128 129 129 static int __tpiu_probe(struct device *dev, struct resource *res) 130 130 { 131 - int ret; 132 131 void __iomem *base; 133 132 struct coresight_platform_data *pdata = NULL; 134 133 struct tpiu_drvdata *drvdata; ··· 143 144 144 145 spin_lock_init(&drvdata->spinlock); 145 146 146 - drvdata->atclk = devm_clk_get(dev, "atclk"); /* optional */ 147 - if (!IS_ERR(drvdata->atclk)) { 148 - ret = clk_prepare_enable(drvdata->atclk); 149 - if (ret) 150 - return ret; 151 - } 147 + drvdata->atclk = devm_clk_get_optional_enabled(dev, "atclk"); 148 + if (IS_ERR(drvdata->atclk)) 149 + return PTR_ERR(drvdata->atclk); 152 150 153 151 drvdata->pclk = coresight_get_enable_apb_pclk(dev); 154 152 if (IS_ERR(drvdata->pclk))