Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1682965 > unrolled thread

[PATCH] mtd: nand: vf610_nfc: add NULL check on of_match_device() return value

Started by"Gustavo A. R. Silva" <garsilva@embeddedor.com>
First post2017-07-07 09:00 +0200
Last post2017-07-17 22:50 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] mtd: nand: vf610_nfc: add NULL check on of_match_device()  return value "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-07-07 09:00 +0200
    Re: [PATCH] mtd: nand: vf610_nfc: add NULL check on of_match_device()  return value Marek Vasut <marek.vasut@gmail.com> - 2017-07-17 22:50 +0200
    Re: [PATCH] mtd: nand: vf610_nfc: add NULL check on  of_match_device() return value Boris Brezillon <boris.brezillon@free-electrons.com> - 2017-07-17 22:50 +0200

#1682965 — [PATCH] mtd: nand: vf610_nfc: add NULL check on of_match_device() return value

From"Gustavo A. R. Silva" <garsilva@embeddedor.com>
Date2017-07-07 09:00 +0200
Subject[PATCH] mtd: nand: vf610_nfc: add NULL check on of_match_device() return value
Message-ID<u0vp7-9I-17@gated-at.bofh.it>
Check return value from call to of_match_device()
in order to prevent a NULL pointer dereference.

In case of NULL print error message and return -ENODEV

Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
 drivers/mtd/nand/vf610_nfc.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c
index 744ab10..ca0ab96 100644
--- a/drivers/mtd/nand/vf610_nfc.c
+++ b/drivers/mtd/nand/vf610_nfc.c
@@ -674,6 +674,11 @@ static int vf610_nfc_probe(struct platform_device *pdev)
 	}
 
 	of_id = of_match_device(vf610_nfc_dt_ids, &pdev->dev);
+	if (!of_id) {
+		dev_err(&pdev->dev, "Failed to match device!\n");
+		return -ENODEV;
+	}
+
 	nfc->variant = (enum vf610_nfc_variant)of_id->data;
 
 	for_each_available_child_of_node(nfc->dev->of_node, child) {
-- 
2.5.0

[toc] | [next] | [standalone]


#1689452

FromMarek Vasut <marek.vasut@gmail.com>
Date2017-07-17 22:50 +0200
Message-ID<u4l7P-1qg-5@gated-at.bofh.it>
In reply to#1682965
On 07/17/2017 10:46 PM, Boris Brezillon wrote:
> Le Fri, 7 Jul 2017 01:59:26 -0500,
> "Gustavo A. R. Silva" <garsilva@embeddedor.com> a écrit :
> 
>> Check return value from call to of_match_device()
>> in order to prevent a NULL pointer dereference.
>>
>> In case of NULL print error message and return -ENODEV
>>
>> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
>> ---
>>  drivers/mtd/nand/vf610_nfc.c | 5 +++++
>>  1 file changed, 5 insertions(+)
>>
>> diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c
>> index 744ab10..ca0ab96 100644
>> --- a/drivers/mtd/nand/vf610_nfc.c
>> +++ b/drivers/mtd/nand/vf610_nfc.c
>> @@ -674,6 +674,11 @@ static int vf610_nfc_probe(struct platform_device *pdev)
>>  	}
>>  
>>  	of_id = of_match_device(vf610_nfc_dt_ids, &pdev->dev);
>> +	if (!of_id) {
>> +		dev_err(&pdev->dev, "Failed to match device!\n");
>> +		return -ENODEV;
>> +	}
>> +
> 
> While this check is functionally correct, this case cannot happen,
> because this is DT-only driver, and without a valid match in
> vf610_nfc_dt_ids the dev wouldn't have been probed in the first place.
> 
> I'll let Stefan decide whether he wants it or not, but I see no real
> reason for this extra check. 

So how did you trigger the issue in the first place ?

-- 
Best regards,
Marek Vasut

[toc] | [prev] | [next] | [standalone]


#1689455 — Re: [PATCH] mtd: nand: vf610_nfc: add NULL check on of_match_device() return value

FromBoris Brezillon <boris.brezillon@free-electrons.com>
Date2017-07-17 22:50 +0200
SubjectRe: [PATCH] mtd: nand: vf610_nfc: add NULL check on of_match_device() return value
Message-ID<u4l7P-1qg-7@gated-at.bofh.it>
In reply to#1682965
Le Fri, 7 Jul 2017 01:59:26 -0500,
"Gustavo A. R. Silva" <garsilva@embeddedor.com> a écrit :

> Check return value from call to of_match_device()
> in order to prevent a NULL pointer dereference.
> 
> In case of NULL print error message and return -ENODEV
> 
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
> ---
>  drivers/mtd/nand/vf610_nfc.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c
> index 744ab10..ca0ab96 100644
> --- a/drivers/mtd/nand/vf610_nfc.c
> +++ b/drivers/mtd/nand/vf610_nfc.c
> @@ -674,6 +674,11 @@ static int vf610_nfc_probe(struct platform_device *pdev)
>  	}
>  
>  	of_id = of_match_device(vf610_nfc_dt_ids, &pdev->dev);
> +	if (!of_id) {
> +		dev_err(&pdev->dev, "Failed to match device!\n");
> +		return -ENODEV;
> +	}
> +

While this check is functionally correct, this case cannot happen,
because this is DT-only driver, and without a valid match in
vf610_nfc_dt_ids the dev wouldn't have been probed in the first place.

I'll let Stefan decide whether he wants it or not, but I see no real
reason for this extra check. 

>  	nfc->variant = (enum vf610_nfc_variant)of_id->data;
>  
>  	for_each_available_child_of_node(nfc->dev->of_node, child) {

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web