[PATCH] net: ethernet: mediatek: add NULL check on of_match_device() return value
Matthias Brugger
matthias.bgg at gmail.com
Fri Jul 7 07:51:17 PDT 2017
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 at embeddedor.com>
> ---
Reviewed-by: Matthias Brugger <matthias.bgg at 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);
>
More information about the linux-arm-kernel
mailing list