linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] spi: microchip-core: fix passing zero to PTR_ERR warning
@ 2022-06-15 14:20 Conor Dooley
  2022-06-16 11:42 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Conor Dooley @ 2022-06-15 14:20 UTC (permalink / raw)
  To: Mark Brown
  Cc: Daire McNamara, Lewis Hanly, Conor Dooley, linux-riscv,
	linux-spi, linux-kernel, Dan Carpenter

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: 9ac8d17694b6 ("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>
---
v2: drop the NULL check entirely rather than returning -ENXIO if NULL
---
 drivers/spi/spi-microchip-core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-microchip-core.c b/drivers/spi/spi-microchip-core.c
index 5b2aee30fa04..d866a831104c 100644
--- a/drivers/spi/spi-microchip-core.c
+++ b/drivers/spi/spi-microchip-core.c
@@ -433,6 +433,8 @@ static int mchp_corespi_calculate_clkgen(struct mchp_corespi *spi,
 	unsigned long clk_hz, spi_hz, clk_gen;
 
 	clk_hz = clk_get_rate(spi->clk);
+	if (!clk_hz)
+		return -EINVAL;
 	spi_hz = min(target_hz, clk_hz);
 
 	/*
@@ -553,7 +555,7 @@ static int mchp_corespi_probe(struct platform_device *pdev)
 	}
 
 	spi->clk = devm_clk_get(&pdev->dev, NULL);
-	if (!spi->clk || IS_ERR(spi->clk)) {
+	if (IS_ERR(spi->clk)) {
 		ret = PTR_ERR(spi->clk);
 		dev_err(&pdev->dev, "could not get clk: %d\n", ret);
 		goto error_release_master;
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] spi: microchip-core: fix passing zero to PTR_ERR warning
  2022-06-15 14:20 [PATCH v2] spi: microchip-core: fix passing zero to PTR_ERR warning Conor Dooley
@ 2022-06-16 11:42 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2022-06-16 11:42 UTC (permalink / raw)
  To: conor.dooley
  Cc: linux-riscv, linux-spi, dan.carpenter, daire.mcnamara,
	lewis.hanly, linux-kernel

On Wed, 15 Jun 2022 15:20:29 +0100, Conor Dooley wrote:
> 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.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/1] spi: microchip-core: fix passing zero to PTR_ERR warning
      commit: 2081ad1467469b649fc9f9226b235977a7bf9402

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-16 11:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-15 14:20 [PATCH v2] spi: microchip-core: fix passing zero to PTR_ERR warning Conor Dooley
2022-06-16 11:42 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).