Skip to content

Commit a07eb4f

Browse files
committed
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. Fixes: 4c6ac54 ("spi: omap2-mcspi: Fix the IS_ERR() bug for devm_clk_get_optional_enabled()") Reported-by: Lars Pedersen <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]> Tested-by: Lars Pedersen <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 78b435c commit a07eb4f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

drivers/spi/spi-omap2-mcspi.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,10 +1561,15 @@ static int omap2_mcspi_probe(struct platform_device *pdev)
15611561
}
15621562

15631563
mcspi->ref_clk = devm_clk_get_optional_enabled(&pdev->dev, NULL);
1564-
if (IS_ERR(mcspi->ref_clk))
1565-
mcspi->ref_clk_hz = OMAP2_MCSPI_MAX_FREQ;
1566-
else
1564+
if (IS_ERR(mcspi->ref_clk)) {
1565+
status = PTR_ERR(mcspi->ref_clk);
1566+
dev_err_probe(&pdev->dev, status, "Failed to get ref_clk");
1567+
goto free_ctlr;
1568+
}
1569+
if (mcspi->ref_clk)
15671570
mcspi->ref_clk_hz = clk_get_rate(mcspi->ref_clk);
1571+
else
1572+
mcspi->ref_clk_hz = OMAP2_MCSPI_MAX_FREQ;
15681573
ctlr->max_speed_hz = mcspi->ref_clk_hz;
15691574
ctlr->min_speed_hz = mcspi->ref_clk_hz >> 15;
15701575

0 commit comments

Comments
 (0)