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

misc: sram: Improve and simplify clk handling

The current code tries to get an associated clk, ignores any errors in the
process and if there is a clock enables it unconditionally for the whole
lifetime of the sram device.

Instead use an "optional" variant of devm_clk_get() which handles the case
where no clk is needed for the sram device and do proper error handling
for the remaining error cases. Also use an "enabled" variant of
devm_clk_get() to simplify. With that .probe() is the only function using
struct sram_dev::clk, so it can be replaced by a local variable.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Link: https://lore.kernel.org/r/20230302091251.1852454-1-u.kleine-koenig@pengutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Uwe Kleine-König and committed by
Greg Kroah-Hartman
9263271a 7ef1a2c1

+5 -13
+5 -12
drivers/misc/sram.c
··· 381 381 struct sram_dev *sram; 382 382 int ret; 383 383 struct resource *res; 384 + struct clk *clk; 384 385 385 386 config = of_device_get_match_data(&pdev->dev); 386 387 ··· 410 409 return PTR_ERR(sram->pool); 411 410 } 412 411 413 - sram->clk = devm_clk_get(sram->dev, NULL); 414 - if (IS_ERR(sram->clk)) 415 - sram->clk = NULL; 416 - else 417 - clk_prepare_enable(sram->clk); 412 + clk = devm_clk_get_optional_enabled(sram->dev, NULL); 413 + if (IS_ERR(clk)) 414 + return PTR_ERR(clk); 418 415 419 416 ret = sram_reserve_regions(sram, 420 417 platform_get_resource(pdev, IORESOURCE_MEM, 0)); 421 418 if (ret) 422 - goto err_disable_clk; 419 + return ret; 423 420 424 421 platform_set_drvdata(pdev, sram); 425 422 ··· 435 436 436 437 err_free_partitions: 437 438 sram_free_partitions(sram); 438 - err_disable_clk: 439 - if (sram->clk) 440 - clk_disable_unprepare(sram->clk); 441 439 442 440 return ret; 443 441 } ··· 447 451 448 452 if (sram->pool && gen_pool_avail(sram->pool) < gen_pool_size(sram->pool)) 449 453 dev_err(sram->dev, "removed while SRAM allocated\n"); 450 - 451 - if (sram->clk) 452 - clk_disable_unprepare(sram->clk); 453 454 454 455 return 0; 455 456 }
-1
drivers/misc/sram.h
··· 27 27 bool no_memory_wc; 28 28 29 29 struct gen_pool *pool; 30 - struct clk *clk; 31 30 32 31 struct sram_partition *partition; 33 32 u32 partitions;