summaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi-coldfire-qspi.c
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@ingics.com>2014-03-09 14:11:10 +0800
committerMark Brown <broonie@linaro.org>2014-03-10 16:06:45 +0000
commit2271cf124a2763b7252887814a7fc8a844767e8f (patch)
tree2aa554da7a1af8000ac7c5c594123f1b6de0b5b7 /drivers/spi/spi-coldfire-qspi.c
parent2aa237f4a1a72813f9684a0ce6e48288e75de479 (diff)
downloadlinux-2271cf124a2763b7252887814a7fc8a844767e8f.tar.gz
linux-2271cf124a2763b7252887814a7fc8a844767e8f.tar.bz2
linux-2271cf124a2763b7252887814a7fc8a844767e8f.zip
spi: coldfire-qspi: Prevent NULL pointer dereference
If pdata->cs_control is NULL, we will hit NULL pointer dereference in mcfqspi_cs_select() and mcfqspi_cs_deselect(). Thus add NULL test for pdata->cs_control in probe(). Signed-off-by: Axel Lin <axel.lin@ingics.com> Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'drivers/spi/spi-coldfire-qspi.c')
-rw-r--r--drivers/spi/spi-coldfire-qspi.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/drivers/spi/spi-coldfire-qspi.c b/drivers/spi/spi-coldfire-qspi.c
index 94d817523d5f..6d78f96bdc55 100644
--- a/drivers/spi/spi-coldfire-qspi.c
+++ b/drivers/spi/spi-coldfire-qspi.c
@@ -133,13 +133,13 @@ static void mcfqspi_cs_deselect(struct mcfqspi *mcfqspi, u8 chip_select,
static int mcfqspi_cs_setup(struct mcfqspi *mcfqspi)
{
- return (mcfqspi->cs_control && mcfqspi->cs_control->setup) ?
+ return (mcfqspi->cs_control->setup) ?
mcfqspi->cs_control->setup(mcfqspi->cs_control) : 0;
}
static void mcfqspi_cs_teardown(struct mcfqspi *mcfqspi)
{
- if (mcfqspi->cs_control && mcfqspi->cs_control->teardown)
+ if (mcfqspi->cs_control->teardown)
mcfqspi->cs_control->teardown(mcfqspi->cs_control);
}
@@ -372,6 +372,11 @@ static int mcfqspi_probe(struct platform_device *pdev)
return -ENOENT;
}
+ if (!pdata->cs_control) {
+ dev_dbg(&pdev->dev, "pdata->cs_control is NULL\n");
+ return -EINVAL;
+ }
+
master = spi_alloc_master(&pdev->dev, sizeof(*mcfqspi));
if (master == NULL) {
dev_dbg(&pdev->dev, "spi_alloc_master failed\n");