mtd: fsl-quadspi: possible NULL dereference

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Tue Jan 12 15:59:07 PST 2016


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=c98f71d1c05601cff0f302889933798020e08869
Commit:     c98f71d1c05601cff0f302889933798020e08869
Parent:     fc5adbebac6ffab461492f7a415648b29b1a3b31
Author:     Brian Norris <computersforpeace at gmail.com>
AuthorDate: Mon Nov 16 10:45:30 2015 -0800
Committer:  Brian Norris <computersforpeace at gmail.com>
CommitDate: Wed Nov 18 10:31:23 2015 -0800

    mtd: fsl-quadspi: possible NULL dereference
    
    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 at gmail.com>
    Acked-by: Han xu <han.xu at freescale.com>
---
 drivers/mtd/spi-nor/fsl-quadspi.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/spi-nor/fsl-quadspi.c b/drivers/mtd/spi-nor/fsl-quadspi.c
index 9e7f657..54640f1 100644
--- a/drivers/mtd/spi-nor/fsl-quadspi.c
+++ b/drivers/mtd/spi-nor/fsl-quadspi.c
@@ -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 */



More information about the linux-mtd-cvs mailing list