spi: omap2-mcspi: Correctly handle devm_clk_get_optional() errors
Mark Brown
maintainerPATCH 1/1 spi: omap2-mcspi: Correctly handle devm_clk_get_optional() errors
devm_clk_get_optional() returns NULL for missing clocks and a PTR_ERR() if there is a clock but we fail to get it, but currently we only handle the latter case and do so as though the clock was missing. If we get an error back we should handle that as an error since the clock exists but we failed to get it, if we get NULL then the clock doesn't exist and we should handle that.
--- drivers/spi/spi-omap2-mcspi.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/spi/spi-omap2-mcspi.c +8 -3
@@ -1561,10 +1561,15 @@ static int omap2_mcspi_probe(struct platform_device *pdev) } mcspi->ref_clk =devm_clk_get_optional_enabled (&pdev->dev,NULL ); -if (IS_ERR (mcspi->ref_clk)) - mcspi->ref_clk_hz =OMAP2_MCSPI_MAX_FREQ ; -else +if (IS_ERR (mcspi->ref_clk)) { + status =PTR_ERR (mcspi->ref_clk); +dev_err_probe (&pdev->dev, status,"Failed to get ref_clk" ); + goto free_ctlr; + } +if (mcspi->ref_clk) mcspi->ref_clk_hz =clk_get_rate (mcspi->ref_clk); +else + mcspi->ref_clk_hz =OMAP2_MCSPI_MAX_FREQ ; ctlr->max_speed_hz = mcspi->ref_clk_hz; ctlr->min_speed_hz = mcspi->ref_clk_hz >>15 ;
---
base-commit: 9d89551994a430b50c4fffcb1e617a057fa76e20
change-id: 20250116-spi-fix-omap2-optional-84aa541869e6
Best regards,
Signature · 1 line
Mark Brown <[email protected]>
Quoted 7 lines · Mark Brown
devm_clk_get_optional()returns NULL for missing clocks and aPTR_ERR()if there is a clock but we fail to get it, but currently we only handle the latter case and do so as though the clock was missing. If we get an error back we should handle that as an error since the clock exists but we failed to get it, if we get NULL then the clock doesn't exist and we should handle that.
Hi Mark.
I have now tested the patch on our board and everything now works as expected. Thanks!
Quoted 40 lines
Fixes 4c6ac5446d06 ("spi: omap2-mcspi: Fix the IS_ERR() bug for devm_clk_get_optional_enabled()")Reported-by Lars Pedersen <[email protected]>Signed-off-by Mark Brown <[email protected]>--- drivers/spi/spi-omap2-mcspi.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)drivers/spi/spi-omap2-mcspi.c +8
-4@@ -1561,10 +1561,15 @@ static int omap2_mcspi_probe(struct platform_device *pdev) } mcspi->ref_clk =devm_clk_get_optional_enabled (&pdev->dev,NULL ); -if (IS_ERR (mcspi->ref_clk)) - mcspi->ref_clk_hz =OMAP2_MCSPI_MAX_FREQ ; -else +if (IS_ERR (mcspi->ref_clk)) { + status =PTR_ERR (mcspi->ref_clk); +dev_err_probe (&pdev->dev, status,"Failed to get ref_clk" ); + goto free_ctlr; + } +if (mcspi->ref_clk) mcspi->ref_clk_hz =clk_get_rate (mcspi->ref_clk); +else + mcspi->ref_clk_hz =OMAP2_MCSPI_MAX_FREQ ; ctlr->max_speed_hz = mcspi->ref_clk_hz; ctlr->min_speed_hz = mcspi->ref_clk_hz >>15 ; ---base-commit:
9d89551994a430b50c4fffcb1e617a057fa76e20
change-id: 20250116-spi-fix-omap2-optional-84aa541869e6Best regards,
--
Mark Brown <[email protected]>
Mark Brown
maintainerQuoted 8 lines · Mark Brown
devm_clk_get_optional()returns NULL for missing clocks and aPTR_ERR()if there is a clock but we fail to get it, but currently we only handle the latter case and do so as though the clock was missing. If we get an error back we should handle that as an error since the clock exists but we failed to get it, if we get NULL then the clock doesn't exist and we should handle that.[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
Thanks!
[1/1] spi: omap2-mcspi: Correctly handle devm_clk_get_optional() errors
commit: a07eb4f67ed085f32002a1af2b6073546d67de3f
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark