Skip to contentSkip to conversation

spi: microchip-core: fix passing zero to PTR_ERR warning

PATCH Superseded Conor Dooley 2 participants 7 messages Jun 15, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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'

Fix the warning by explicitly returning an error if devm_clk_get() returns NULL.

Fixes 9ac8d17694b6 ("spi: add support for microchip fpga spi controllers")
---
 drivers/spi/spi-microchip-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi-microchip-core.c +1 -1
index 5b2aee30fa04..d44663cca071 100644
@@ -554,7 +554,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)) {
-		ret = PTR_ERR(spi->clk);
+		ret = !spi->clk ? -ENXIO : PTR_ERR(spi->clk);
 		dev_err(&pdev->dev, "could not get clk: %d\n", ret);
 		goto error_release_master;
 	}
Signature · 1 line
2.36.1
maintainer
#1 lore raw

drivers/spi/spi-microchip-core.c static int mchp_corespi_probe(struct platform_device *pdev) · line 557

Quoted 2 lines · Conor Dooley
drivers/spi/spi-microchip-core.c +1 -1
-		ret = PTR_ERR(spi->clk);
+		ret = !spi->clk ? -ENXIO : PTR_ERR(spi->clk);

I think you're looking for PTR_ERR_OR_ZERO() here?

#2 lore raw
Quoted 8 lines · Mark Brown

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

drivers/spi/spi-microchip-core.c static int mchp_corespi_probe(struct platform_device *pdev) · line 557

Quoted 2 lines · Conor Dooley
drivers/spi/spi-microchip-core.c +1 -1
-             ret = PTR_ERR(spi->clk);
+             ret = !spi->clk ? -ENXIO : PTR_ERR(spi->clk);

I think you're looking for PTR_ERR_OR_ZERO() here?

Maybe I don't understand, so let me explain what I think you're suggesting & maybe you can correct me:

Review

Quoted 2 lines
(quoted diff) +1 -1
-             ret = PTR_ERR(spi->clk);
+             ret = PTR_ERR_OR_ZERO(spi->clk);

But if spi->clk is NULL, this will return 0 from the probe rather than returning an error?
If that's not what you meant, lmk
Thanks,
Conor.

Quoted 6 lines

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

maintainer
#3 lore raw
Quoted 12 lines · On Wed, Jun 15, 2022 at 11:57:37AM +0000, [email protected] wrote:
Quoted 7 lines · Mark Brown

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

drivers/spi/spi-microchip-core.c static int mchp_corespi_probe(struct platform_device *pdev) · line 557

Quoted 2 lines · Conor Dooley
drivers/spi/spi-microchip-core.c +1 -1
-             ret = PTR_ERR(spi->clk);
+             ret = !spi->clk ? -ENXIO : PTR_ERR(spi->clk);

I think you're looking for PTR_ERR_OR_ZERO() here?

Maybe I don't understand, so let me explain what I think you're suggesting & maybe you can correct me:

Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +1 -1
-             ret = PTR_ERR(spi->clk);
+             ret = PTR_ERR_OR_ZERO(spi->clk);

But if spi->clk is NULL, this will return 0 from the probe rather than returning an error?
If that's not what you meant, lmk

Oh, hang on - what error conditions can clk_get() return 0 in? The documentation doesn't mention any...

#4 lore raw
Quoted 18 lines · Mark Brown

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 14 lines · On Wed, Jun 15, 2022 at 11:57:37AM +0000, [email protected] wrote:
Quoted 7 lines · Mark Brown

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

drivers/spi/spi-microchip-core.c static int mchp_corespi_probe(struct platform_device *pdev) · line 557

Quoted 2 lines · Conor Dooley
drivers/spi/spi-microchip-core.c +1 -1
-             ret = PTR_ERR(spi->clk);
+             ret = !spi->clk ? -ENXIO : PTR_ERR(spi->clk);

I think you're looking for PTR_ERR_OR_ZERO() here?

Maybe I don't understand, so let me explain what I think you're suggesting & maybe you can correct me:

Quoted 2 lines
(quoted diff) +1 -1
-             ret = PTR_ERR(spi->clk);
+             ret = PTR_ERR_OR_ZERO(spi->clk);
Quoted 6 lines
Quoted 3 lines

But if spi->clk is NULL, this will return 0 from the probe rather than returning an error?
If that's not what you meant, lmk

Oh, hang on - what error conditions can clk_get() return 0 in? The documentation doesn't mention any...

If !CONFIG_HAVE_CLK, (without which it won't boot on the coreplex) but I don't think I can be sure that CONFIG_HAVE_CLK will /always/ be enabled for other uses of the FPGA.

maintainer
#5 lore raw
Quoted 6 lines · On Wed, Jun 15, 2022 at 12:42:27PM +0000, [email protected] wrote:
Quoted 3 lines · Mark Brown
Quoted 3 lines

But if spi->clk is NULL, this will return 0 from the probe rather than returning an error?
If that's not what you meant, lmk

Quoted 6 lines
Quoted 2 lines

Oh, hang on - what error conditions can clk_get() return 0 in? The documentation doesn't mention any...

If !CONFIG_HAVE_CLK, (without which it won't boot on the coreplex) but I don't think I can be sure that CONFIG_HAVE_CLK will /always/ be enabled for other uses of the FPGA.

That's not an error, that's returning NULL as a dummy clock. The expectation is that the driver will proceed as though it has a clock.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#6 lore raw
Quoted 10 lines · Mark Brown
Quoted 8 lines · On Wed, Jun 15, 2022 at 12:42:27PM +0000, [email protected] wrote:
Quoted 6 lines · Mark Brown
Quoted 3 lines

But if spi->clk is NULL, this will return 0 from the probe rather than returning an error?
If that's not what you meant, lmk

Oh, hang on - what error conditions can clk_get() return 0 in? The documentation doesn't mention any...

Quoted 6 lines
Quoted 3 lines

If !CONFIG_HAVE_CLK, (without which it won't boot on the coreplex) but I don't think I can be sure that CONFIG_HAVE_CLK will /always/ be enabled for other uses of the FPGA.

That's not an error, that's returning NULL as a dummy clock. The expectation is that the driver will proceed as though it has a clock.

Ahh, cool. I guess I'll just drop the null check entirely so & guard against a div zero when I actually go to use the clock. Thanks!
Conor