spi/imx: prevent NULL pointer dereference in spi_imx_probe()
Subsystems (2)
PATCH 1/1 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.
--- drivers/spi/spi-imx.c | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-)
drivers/spi/spi-imx.c +7 -3
@@ -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);
@@ -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;
Signature · 1 line
1.7.2.5
A message that is not in the archive (sent off-list or not yet received): 1333458224-7602-1-git-send-email-LW-bxm8fMRDkQLDiMYJYoSAnRvVK+yQ3ZXh@public.gmane.org
Grant Likely
AppliedQuoted 6 lines · Lothar Waßmann
When no
platform_datais present and either 'spi-num-chipselects' is not defined in the DT or 'cs-gpios' has less entries than 'spi-num-chipselects' specifies, the NULLplatform_datapointer is being dereferenced.Signed-off-by Lothar Waßmann <[email protected]>
Applied, thanks.
g.
Quoted 40 lines
--- drivers/spi/spi-imx.c | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-)drivers/spi/spi-imx.c +7
-3@@ -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);@@ -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;Signature · 7 lines
1.7.2.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Signature · 2 lines
Grant Likely, B.Sc, P.Eng. Secret Lab Technologies,Ltd.
------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to monitoring Big Data applications. Try Boundary one-second resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
spi-devel-general mailing list spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/spi-devel-general