Skip to content

Commit

Permalink
spi/imx: prevent NULL pointer dereference in spi_imx_probe()
Browse files Browse the repository at this point in the history
When no platform_data is present and either 'spi-num-chipselects' is
not defined in the DT or 'cs-gpios' has less entries than
'spi-num-chipselects' specifies, the NULL platform_data pointer is
being dereferenced.

Signed-off-by: Lothar Waßmann <LW@KARO-electronics.de>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
  • Loading branch information
Lothar Waßmann authored and Grant Likely committed Apr 11, 2012
1 parent cc4d22a commit 39ec0d3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions drivers/spi/spi-imx.c
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,12 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
}

ret = of_property_read_u32(np, "fsl,spi-num-chipselects", &num_cs);
if (ret < 0)
num_cs = mxc_platform_info->num_chipselect;
if (ret < 0) {
if (mxc_platform_info)
num_cs = mxc_platform_info->num_chipselect;
else
return ret;
}

master = spi_alloc_master(&pdev->dev,
sizeof(struct spi_imx_data) + sizeof(int) * num_cs);
Expand All @@ -784,7 +788,7 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)

for (i = 0; i < master->num_chipselect; i++) {
int cs_gpio = of_get_named_gpio(np, "cs-gpios", i);
if (cs_gpio < 0)
if (cs_gpio < 0 && mxc_platform_info)
cs_gpio = mxc_platform_info->chipselect[i];

spi_imx->chipselect[i] = cs_gpio;
Expand Down

0 comments on commit 39ec0d3

Please sign in to comment.