linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd: fsl-quadspi: possible NULL reference
@ 2015-11-16 18:42 Brian Norris
  2015-11-16 18:45 ` [PATCH v2] mtd: fsl-quadspi: possible NULL dereference Brian Norris
  2015-11-16 19:46 ` [PATCH] mtd: fsl-quadspi: possible NULL reference kbuild test robot
  0 siblings, 2 replies; 5+ messages in thread
From: Brian Norris @ 2015-11-16 18:42 UTC (permalink / raw)
  To: linux-mtd; +Cc: linux-kernel, Brian Norris, Han Xu

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>
Cc: Han Xu <han.xu@freescale.com>
---
 drivers/mtd/spi-nor/fsl-quadspi.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/spi-nor/fsl-quadspi.c b/drivers/mtd/spi-nor/fsl-quadspi.c
index cc3a70b9b020..68fe7a2ecd5c 100644
--- a/drivers/mtd/spi-nor/fsl-quadspi.c
+++ b/drivers/mtd/spi-nor/fsl-quadspi.c
@@ -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 */
-- 
2.6.0.rc2.230.g3dd15c0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2] mtd: fsl-quadspi: possible NULL dereference
  2015-11-16 18:42 [PATCH] mtd: fsl-quadspi: possible NULL reference Brian Norris
@ 2015-11-16 18:45 ` Brian Norris
  2015-11-17 21:42   ` Han Xu
  2015-11-18 18:32   ` Brian Norris
  2015-11-16 19:46 ` [PATCH] mtd: fsl-quadspi: possible NULL reference kbuild test robot
  1 sibling, 2 replies; 5+ messages in thread
From: Brian Norris @ 2015-11-16 18:45 UTC (permalink / raw)
  To: linux-mtd; +Cc: Brian Norris, linux-kernel, Han Xu

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>
Cc: Han Xu <han.xu@freescale.com>
---
v2:
 * missed a 'const' warning
 * s/reference/dereference in $subject

 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 cc3a70b9b020..916d6dd5b575 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 */
-- 
2.6.0.rc2.230.g3dd15c0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] mtd: fsl-quadspi: possible NULL reference
  2015-11-16 18:42 [PATCH] mtd: fsl-quadspi: possible NULL reference Brian Norris
  2015-11-16 18:45 ` [PATCH v2] mtd: fsl-quadspi: possible NULL dereference Brian Norris
@ 2015-11-16 19:46 ` kbuild test robot
  1 sibling, 0 replies; 5+ messages in thread
From: kbuild test robot @ 2015-11-16 19:46 UTC (permalink / raw)
  To: Brian Norris; +Cc: kbuild-all, linux-mtd, linux-kernel, Brian Norris, Han Xu

[-- Attachment #1: Type: text/plain, Size: 1773 bytes --]

Hi Brian,

[auto build test WARNING on mtd/master]
[also build test WARNING on v4.4-rc1 next-20151116]

url:    https://github.com/0day-ci/linux/commits/Brian-Norris/mtd-fsl-quadspi-possible-NULL-reference/20151117-024430
base:   git://git.infradead.org/linux-mtd.git master
config: i386-allmodconfig (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All warnings (new ones prefixed by >>):

   drivers/mtd/spi-nor/fsl-quadspi.c: In function 'fsl_qspi_probe':
>> drivers/mtd/spi-nor/fsl-quadspi.c:947:18: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
     q->devtype_data = of_device_get_match_data(dev);
                     ^

vim +/const +947 drivers/mtd/spi-nor/fsl-quadspi.c

   931		struct device *dev = &pdev->dev;
   932		struct fsl_qspi *q;
   933		struct resource *res;
   934		struct spi_nor *nor;
   935		struct mtd_info *mtd;
   936		int ret, i = 0;
   937	
   938		q = devm_kzalloc(dev, sizeof(*q), GFP_KERNEL);
   939		if (!q)
   940			return -ENOMEM;
   941	
   942		q->nor_num = of_get_child_count(dev->of_node);
   943		if (!q->nor_num || q->nor_num > FSL_QSPI_MAX_CHIP)
   944			return -ENODEV;
   945	
   946		q->dev = dev;
 > 947		q->devtype_data = of_device_get_match_data(dev);
   948		if (!q->devtype_data)
   949			return -ENODEV;
   950		platform_set_drvdata(pdev, q);
   951	
   952		/* find the resources */
   953		res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "QuadSPI");
   954		q->iobase = devm_ioremap_resource(dev, res);
   955		if (IS_ERR(q->iobase))

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 51520 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] mtd: fsl-quadspi: possible NULL dereference
  2015-11-16 18:45 ` [PATCH v2] mtd: fsl-quadspi: possible NULL dereference Brian Norris
@ 2015-11-17 21:42   ` Han Xu
  2015-11-18 18:32   ` Brian Norris
  1 sibling, 0 replies; 5+ messages in thread
From: Han Xu @ 2015-11-17 21:42 UTC (permalink / raw)
  To: Brian Norris; +Cc: linux-mtd, linux-kernel

On Mon, Nov 16, 2015 at 10:45:30AM -0800, Brian Norris wrote:
> 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>
> Cc: Han Xu <han.xu@freescale.com>
> ---
> v2:
>  * missed a 'const' warning
>  * s/reference/dereference in $subject
> 
>  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 cc3a70b9b020..916d6dd5b575 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 */
> -- 
> 2.6.0.rc2.230.g3dd15c0
> 
Acked-by: Han xu <han.xu@freescale.com>
-- 
Best Regards,

Han "Allen" Xu

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] mtd: fsl-quadspi: possible NULL dereference
  2015-11-16 18:45 ` [PATCH v2] mtd: fsl-quadspi: possible NULL dereference Brian Norris
  2015-11-17 21:42   ` Han Xu
@ 2015-11-18 18:32   ` Brian Norris
  1 sibling, 0 replies; 5+ messages in thread
From: Brian Norris @ 2015-11-18 18:32 UTC (permalink / raw)
  To: linux-mtd; +Cc: linux-kernel, Han Xu

On Mon, Nov 16, 2015 at 10:45:30AM -0800, Brian Norris wrote:
> 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>
> Cc: Han Xu <han.xu@freescale.com>
> ---
> v2:
>  * missed a 'const' warning
>  * s/reference/dereference in $subject

Pushed to l2-mtd.git

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-11-18 18:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-16 18:42 [PATCH] mtd: fsl-quadspi: possible NULL reference Brian Norris
2015-11-16 18:45 ` [PATCH v2] mtd: fsl-quadspi: possible NULL dereference Brian Norris
2015-11-17 21:42   ` Han Xu
2015-11-18 18:32   ` Brian Norris
2015-11-16 19:46 ` [PATCH] mtd: fsl-quadspi: possible NULL reference kbuild test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).