spi: sifive: check return value for platform_get_resource()
Subsystems (3)
PATCH 1/1 spi: sifive: check return value for platform_get_resource()
platform_get_resource() may return NULL. If it is so, return -ENXIO
--- drivers/spi/spi-sifive.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/spi/spi-sifive.c +6 -0
@@ -308,6 +308,12 @@ static int sifive_spi_probe(struct platform_device *pdev)platform_set_drvdata (pdev, master); res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) { +dev_err (&pdev->dev,"no IOMEM resource found\n" ); + ret = -ENXIO ; + goto put_master; + } + spi->regs =devm_ioremap_resource (&pdev->dev, res);if (IS_ERR (spi->regs)) { ret =PTR_ERR (spi->regs);
Signature · 1 line
2.23.0
Quoted 3 lines · Aurabindo Jayamohanan
platform_get_resource()may return NULL. If it is so, return-ENXIOSigned-off-by Aurabindo Jayamohanan <[email protected]>
- Paul
Quoted 13 lines · Aurabindo Jayamohanan
platform_get_resource()may return NULL. If it is so, return-ENXIOSigned-off-by Aurabindo Jayamohanan <[email protected]>--- drivers/spi/spi-sifive.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/spi/spi-sifive.c +0
-0
drivers/spi/spi-sifive.c static int sifive_spi_probe(struct platform_device *pdev) · line 315
Quoted 8 lines
drivers/spi/spi-sifive.c +5
-0@@ -308,6 +308,12 @@ static int sifive_spi_probe(struct platform_device *pdev)platform_set_drvdata (pdev, master); res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) { +dev_err (&pdev->dev,"no IOMEM resource found\n" ); + ret = -ENXIO ; + goto put_master; + }
Seems unnecessary, the devm_ioremap_resource() already validated if the resource is available.
Signature · 2 lines
Baolin Wang Best Regards
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
Quoted 32 lines · Baolin Wang
Quoted 30 lines · On Tue, 17 Sep 2019 at 17:12, Aurabindo Jayamohanan [email protected] wrote:
platform_get_resource()may return NULL. If it is so, return-ENXIOSigned-off-by Aurabindo Jayamohanan [email protected]-------------------------------------------------------
drivers/spi/spi-sifive.c| 6 ++++++1 file changed, 6 insertions(+)drivers/spi/spi-sifive.c +0
-4@@ -308,6 +308,12 @@ static int sifive_spi_probe(struct platform_device *pdev)platform_set_drvdata (pdev, master); res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); -if (!res) { -dev_err (&pdev->dev,"no IOMEM resource found\\n" ); - ret = -ENXIO ; - goto put_master;
Quoted 7 lines
Quoted 3 lines
- }
Seems unnecessary, the
devm_ioremap_resource()already validated if the resource is available.
Okay, thanks for the headsup
Quoted 16 lines · Baolin Wang
Quoted 15 lines · Aurabindo Jayamohanan
platform_get_resource()may return NULL. If it is so, return-ENXIOSigned-off-by Aurabindo Jayamohanan <[email protected]>--- drivers/spi/spi-sifive.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/spi/spi-sifive.c +0
-0@@ -308,6 +308,12 @@ static int sifive_spi_probe(struct platform_device *pdev)platform_set_drvdata (pdev, master);
Quoted 9 lines
drivers/spi/spi-sifive.c static int sifive_spi_probe(struct platform_device *pdev) · line 315
Quoted 6 lines
drivers/spi/spi-sifive.c +5
-0res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) { +dev_err (&pdev->dev,"no IOMEM resource found\n" ); + ret = -ENXIO ; + goto put_master; + }Seems unnecessary, the
devm_ioremap_resource()already validated if the resource is available.
Just doublechecked lib/devres.c and I agree with you.
Aurobindo, is this a patch for a real problem that you've encountered?
- Paul
Hi Paul,
Quoted 26 lines · Paul Walmsley
Quoted 15 lines · Baolin Wang
Quoted 14 lines · Aurabindo Jayamohanan
platform_get_resource()may return NULL. If it is so, return-ENXIOSigned-off-by Aurabindo Jayamohanan <[email protected]>--- drivers/spi/spi-sifive.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/spi/spi-sifive.c +0
-0@@ -308,6 +308,12 @@ static int sifive_spi_probe(struct platform_device *pdev)platform_set_drvdata (pdev, master);Quoted 9 lines
drivers/spi/spi-sifive.c static int sifive_spi_probe(struct platform_device *pdev) · line 315
Quoted 6 lines
drivers/spi/spi-sifive.c +5
-0res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) { +dev_err (&pdev->dev,"no IOMEM resource found\n" ); + ret = -ENXIO ; + goto put_master; + }Seems unnecessary, the
devm_ioremap_resource()already validated if the resource is available.
Quoted 3 lines
Just doublechecked
lib/devres.cand I agree with you.Aurobindo, is this a patch for a real problem that you've encountered?
Probably not.
The sequence can be replaced by a single call to devm_platform_ioremap_resource(), which BTW also doesn't check the intermediate result, as that's unneeded.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Hi Paul,
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
Quoted 41 lines · Paul Walmsley
Quoted 32 lines · Baolin Wang
Quoted 30 lines · On Tue, 17 Sep 2019 at 17:12, Aurabindo Jayamohanan [email protected] wrote:
platform_get_resource()may return NULL. If it is so, return-ENXIOSigned-off-by Aurabindo Jayamohanan [email protected]-------------------------------------------------------
drivers/spi/spi-sifive.c| 6 ++++++1 file changed, 6 insertions(+)drivers/spi/spi-sifive.c +0
-4@@ -308,6 +308,12 @@ static int sifive_spi_probe(struct platform_device *pdev)platform_set_drvdata (pdev, master); res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); -if (!res) { -dev_err (&pdev->dev,"no IOMEM resource found\\n" ); - ret = -ENXIO ; - goto put_master;Quoted 6 lines
Quoted 3 lines
- }
Seems unnecessary, the
devm_ioremap_resource()already validated if the resource is available.
Quoted 5 lines
Just doublechecked
lib/devres.cand I agree with you.Aurobindo, is this a patch for a real problem that you've encountered?
- Paul
Geert is right. I was just breezing through the source and found it odd since I noticed other instances checking for return value. Apparently none of those use the managed api.
If you didnt already do Geert's suggestion, here is a patch:
____
spi: sifive: use device managed api to get plaform resource
calls to devm_ioremap_resource() preceeded by platform_get_resource() may be replaced by devm_platform_ioremap_resource().
--- drivers/spi/spi-sifive.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/spi/spi-sifive.c +1 -3
@@ -292,7 +292,6 @@ sifive_spi_transfer_one(struct spi_master *master, struct spi_device *device,static int sifive_spi_probe (struct platform_device *pdev) {struct sifive_spi *spi; -struct resource *res;int ret, irq, num_cs;u32 cs_bits, max_bits_per_word;struct spi_master *master;
@@ -307,8 +306,7 @@ static int sifive_spi_probe(struct platform_device *pdev)init_completion (&spi->done);platform_set_drvdata (pdev, master); - res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); - spi->regs =devm_ioremap_resource (&pdev->dev, res); + spi->regs =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (spi->regs)) { ret =PTR_ERR (spi->regs); goto put_master;
--
2.23.0
Aurobindo,
Quoted 48 lines · Aurabindo Jayamohanan
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
Quoted 45 lines · Paul Walmsley
Quoted 32 lines · Baolin Wang
Quoted 30 lines · On Tue, 17 Sep 2019 at 17:12, Aurabindo Jayamohanan [email protected] wrote:
platform_get_resource()may return NULL. If it is so, return-ENXIOSigned-off-by Aurabindo Jayamohanan [email protected]-------------------------------------------------------
drivers/spi/spi-sifive.c| 6 ++++++1 file changed, 6 insertions(+)drivers/spi/spi-sifive.c +0
-4@@ -308,6 +308,12 @@ static int sifive_spi_probe(struct platform_device *pdev)platform_set_drvdata (pdev, master); res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); -if (!res) { -dev_err (&pdev->dev,"no IOMEM resource found\\n" ); - ret = -ENXIO ; - goto put_master;Quoted 6 lines
Quoted 3 lines
- }
Seems unnecessary, the
devm_ioremap_resource()already validated if the resource is available.Just doublechecked
lib/devres.cand I agree with you.Aurobindo, is this a patch for a real problem that you've encountered?
Quoted 7 lines
Quoted 1 line
- Paul
Geert is right. I was just breezing through the source and found it odd since I noticed other instances checking for return value. Apparently none of those use the managed api.
If you didnt already do Geert's suggestion,
Mark Brown is the maintainer, so he'd be the one to apply anything touching these drivers.
Quoted 1 line
here is a patch:
Could you please send this as a separate E-mail?
Quoted 3 lines
____
spi: sifive: use device managed api to get plaform resource
"platform resource"
Quoted 2 lines
calls to
devm_ioremap_resource()preceeded byplatform_get_resource()
"Calls"
"preceded"
Quoted 1 line
may be replaced by
devm_platform_ioremap_resource().
Please explain why. In this case "removing boilerplate from the code" seems like a reasonable explanation.
Quoted 29 lines
Signed-off-by Aurabindo Jayamohanan <[email protected]>--- drivers/spi/spi-sifive.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/spi/spi-sifive.c +1
-4@@ -292,7 +292,6 @@ sifive_spi_transfer_one(struct spi_master *master, struct spi_device *device,static int sifive_spi_probe (struct platform_device *pdev) {struct sifive_spi *spi; -struct resource *res;int ret, irq, num_cs;u32 cs_bits, max_bits_per_word;struct spi_master *master;@@ -307,8 +306,7 @@ static int sifive_spi_probe(struct platform_device *pdev)init_completion (&spi->done);platform_set_drvdata (pdev, master); - res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); - spi->regs =devm_ioremap_resource (&pdev->dev, res); + spi->regs =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (spi->regs)) { ret =PTR_ERR (spi->regs); goto put_master; --
Quoted 2 lines
2.23.0
- Paul
I just recalled that YueHaibing already posted a patch to do this:
https://lore.kernel.org/linux-riscv/[email protected]/
- Paul
Hi Paul,
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
Quoted 6 lines · Paul Walmsley
I just recalled that YueHaibing already posted a patch to do this:
Ah, sorry for the noise.