aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi-imx.c
diff options
context:
space:
mode:
authorLothar Waßmann <LW@KARO-electronics.de>2012-04-03 09:03:44 -0400
committerGrant Likely <grant.likely@secretlab.ca>2012-04-11 00:17:15 -0400
commit39ec0d38141b198f94fd19c2bb10fd7c616510d2 (patch)
tree45fdc314c87e04398e4de5c0c93f8590556b1c4c /drivers/spi/spi-imx.c
parentcc4d22ae541ccd989ef163c46a38afde131e1644 (diff)
spi/imx: prevent NULL pointer dereference in spi_imx_probe()
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>
Diffstat (limited to 'drivers/spi/spi-imx.c')
-rw-r--r--drivers/spi/spi-imx.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 373f4fff9358..570f22053be8 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -766,8 +766,12 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
766 } 766 }
767 767
768 ret = of_property_read_u32(np, "fsl,spi-num-chipselects", &num_cs); 768 ret = of_property_read_u32(np, "fsl,spi-num-chipselects", &num_cs);
769 if (ret < 0) 769 if (ret < 0) {
770 num_cs = mxc_platform_info->num_chipselect; 770 if (mxc_platform_info)
771 num_cs = mxc_platform_info->num_chipselect;
772 else
773 return ret;
774 }
771 775
772 master = spi_alloc_master(&pdev->dev, 776 master = spi_alloc_master(&pdev->dev,
773 sizeof(struct spi_imx_data) + sizeof(int) * num_cs); 777 sizeof(struct spi_imx_data) + sizeof(int) * num_cs);
@@ -784,7 +788,7 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
784 788
785 for (i = 0; i < master->num_chipselect; i++) { 789 for (i = 0; i < master->num_chipselect; i++) {
786 int cs_gpio = of_get_named_gpio(np, "cs-gpios", i); 790 int cs_gpio = of_get_named_gpio(np, "cs-gpios", i);
787 if (cs_gpio < 0) 791 if (cs_gpio < 0 && mxc_platform_info)
788 cs_gpio = mxc_platform_info->chipselect[i]; 792 cs_gpio = mxc_platform_info->chipselect[i];
789 793
790 spi_imx->chipselect[i] = cs_gpio; 794 spi_imx->chipselect[i] = cs_gpio;