Skip to content

Commit 2081ad1

Browse files
ConchuODbroonie
authored andcommitted
spi: microchip-core: fix passing zero to PTR_ERR warning
It is possible that the error case for devm_clk_get() returns NULL, in which case zero will be passed to PTR_ERR() as shown by the Smatch static checker warning: drivers/spi/spi-microchip-core.c:557 mchp_corespi_probe() warn: passing zero to 'PTR_ERR' Remove the NULL check and carry on with a dummy clock in case of an error. To avoid a potential div zero, abort calculating clkgen if clk_get_rate(spi->clk) is zero. Fixes: 9ac8d17 ("spi: add support for microchip fpga spi controllers") Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Link: https://lore.kernel.org/linux-spi/20220615091633.GI2168@kadam/ Signed-off-by: Conor Dooley <conor.dooley@microchip.com> Link: https://lore.kernel.org/r/20220615142028.2991915-1-conor.dooley@microchip.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent d52b095 commit 2081ad1

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/spi/spi-microchip-core.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,8 @@ static int mchp_corespi_calculate_clkgen(struct mchp_corespi *spi,
433433
unsigned long clk_hz, spi_hz, clk_gen;
434434

435435
clk_hz = clk_get_rate(spi->clk);
436+
if (!clk_hz)
437+
return -EINVAL;
436438
spi_hz = min(target_hz, clk_hz);
437439

438440
/*
@@ -553,7 +555,7 @@ static int mchp_corespi_probe(struct platform_device *pdev)
553555
}
554556

555557
spi->clk = devm_clk_get(&pdev->dev, NULL);
556-
if (!spi->clk || IS_ERR(spi->clk)) {
558+
if (IS_ERR(spi->clk)) {
557559
ret = PTR_ERR(spi->clk);
558560
dev_err(&pdev->dev, "could not get clk: %d\n", ret);
559561
goto error_release_master;

0 commit comments

Comments
 (0)