Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

spi: Fix potential uninitialized variable in probe()

If the device tree is messed up, then potentially the "protocol" string
could potentially be uninitialized. The property is supposed to default
to "motorola" so if the of_property_read_string() function returns
-EINVAL then default to "motorola".

Fixes: 059f545832be ("spi: add support for microchip "soft" spi controller")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Prajna Rajendra Kumar <prajna.rajendrakumar@microchip.com>
Link: https://patch.msgid.link/aSQPkfkiJ0w-FJMW@stanley.mountain
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Dan Carpenter and committed by
Mark Brown
cb99656b 43a3adb6

+3 -1
+3 -1
drivers/spi/spi-microchip-core-spi.c
··· 295 295 296 296 static int mchp_corespi_probe(struct platform_device *pdev) 297 297 { 298 + const char *protocol = "motorola"; 298 299 struct spi_controller *host; 299 300 struct mchp_corespi *spi; 300 301 struct resource *res; 301 - const char *protocol; 302 302 u32 num_cs, mode, frame_size; 303 303 bool assert_ssel; 304 304 int ret = 0; ··· 320 320 */ 321 321 ret = of_property_read_string(pdev->dev.of_node, "microchip,protocol-configuration", 322 322 &protocol); 323 + if (ret && ret != -EINVAL) 324 + return dev_err_probe(&pdev->dev, ret, "Error reading protocol-configuration\n"); 323 325 if (strcmp(protocol, "motorola") != 0) 324 326 return dev_err_probe(&pdev->dev, -EINVAL, 325 327 "CoreSPI: protocol '%s' not supported by this driver\n",