Skip to content

Commit cb99656

Browse files
Dan Carpenterbroonie
authored andcommitted
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: 059f545 ("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>
1 parent 43a3adb commit cb99656

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

drivers/spi/spi-microchip-core-spi.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,10 @@ static int mchp_corespi_transfer_one(struct spi_controller *host,
295295

296296
static int mchp_corespi_probe(struct platform_device *pdev)
297297
{
298+
const char *protocol = "motorola";
298299
struct spi_controller *host;
299300
struct mchp_corespi *spi;
300301
struct resource *res;
301-
const char *protocol;
302302
u32 num_cs, mode, frame_size;
303303
bool assert_ssel;
304304
int ret = 0;
@@ -320,6 +320,8 @@ static int mchp_corespi_probe(struct platform_device *pdev)
320320
*/
321321
ret = of_property_read_string(pdev->dev.of_node, "microchip,protocol-configuration",
322322
&protocol);
323+
if (ret && ret != -EINVAL)
324+
return dev_err_probe(&pdev->dev, ret, "Error reading protocol-configuration\n");
323325
if (strcmp(protocol, "motorola") != 0)
324326
return dev_err_probe(&pdev->dev, -EINVAL,
325327
"CoreSPI: protocol '%s' not supported by this driver\n",

0 commit comments

Comments
 (0)