mtd: fsl-quadspi: possible NULL dereference
authorBrian Norris <computersforpeace@gmail.com>
Mon, 16 Nov 2015 18:45:30 +0000 (10:45 -0800)
committerBrian Norris <computersforpeace@gmail.com>
Wed, 18 Nov 2015 18:31:23 +0000 (10:31 -0800)
It is theoretically possible to probe this driver without a matching
device tree, so let's guard against this.

Also, use the of_device_get_match_data() helper to make this a bit
simpler.

Coverity complained about this one.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Acked-by: Han xu <han.xu@freescale.com>
drivers/mtd/spi-nor/fsl-quadspi.c

index 9e7f657af6a56818bb22fc267d0c44effe187aeb..54640f1eb3a13caa772b003e624a4c61ae842171 100644 (file)
@@ -269,7 +269,7 @@ struct fsl_qspi {
        struct clk *clk, *clk_en;
        struct device *dev;
        struct completion c;
-       struct fsl_qspi_devtype_data *devtype_data;
+       const struct fsl_qspi_devtype_data *devtype_data;
        u32 nor_size;
        u32 nor_num;
        u32 clk_rate;
@@ -933,8 +933,6 @@ static int fsl_qspi_probe(struct platform_device *pdev)
        struct spi_nor *nor;
        struct mtd_info *mtd;
        int ret, i = 0;
-       const struct of_device_id *of_id =
-                       of_match_device(fsl_qspi_dt_ids, &pdev->dev);
 
        q = devm_kzalloc(dev, sizeof(*q), GFP_KERNEL);
        if (!q)
@@ -945,7 +943,9 @@ static int fsl_qspi_probe(struct platform_device *pdev)
                return -ENODEV;
 
        q->dev = dev;
-       q->devtype_data = (struct fsl_qspi_devtype_data *)of_id->data;
+       q->devtype_data = of_device_get_match_data(dev);
+       if (!q->devtype_data)
+               return -ENODEV;
        platform_set_drvdata(pdev, q);
 
        /* find the resources */