spi: Fix potential uninitialized variable in probe()
Subsystems (2)
PATCH 1/1 spi: Fix potential uninitialized variable in probe()
If the device tree is messed up, then potentially the "protocol" string could potentially be uninitialized. Add a check to prevent that.
--- drivers/spi/spi-microchip-core-spi.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/spi/spi-microchip-core-spi.c +2 -0
@@ -320,6 +320,8 @@ static int mchp_corespi_probe(struct platform_device *pdev)*/ ret =of_property_read_string (pdev->dev.of_node,"microchip,protocol-configuration" , &protocol); +if (ret) +return ret;if (strcmp (protocol,"motorola" ) !=0 ) return dev_err_probe(&pdev->dev, -EINVAL, "CoreSPI: protocol '%s' not supported by this driver\n",
Signature · 1 line
2.51.0
Mark Brown
maintainerQuoted 14 lines · Dan Carpenter
If the device tree is messed up, then potentially the "protocol" string could potentially be uninitialized. Add a check to prevent that.
Fixes 059f545832be ("spi: add support for microchip "soft" spi controller")Signed-off-by Dan Carpenter <[email protected]>--- drivers/spi/spi-microchip-core-spi.c | 2 ++ 1 file changed, 2 insertions(+)drivers/spi/spi-microchip-core-spi.c +0
-0
drivers/spi/spi-microchip-core-spi.c static int mchp_corespi_probe(struct platform_device *pdev) · line 327
Quoted 8 lines
drivers/spi/spi-microchip-core-spi.c +2
-0@@ -320,6 +320,8 @@ static int mchp_corespi_probe(struct platform_device *pdev)*/ ret =of_property_read_string (pdev->dev.of_node,"microchip,protocol-configuration" , &protocol); +if (ret) +return ret;if (strcmp (protocol,"motorola" ) !=0 ) return dev_err_probe(&pdev->dev, -EINVAL, "CoreSPI: protocol '%s' not supported by this driver\n",
This should probably also complain about not being able to get the property, otherwise nobody is going to be able to figure out what's wrong if we actually hit the error case.
Quoted 19 lines · Mark Brown
Quoted 18 lines · Dan Carpenter
If the device tree is messed up, then potentially the "protocol" string could potentially be uninitialized. Add a check to prevent that.
Fixes 059f545832be ("spi: add support for microchip "soft" spi controller")Signed-off-by Dan Carpenter <[email protected]>--- drivers/spi/spi-microchip-core-spi.c | 2 ++ 1 file changed, 2 insertions(+)drivers/spi/spi-microchip-core-spi.c +1
-0@@ -320,6 +320,8 @@ static int mchp_corespi_probe(struct platform_device *pdev)*/ ret =of_property_read_string (pdev->dev.of_node,"microchip,protocol-configuration" , &protocol); +if (ret)
Quoted 8 lines
drivers/spi/spi-microchip-core-spi.c static int mchp_corespi_probe(struct platform_device *pdev) · line 327
Quoted 4 lines
drivers/spi/spi-microchip-core-spi.c +1
-0+return ret;if (strcmp (protocol,"motorola" ) !=0 ) return dev_err_probe(&pdev->dev, -EINVAL, "CoreSPI: protocol '%s' not supported by this driver\n",This should probably also complain about not being able to get the property, otherwise nobody is going to be able to figure out what's wrong if we actually hit the error case.
The one thing to be careful of is that the property has a default, so EINVAL needs to be treated differently, so the decision tree is something like:
if (ret == _EINVAL)
<do nothing>
else if (ret)
abort complaining about malformed
else if (!motorola)
abort complaining about unsupported mode
else
<do nothing>
obviously that can just become two clauses, but you get the idea.
Quoted 41 lines · Conor Dooley
Quoted 19 lines · Mark Brown
Quoted 18 lines · Dan Carpenter
If the device tree is messed up, then potentially the "protocol" string could potentially be uninitialized. Add a check to prevent that.
Fixes 059f545832be ("spi: add support for microchip "soft" spi controller")Signed-off-by Dan Carpenter <[email protected]>--- drivers/spi/spi-microchip-core-spi.c | 2 ++ 1 file changed, 2 insertions(+)drivers/spi/spi-microchip-core-spi.c +1
-0@@ -320,6 +320,8 @@ static int mchp_corespi_probe(struct platform_device *pdev)*/ ret =of_property_read_string (pdev->dev.of_node,"microchip,protocol-configuration" , &protocol); +if (ret)Quoted 8 lines
drivers/spi/spi-microchip-core-spi.c static int mchp_corespi_probe(struct platform_device *pdev) · line 327
Quoted 4 lines
drivers/spi/spi-microchip-core-spi.c +1
-0+return ret;if (strcmp (protocol,"motorola" ) !=0 ) return dev_err_probe(&pdev->dev, -EINVAL, "CoreSPI: protocol '%s' not supported by this driver\n",This should probably also complain about not being able to get the property, otherwise nobody is going to be able to figure out what's wrong if we actually hit the error case.
The one thing to be careful of is that the property has a default, so EINVAL needs to be treated differently, so the decision tree is something like:
if (ret ==_EINVAL)
<do nothing>
else if (ret)
abort complaining about malformed
else if (!motorola)
abort complaining about unsupported mode
else
<do nothing>
Quoted 1 line
obviously that can just become two clauses, but you get the idea.
Sure. I've sent a v2 which defaults to motorola.
regards,
dan carpenter