* [PATCH next] spi: Fix potential uninitialized variable in probe()
@ 2025-11-21 13:35 Dan Carpenter
2025-11-21 14:18 ` Mark Brown
0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2025-11-21 13:35 UTC (permalink / raw)
To: Prajna Rajendra Kumar
Cc: Mark Brown, Conor Dooley, linux-spi, linux-kernel,
kernel-janitors
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 <dan.carpenter@linaro.org>
---
drivers/spi/spi-microchip-core-spi.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/spi/spi-microchip-core-spi.c b/drivers/spi/spi-microchip-core-spi.c
index b8738190cdcb..e65036cc62f3 100644
--- a/drivers/spi/spi-microchip-core-spi.c
+++ b/drivers/spi/spi-microchip-core-spi.c
@@ -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",
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH next] spi: Fix potential uninitialized variable in probe() 2025-11-21 13:35 [PATCH next] spi: Fix potential uninitialized variable in probe() Dan Carpenter @ 2025-11-21 14:18 ` Mark Brown 2025-11-21 16:20 ` Conor Dooley 0 siblings, 1 reply; 4+ messages in thread From: Mark Brown @ 2025-11-21 14:18 UTC (permalink / raw) To: Dan Carpenter Cc: Prajna Rajendra Kumar, Conor Dooley, linux-spi, linux-kernel, kernel-janitors [-- Attachment #1: Type: text/plain, Size: 1256 bytes --] On Fri, Nov 21, 2025 at 04:35:01PM +0300, Dan Carpenter wrote: > 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 <dan.carpenter@linaro.org> > --- > drivers/spi/spi-microchip-core-spi.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/spi/spi-microchip-core-spi.c b/drivers/spi/spi-microchip-core-spi.c > index b8738190cdcb..e65036cc62f3 100644 > --- a/drivers/spi/spi-microchip-core-spi.c > +++ b/drivers/spi/spi-microchip-core-spi.c > @@ -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. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH next] spi: Fix potential uninitialized variable in probe() 2025-11-21 14:18 ` Mark Brown @ 2025-11-21 16:20 ` Conor Dooley 2025-11-24 7:56 ` Dan Carpenter 0 siblings, 1 reply; 4+ messages in thread From: Conor Dooley @ 2025-11-21 16:20 UTC (permalink / raw) To: Mark Brown Cc: Dan Carpenter, Prajna Rajendra Kumar, Conor Dooley, linux-spi, linux-kernel, kernel-janitors [-- Attachment #1: Type: text/plain, Size: 1773 bytes --] On Fri, Nov 21, 2025 at 02:18:49PM +0000, Mark Brown wrote: > On Fri, Nov 21, 2025 at 04:35:01PM +0300, Dan Carpenter wrote: > > 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 <dan.carpenter@linaro.org> > > --- > > drivers/spi/spi-microchip-core-spi.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/drivers/spi/spi-microchip-core-spi.c b/drivers/spi/spi-microchip-core-spi.c > > index b8738190cdcb..e65036cc62f3 100644 > > --- a/drivers/spi/spi-microchip-core-spi.c > > +++ b/drivers/spi/spi-microchip-core-spi.c > > @@ -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. 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. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH next] spi: Fix potential uninitialized variable in probe() 2025-11-21 16:20 ` Conor Dooley @ 2025-11-24 7:56 ` Dan Carpenter 0 siblings, 0 replies; 4+ messages in thread From: Dan Carpenter @ 2025-11-24 7:56 UTC (permalink / raw) To: Conor Dooley Cc: Mark Brown, Prajna Rajendra Kumar, Conor Dooley, linux-spi, linux-kernel, kernel-janitors On Fri, Nov 21, 2025 at 04:20:41PM +0000, Conor Dooley wrote: > On Fri, Nov 21, 2025 at 02:18:49PM +0000, Mark Brown wrote: > > On Fri, Nov 21, 2025 at 04:35:01PM +0300, Dan Carpenter wrote: > > > 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 <dan.carpenter@linaro.org> > > > --- > > > drivers/spi/spi-microchip-core-spi.c | 2 ++ > > > 1 file changed, 2 insertions(+) > > > > > > diff --git a/drivers/spi/spi-microchip-core-spi.c b/drivers/spi/spi-microchip-core-spi.c > > > index b8738190cdcb..e65036cc62f3 100644 > > > --- a/drivers/spi/spi-microchip-core-spi.c > > > +++ b/drivers/spi/spi-microchip-core-spi.c > > > @@ -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. > > 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. Sure. I've sent a v2 which defaults to motorola. regards, dan carpenter ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-11-24 7:56 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-11-21 13:35 [PATCH next] spi: Fix potential uninitialized variable in probe() Dan Carpenter 2025-11-21 14:18 ` Mark Brown 2025-11-21 16:20 ` Conor Dooley 2025-11-24 7:56 ` Dan Carpenter
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox