* [PATCH] net: ethernet: mediatek: add NULL check on of_match_device() return value
@ 2017-07-07 7:11 Gustavo A. R. Silva
2017-07-07 14:51 ` Matthias Brugger
2017-07-07 14:57 ` Andrew Lunn
0 siblings, 2 replies; 7+ messages in thread
From: Gustavo A. R. Silva @ 2017-07-07 7:11 UTC (permalink / raw)
To: Felix Fietkau, John Crispin, Matthias Brugger
Cc: netdev, linux-arm-kernel, linux-mediatek, 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/net/ethernet/mediatek/mtk_eth_soc.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index adaaafc..6a77dea 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -2408,6 +2408,11 @@ static int mtk_probe(struct platform_device *pdev)
int i;
match = of_match_device(of_mtk_match, &pdev->dev);
+ if (!match) {
+ dev_err(&pdev->dev, "failed to match device\n");
+ return -ENODEV;
+ }
+
soc = (struct mtk_soc_data *)match->data;
eth = devm_kzalloc(&pdev->dev, sizeof(*eth), GFP_KERNEL);
--
2.5.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] net: ethernet: mediatek: add NULL check on of_match_device() return value
2017-07-07 7:11 [PATCH] net: ethernet: mediatek: add NULL check on of_match_device() return value Gustavo A. R. Silva
@ 2017-07-07 14:51 ` Matthias Brugger
2017-07-07 14:57 ` Andrew Lunn
1 sibling, 0 replies; 7+ messages in thread
From: Matthias Brugger @ 2017-07-07 14:51 UTC (permalink / raw)
To: Gustavo A. R. Silva, Felix Fietkau, John Crispin
Cc: netdev, linux-arm-kernel, linux-mediatek, linux-kernel
On 07/07/2017 09:11 AM, Gustavo A. R. Silva wrote:
> 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>
> ---
Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com>
> drivers/net/ethernet/mediatek/mtk_eth_soc.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index adaaafc..6a77dea 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -2408,6 +2408,11 @@ static int mtk_probe(struct platform_device *pdev)
> int i;
>
> match = of_match_device(of_mtk_match, &pdev->dev);
> + if (!match) {
> + dev_err(&pdev->dev, "failed to match device\n");
> + return -ENODEV;
> + }
> +
> soc = (struct mtk_soc_data *)match->data;
>
> eth = devm_kzalloc(&pdev->dev, sizeof(*eth), GFP_KERNEL);
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] net: ethernet: mediatek: add NULL check on of_match_device() return value
2017-07-07 7:11 [PATCH] net: ethernet: mediatek: add NULL check on of_match_device() return value Gustavo A. R. Silva
2017-07-07 14:51 ` Matthias Brugger
@ 2017-07-07 14:57 ` Andrew Lunn
2017-07-07 20:08 ` Gustavo A. R. Silva
1 sibling, 1 reply; 7+ messages in thread
From: Andrew Lunn @ 2017-07-07 14:57 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Felix Fietkau, John Crispin, Matthias Brugger, netdev,
linux-mediatek, linux-kernel, linux-arm-kernel
On Fri, Jul 07, 2017 at 02:11:35AM -0500, Gustavo A. R. Silva wrote:
> 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/net/ethernet/mediatek/mtk_eth_soc.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index adaaafc..6a77dea 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -2408,6 +2408,11 @@ static int mtk_probe(struct platform_device *pdev)
> int i;
>
> match = of_match_device(of_mtk_match, &pdev->dev);
> + if (!match) {
> + dev_err(&pdev->dev, "failed to match device\n");
> + return -ENODEV;
> + }
> +
> soc = (struct mtk_soc_data *)match->data;
Hi Gustavo
I think you are fixing the wrong thing. The soc variable is unused. Also,
const struct of_device_id of_mtk_match[] = {
{ .compatible = "mediatek,mt2701-eth" },
{},
};
So match->data is NULL. This code is all pointless and should be
removed, rather than try to avoid a NULL pointer dereference which can
not actually happen.
Andrew
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] net: ethernet: mediatek: add NULL check on of_match_device() return value
2017-07-07 14:57 ` Andrew Lunn
@ 2017-07-07 20:08 ` Gustavo A. R. Silva
2017-07-07 20:23 ` [PATCH] net: ethernet: mediatek: remove useless code in mtk_probe() Gustavo A. R. Silva
0 siblings, 1 reply; 7+ messages in thread
From: Gustavo A. R. Silva @ 2017-07-07 20:08 UTC (permalink / raw)
To: Andrew Lunn
Cc: Felix Fietkau, John Crispin, Matthias Brugger, netdev,
linux-mediatek, linux-kernel, linux-arm-kernel
Hi Andrew,
Quoting Andrew Lunn <andrew@lunn.ch>:
> On Fri, Jul 07, 2017 at 02:11:35AM -0500, Gustavo A. R. Silva wrote:
>> 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/net/ethernet/mediatek/mtk_eth_soc.c | 5 +++++
>> 1 file changed, 5 insertions(+)
>>
>> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
>> b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
>> index adaaafc..6a77dea 100644
>> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
>> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
>> @@ -2408,6 +2408,11 @@ static int mtk_probe(struct platform_device *pdev)
>> int i;
>>
>> match = of_match_device(of_mtk_match, &pdev->dev);
>> + if (!match) {
>> + dev_err(&pdev->dev, "failed to match device\n");
>> + return -ENODEV;
>> + }
>> +
>> soc = (struct mtk_soc_data *)match->data;
>
> Hi Gustavo
>
> I think you are fixing the wrong thing. The soc variable is unused. Also,
>
> const struct of_device_id of_mtk_match[] = {
> { .compatible = "mediatek,mt2701-eth" },
> {},
> };
>
> So match->data is NULL. This code is all pointless and should be
> removed, rather than try to avoid a NULL pointer dereference which can
> not actually happen.
>
You are right. Thank you for pointing it out. I'll remove that code
and send a new patch shortly.
Thanks!
--
Gustavo A. R. Silva
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] net: ethernet: mediatek: remove useless code in mtk_probe()
2017-07-07 20:08 ` Gustavo A. R. Silva
@ 2017-07-07 20:23 ` Gustavo A. R. Silva
2017-07-08 6:56 ` Sean Wang
2017-07-08 10:28 ` David Miller
0 siblings, 2 replies; 7+ messages in thread
From: Gustavo A. R. Silva @ 2017-07-07 20:23 UTC (permalink / raw)
To: Andrew Lunn, Felix Fietkau, John Crispin, Matthias Brugger
Cc: netdev, linux-arm-kernel, linux-mediatek, linux-kernel,
Gustavo A. R. Silva
Remove useless local variables _match_, _soc_ and the code related.
Notice that
const struct of_device_id of_mtk_match[] = {
{ .compatible = "mediatek,mt2701-eth" },
{},
};
So match->data is NULL.
Suggested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
drivers/net/ethernet/mediatek/mtk_eth_soc.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index adaaafc..b9a5a65 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -2401,15 +2401,10 @@ static int mtk_probe(struct platform_device *pdev)
{
struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
struct device_node *mac_np;
- const struct of_device_id *match;
- struct mtk_soc_data *soc;
struct mtk_eth *eth;
int err;
int i;
- match = of_match_device(of_mtk_match, &pdev->dev);
- soc = (struct mtk_soc_data *)match->data;
-
eth = devm_kzalloc(&pdev->dev, sizeof(*eth), GFP_KERNEL);
if (!eth)
return -ENOMEM;
--
2.5.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] net: ethernet: mediatek: remove useless code in mtk_probe()
2017-07-07 20:23 ` [PATCH] net: ethernet: mediatek: remove useless code in mtk_probe() Gustavo A. R. Silva
@ 2017-07-08 6:56 ` Sean Wang
2017-07-08 10:28 ` David Miller
1 sibling, 0 replies; 7+ messages in thread
From: Sean Wang @ 2017-07-08 6:56 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Andrew Lunn, Felix Fietkau, John Crispin, Matthias Brugger,
netdev, linux-mediatek, linux-kernel, linux-arm-kernel
Hi, Gustavo
It indeed is useless at the current time point.
but actually I will add new SoC support to the driver in the next week,
which requires the variable match :-(
Sean
On Fri, 2017-07-07 at 15:23 -0500, Gustavo A. R. Silva wrote:
> Remove useless local variables _match_, _soc_ and the code related.
>
> Notice that
>
> const struct of_device_id of_mtk_match[] = {
> { .compatible = "mediatek,mt2701-eth" },
> {},
> };
>
> So match->data is NULL.
>
> Suggested-by: Andrew Lunn <andrew@lunn.ch>
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
> ---
> drivers/net/ethernet/mediatek/mtk_eth_soc.c | 5 -----
> 1 file changed, 5 deletions(-)
>
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index adaaafc..b9a5a65 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -2401,15 +2401,10 @@ static int mtk_probe(struct platform_device *pdev)
> {
> struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> struct device_node *mac_np;
> - const struct of_device_id *match;
> - struct mtk_soc_data *soc;
> struct mtk_eth *eth;
> int err;
> int i;
>
> - match = of_match_device(of_mtk_match, &pdev->dev);
> - soc = (struct mtk_soc_data *)match->data;
> -
> eth = devm_kzalloc(&pdev->dev, sizeof(*eth), GFP_KERNEL);
> if (!eth)
> return -ENOMEM;
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] net: ethernet: mediatek: remove useless code in mtk_probe()
2017-07-07 20:23 ` [PATCH] net: ethernet: mediatek: remove useless code in mtk_probe() Gustavo A. R. Silva
2017-07-08 6:56 ` Sean Wang
@ 2017-07-08 10:28 ` David Miller
1 sibling, 0 replies; 7+ messages in thread
From: David Miller @ 2017-07-08 10:28 UTC (permalink / raw)
To: garsilva
Cc: andrew, nbd, blogic, matthias.bgg, netdev, linux-arm-kernel,
linux-mediatek, linux-kernel
From: "Gustavo A. R. Silva" <garsilva@embeddedor.com>
Date: Fri, 7 Jul 2017 15:23:34 -0500
> Remove useless local variables _match_, _soc_ and the code related.
>
> Notice that
>
> const struct of_device_id of_mtk_match[] = {
> { .compatible = "mediatek,mt2701-eth" },
> {},
> };
>
> So match->data is NULL.
>
> Suggested-by: Andrew Lunn <andrew@lunn.ch>
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
Applied, thanks.
If someone needs this they can it back, in a less buggy form.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-07-08 10:28 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-07 7:11 [PATCH] net: ethernet: mediatek: add NULL check on of_match_device() return value Gustavo A. R. Silva
2017-07-07 14:51 ` Matthias Brugger
2017-07-07 14:57 ` Andrew Lunn
2017-07-07 20:08 ` Gustavo A. R. Silva
2017-07-07 20:23 ` [PATCH] net: ethernet: mediatek: remove useless code in mtk_probe() Gustavo A. R. Silva
2017-07-08 6:56 ` Sean Wang
2017-07-08 10:28 ` David Miller
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).