[PATCH next] spi: Fix potential uninitialized variable in probe()

Dan Carpenter
2025-11-21T13:35:07Z

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