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


Groups > linux.kernel > #1683234

Re: [PATCH] net: ethernet: mediatek: add NULL check on of_match_device() return value

From Andrew Lunn <andrew@lunn.ch>
Newsgroups linux.kernel
Subject Re: [PATCH] net: ethernet: mediatek: add NULL check on of_match_device() return value
Date 2017-07-07 17:00 +0200
Message-ID <u0CTF-5qc-25@gated-at.bofh.it> (permalink)
References <u0vIt-ww-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] net: ethernet: mediatek: add NULL check on of_match_device()  return value "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-07-07 09:20 +0200
  Re: [PATCH] net: ethernet: mediatek: add NULL check on  of_match_device() return value Andrew Lunn <andrew@lunn.ch> - 2017-07-07 17:00 +0200
    Re: [PATCH] net: ethernet: mediatek: add NULL check on  of_match_device() return value "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-07-07 22:10 +0200
      [PATCH] net: ethernet: mediatek: remove useless code in mtk_probe() "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-07-07 22:30 +0200
        Re: [PATCH] net: ethernet: mediatek: remove useless code in  mtk_probe() Sean Wang <sean.wang@mediatek.com> - 2017-07-08 09:00 +0200
        Re: [PATCH] net: ethernet: mediatek: remove useless code in  mtk_probe() David Miller <davem@davemloft.net> - 2017-07-08 12:30 +0200
  Re: [PATCH] net: ethernet: mediatek: add NULL check on  of_match_device() return value Matthias Brugger <matthias.bgg@gmail.com> - 2017-07-07 17:00 +0200

csiph-web