1080-mtd-fsl-quadspi-possible-NULL-dereference.patch 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. From bd02decd1ad7cc883ce388e769a34a3c402b90c4 Mon Sep 17 00:00:00 2001
  2. From: Brian Norris <computersforpeace@gmail.com>
  3. Date: Mon, 16 Nov 2015 10:45:30 -0800
  4. Subject: [PATCH 080/113] mtd: fsl-quadspi: possible NULL dereference
  5. It is theoretically possible to probe this driver without a matching
  6. device tree, so let's guard against this.
  7. Also, use the of_device_get_match_data() helper to make this a bit
  8. simpler.
  9. Coverity complained about this one.
  10. Signed-off-by: Brian Norris <computersforpeace@gmail.com>
  11. Acked-by: Han xu <han.xu@freescale.com>
  12. ---
  13. drivers/mtd/spi-nor/fsl-quadspi.c | 8 ++++----
  14. 1 file changed, 4 insertions(+), 4 deletions(-)
  15. --- a/drivers/mtd/spi-nor/fsl-quadspi.c
  16. +++ b/drivers/mtd/spi-nor/fsl-quadspi.c
  17. @@ -269,7 +269,7 @@ struct fsl_qspi {
  18. struct clk *clk, *clk_en;
  19. struct device *dev;
  20. struct completion c;
  21. - struct fsl_qspi_devtype_data *devtype_data;
  22. + const struct fsl_qspi_devtype_data *devtype_data;
  23. u32 nor_size;
  24. u32 nor_num;
  25. u32 clk_rate;
  26. @@ -933,8 +933,6 @@ static int fsl_qspi_probe(struct platfor
  27. struct spi_nor *nor;
  28. struct mtd_info *mtd;
  29. int ret, i = 0;
  30. - const struct of_device_id *of_id =
  31. - of_match_device(fsl_qspi_dt_ids, &pdev->dev);
  32. q = devm_kzalloc(dev, sizeof(*q), GFP_KERNEL);
  33. if (!q)
  34. @@ -945,7 +943,9 @@ static int fsl_qspi_probe(struct platfor
  35. return -ENODEV;
  36. q->dev = dev;
  37. - q->devtype_data = (struct fsl_qspi_devtype_data *)of_id->data;
  38. + q->devtype_data = of_device_get_match_data(dev);
  39. + if (!q->devtype_data)
  40. + return -ENODEV;
  41. platform_set_drvdata(pdev, q);
  42. /* find the resources */