* [PATCH] mtd: nand: vf610_nfc: add NULL check on of_match_device() return value
@ 2017-07-07 6:59 Gustavo A. R. Silva
2017-07-17 20:46 ` Boris Brezillon
0 siblings, 1 reply; 3+ messages in thread
From: Gustavo A. R. Silva @ 2017-07-07 6:59 UTC (permalink / raw)
To: Stefan Agner, Boris Brezillon, Richard Weinberger,
David Woodhouse, Brian Norris, Marek Vasut, Cyrille Pitchen
Cc: linux-mtd, linux-kernel, Gustavo A. R. Silva
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] mtd: nand: vf610_nfc: add NULL check on of_match_device() return value
2017-07-07 6:59 [PATCH] mtd: nand: vf610_nfc: add NULL check on of_match_device() return value Gustavo A. R. Silva
@ 2017-07-17 20:46 ` Boris Brezillon
2017-07-17 20:49 ` Marek Vasut
0 siblings, 1 reply; 3+ messages in thread
From: Boris Brezillon @ 2017-07-17 20:46 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Stefan Agner, Richard Weinberger, David Woodhouse, Brian Norris,
Marek Vasut, Cyrille Pitchen, linux-mtd, linux-kernel
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) {
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mtd: nand: vf610_nfc: add NULL check on of_match_device() return value
2017-07-17 20:46 ` Boris Brezillon
@ 2017-07-17 20:49 ` Marek Vasut
0 siblings, 0 replies; 3+ messages in thread
From: Marek Vasut @ 2017-07-17 20:49 UTC (permalink / raw)
To: Boris Brezillon, Gustavo A. R. Silva
Cc: Stefan Agner, Richard Weinberger, David Woodhouse, Brian Norris,
Cyrille Pitchen, linux-mtd, linux-kernel
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-07-17 20:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-07 6:59 [PATCH] mtd: nand: vf610_nfc: add NULL check on of_match_device() return value Gustavo A. R. Silva
2017-07-17 20:46 ` Boris Brezillon
2017-07-17 20:49 ` Marek Vasut
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox