All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <garsilva@embeddedor.com>
To: Andrew Lunn <andrew@lunn.ch>
Cc: Felix Fietkau <nbd@openwrt.org>,
	John Crispin <blogic@openwrt.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	netdev@vger.kernel.org, linux-mediatek@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] net: ethernet: mediatek: add NULL check on of_match_device() return value
Date: Fri, 07 Jul 2017 15:08:31 -0500	[thread overview]
Message-ID: <20170707150831.Horde.MYtEbXeqxGS-hTg2bUv3DWt@gator4166.hostgator.com> (raw)
In-Reply-To: <20170707145717.GG24237@lunn.ch>

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

WARNING: multiple messages have this Message-ID (diff)
From: garsilva@embeddedor.com (Gustavo A. R. Silva)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] net: ethernet: mediatek: add NULL check on of_match_device() return value
Date: Fri, 07 Jul 2017 15:08:31 -0500	[thread overview]
Message-ID: <20170707150831.Horde.MYtEbXeqxGS-hTg2bUv3DWt@gator4166.hostgator.com> (raw)
In-Reply-To: <20170707145717.GG24237@lunn.ch>

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

  reply	other threads:[~2017-07-07 20:09 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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  7:11 ` Gustavo A. R. Silva
2017-07-07 14:51 ` Matthias Brugger
2017-07-07 14:51   ` Matthias Brugger
2017-07-07 14:57 ` Andrew Lunn
2017-07-07 14:57   ` Andrew Lunn
2017-07-07 20:08   ` Gustavo A. R. Silva [this message]
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-07 20:23       ` Gustavo A. R. Silva
2017-07-08  6:56       ` Sean Wang
2017-07-08  6:56         ` Sean Wang
2017-07-08  6:56         ` Sean Wang
2017-07-08 10:28       ` David Miller
2017-07-08 10:28         ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170707150831.Horde.MYtEbXeqxGS-hTg2bUv3DWt@gator4166.hostgator.com \
    --to=garsilva@embeddedor.com \
    --cc=andrew@lunn.ch \
    --cc=blogic@openwrt.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=nbd@openwrt.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.