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


Groups > linux.kernel > #1568151 > unrolled thread

[PATCH] Net: ethernet: mediatek - Fix possible NULL derefrence.

Started byShailendra Verma <shailendra.v@samsung.com>
First post2017-01-27 12:30 +0100
Last post2017-01-27 17:30 +0100
Articles 3 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH] Net: ethernet: mediatek - Fix possible NULL derefrence. Shailendra Verma <shailendra.v@samsung.com> - 2017-01-27 12:30 +0100
    Re: [PATCH] Net: ethernet: mediatek - Fix possible NULL derefrence. Corentin Labbe <clabbe.montjoie@gmail.com> - 2017-01-27 14:00 +0100
      Re: [PATCH] Net: ethernet: mediatek - Fix possible NULL derefrence. David Miller <davem@davemloft.net> - 2017-01-27 17:30 +0100

#1568151 — [PATCH] Net: ethernet: mediatek - Fix possible NULL derefrence.

FromShailendra Verma <shailendra.v@samsung.com>
Date2017-01-27 12:30 +0100
Subject[PATCH] Net: ethernet: mediatek - Fix possible NULL derefrence.
Message-ID<t4cT7-3sv-1@gated-at.bofh.it>
of_match_device could return NULL, and so can cause a NULL
pointer dereference later.

Signed-off-by: Shailendra Verma <shailendra.v@samsung.com>
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 4a62ffd..4495b7b 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -2369,6 +2369,10 @@ 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, "Error: No device match found\n");
+		return -ENODEV;
+	}
 	soc = (struct mtk_soc_data *)match->data;
 
 	eth = devm_kzalloc(&pdev->dev, sizeof(*eth), GFP_KERNEL);
-- 
1.7.9.5

[toc] | [next] | [standalone]


#1568341

FromCorentin Labbe <clabbe.montjoie@gmail.com>
Date2017-01-27 14:00 +0100
Message-ID<t4eie-4g8-9@gated-at.bofh.it>
In reply to#1568151
On Fri, Jan 27, 2017 at 04:49:40PM +0530, Shailendra Verma wrote:
> of_match_device could return NULL, and so can cause a NULL
> pointer dereference later.
> 
> Signed-off-by: Shailendra Verma <shailendra.v@samsung.com>
> ---
>  drivers/net/ethernet/mediatek/mtk_eth_soc.c |    4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index 4a62ffd..4495b7b 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -2369,6 +2369,10 @@ 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, "Error: No device match found\n");
> +		return -ENODEV;
> +	}
>  	soc = (struct mtk_soc_data *)match->data;
>  
>  	eth = devm_kzalloc(&pdev->dev, sizeof(*eth), GFP_KERNEL);
> -- 

Hello

You could use of_device_get_match_data() and simplifiy code

Regards
Corentin Labbe

[toc] | [prev] | [next] | [standalone]


#1568487

FromDavid Miller <davem@davemloft.net>
Date2017-01-27 17:30 +0100
Message-ID<t4hzs-6qz-21@gated-at.bofh.it>
In reply to#1568341
From: Corentin Labbe <clabbe.montjoie@gmail.com>
Date: Fri, 27 Jan 2017 13:44:49 +0100

> On Fri, Jan 27, 2017 at 04:49:40PM +0530, Shailendra Verma wrote:
>> of_match_device could return NULL, and so can cause a NULL
>> pointer dereference later.
>> 
>> Signed-off-by: Shailendra Verma <shailendra.v@samsung.com>
>> ---
>>  drivers/net/ethernet/mediatek/mtk_eth_soc.c |    4 ++++
>>  1 file changed, 4 insertions(+)
>> 
>> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
>> index 4a62ffd..4495b7b 100644
>> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
>> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
>> @@ -2369,6 +2369,10 @@ 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, "Error: No device match found\n");
>> +		return -ENODEV;
>> +	}
>>  	soc = (struct mtk_soc_data *)match->data;
>>  
>>  	eth = devm_kzalloc(&pdev->dev, sizeof(*eth), GFP_KERNEL);
>> -- 
> 
> Hello
> 
> You could use of_device_get_match_data() and simplifiy code

Agreed.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web