netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] drivers: net: davinci_mdio: fix potential NULL dereference in davinci_mdio_probe()
@ 2020-04-27  9:40 Wei Yongjun
  2020-04-27 15:16 ` David Lechner
  2020-04-29  2:52 ` [PATCH net-next v2] " Wei Yongjun
  0 siblings, 2 replies; 6+ messages in thread
From: Wei Yongjun @ 2020-04-27  9:40 UTC (permalink / raw)
  To: Grygorii Strashko, Andrew Lunn, Wei Yongjun
  Cc: linux-omap, netdev, kernel-janitors

platform_get_resource() may fail and return NULL, so we should
better check it's return value to avoid a NULL pointer dereference
a bit later in the code.

This is detected by Coccinelle semantic patch.

@@
expression pdev, res, n, t, e, e1, e2;
@@

res = \(platform_get_resource\|platform_get_resource_byname\)(pdev, t, n);
+ if (!res)
+   return -EINVAL;
... when != res == NULL
e = devm_ioremap(e1, res->start, e2);

Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
 drivers/net/ethernet/ti/davinci_mdio.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/ti/davinci_mdio.c b/drivers/net/ethernet/ti/davinci_mdio.c
index 38b7f6d35759..702fdc393da0 100644
--- a/drivers/net/ethernet/ti/davinci_mdio.c
+++ b/drivers/net/ethernet/ti/davinci_mdio.c
@@ -397,6 +397,8 @@ static int davinci_mdio_probe(struct platform_device *pdev)
 	data->dev = dev;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
 	data->regs = devm_ioremap(dev, res->start, resource_size(res));
 	if (!data->regs)
 		return -ENOMEM;






^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] drivers: net: davinci_mdio: fix potential NULL dereference in davinci_mdio_probe()
  2020-04-27  9:40 [PATCH net-next] drivers: net: davinci_mdio: fix potential NULL dereference in davinci_mdio_probe() Wei Yongjun
@ 2020-04-27 15:16 ` David Lechner
  2020-04-29  2:52 ` [PATCH net-next v2] " Wei Yongjun
  1 sibling, 0 replies; 6+ messages in thread
From: David Lechner @ 2020-04-27 15:16 UTC (permalink / raw)
  To: Wei Yongjun, Grygorii Strashko, Andrew Lunn
  Cc: linux-omap, netdev, kernel-janitors

On 4/27/20 4:40 AM, Wei Yongjun wrote:
> platform_get_resource() may fail and return NULL, so we should
> better check it's return value to avoid a NULL pointer dereference
> a bit later in the code.
> 
> This is detected by Coccinelle semantic patch.
> 
> @@
> expression pdev, res, n, t, e, e1, e2;
> @@
> 
> res = \(platform_get_resource\|platform_get_resource_byname\)(pdev, t, n);
> + if (!res)
> +   return -EINVAL;
> ... when != res == NULL
> e = devm_ioremap(e1, res->start, e2);
> 
> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> ---
>   drivers/net/ethernet/ti/davinci_mdio.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/net/ethernet/ti/davinci_mdio.c b/drivers/net/ethernet/ti/davinci_mdio.c
> index 38b7f6d35759..702fdc393da0 100644
> --- a/drivers/net/ethernet/ti/davinci_mdio.c
> +++ b/drivers/net/ethernet/ti/davinci_mdio.c
> @@ -397,6 +397,8 @@ static int davinci_mdio_probe(struct platform_device *pdev)
>   	data->dev = dev;
>   
>   	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	if (!res)
> +		return -EINVAL;
>   	data->regs = devm_ioremap(dev, res->start, resource_size(res));
>   	if (!data->regs)
>   		return -ENOMEM;
> 

Could we use devm_platform_ioremap_resource() instead?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH net-next v2] drivers: net: davinci_mdio: fix potential NULL dereference in davinci_mdio_probe()
  2020-04-27  9:40 [PATCH net-next] drivers: net: davinci_mdio: fix potential NULL dereference in davinci_mdio_probe() Wei Yongjun
  2020-04-27 15:16 ` David Lechner
@ 2020-04-29  2:52 ` Wei Yongjun
  2020-05-01 22:28   ` David Miller
  1 sibling, 1 reply; 6+ messages in thread
From: Wei Yongjun @ 2020-04-29  2:52 UTC (permalink / raw)
  To: Grygorii Strashko, David Lechner, Wei Yongjun
  Cc: linux-omap, netdev, kernel-janitors

platform_get_resource() may fail and return NULL, so we should
better check it's return value to avoid a NULL pointer dereference
since devm_ioremap() does not check input parameters for null.

This is detected by Coccinelle semantic patch.

@@
expression pdev, res, n, t, e, e1, e2;
@@

res = \(platform_get_resource\|platform_get_resource_byname\)(pdev, t, n);
+ if (!res)
+   return -EINVAL;
... when != res == NULL
e = devm_ioremap(e1, res->start, e2);

Fixes: 03f66f067560 ("net: ethernet: ti: davinci_mdio: use devm_ioremap()")
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com>
---
v1 -> v2: add fixes and reviewed-by
---
 drivers/net/ethernet/ti/davinci_mdio.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/ti/davinci_mdio.c b/drivers/net/ethernet/ti/davinci_mdio.c
index 38b7f6d35759..702fdc393da0 100644
--- a/drivers/net/ethernet/ti/davinci_mdio.c
+++ b/drivers/net/ethernet/ti/davinci_mdio.c
@@ -397,6 +397,8 @@ static int davinci_mdio_probe(struct platform_device *pdev)
 	data->dev = dev;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
 	data->regs = devm_ioremap(dev, res->start, resource_size(res));
 	if (!data->regs)
 		return -ENOMEM;




^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v2] drivers: net: davinci_mdio: fix potential NULL dereference in davinci_mdio_probe()
  2020-04-29  2:52 ` [PATCH net-next v2] " Wei Yongjun
@ 2020-05-01 22:28   ` David Miller
  0 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2020-05-01 22:28 UTC (permalink / raw)
  To: weiyongjun1; +Cc: grygorii.strashko, david, linux-omap, netdev, kernel-janitors

From: Wei Yongjun <weiyongjun1@huawei.com>
Date: Wed, 29 Apr 2020 02:52:20 +0000

> platform_get_resource() may fail and return NULL, so we should
> better check it's return value to avoid a NULL pointer dereference
> since devm_ioremap() does not check input parameters for null.
> 
> This is detected by Coccinelle semantic patch.
> 
> @@
> expression pdev, res, n, t, e, e1, e2;
> @@
> 
> res = \(platform_get_resource\|platform_get_resource_byname\)(pdev, t, n);
> + if (!res)
> +   return -EINVAL;
> ... when != res == NULL
> e = devm_ioremap(e1, res->start, e2);
> 
> Fixes: 03f66f067560 ("net: ethernet: ti: davinci_mdio: use devm_ioremap()")
> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com>

Applied.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] drivers: net: davinci_mdio: fix potential NULL dereference in davinci_mdio_probe()
  2020-04-28  3:25 [PATCH net-next] " weiyongjun (A)
@ 2020-04-28  7:30 ` Grygorii Strashko
  0 siblings, 0 replies; 6+ messages in thread
From: Grygorii Strashko @ 2020-04-28  7:30 UTC (permalink / raw)
  To: weiyongjun (A), David Lechner, Andrew Lunn
  Cc: linux-omap, netdev, kernel-janitors



On 28/04/2020 06:25, weiyongjun (A) wrote:
>>
>> On 4/27/20 4:40 AM, Wei Yongjun wrote:
>>> platform_get_resource() may fail and return NULL, so we should better
>>> check it's return value to avoid a NULL pointer dereference a bit
>>> later in the code.
>>>
>>> This is detected by Coccinelle semantic patch.
>>>
>>> @@
>>> expression pdev, res, n, t, e, e1, e2; @@
>>>
>>> res = \(platform_get_resource\|platform_get_resource_byname\)(pdev, t, n);
>>> + if (!res)
>>> +   return -EINVAL;
>>> ... when != res == NULL
>>> e = devm_ioremap(e1, res->start, e2);
>>>
>>> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
>>> ---
>>
>> Could we use devm_platform_ioremap_resource() instead?
> 
> We cannot use devm_platform_ioremap_resource() here, see
> Commit 03f66f067560 ("net: ethernet: ti: davinci_mdio: use devm_ioremap()")

Correct, could you add fixed tag as above commit actually introduced an issue:
devm_ioremap_resource() checks input parameters for null.
  
Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com>

-- 
Best regards,
grygorii

^ permalink raw reply	[flat|nested] 6+ messages in thread

* re: [PATCH net-next] drivers: net: davinci_mdio: fix potential NULL dereference in davinci_mdio_probe()
@ 2020-04-28  3:25 weiyongjun (A)
  2020-04-28  7:30 ` Grygorii Strashko
  0 siblings, 1 reply; 6+ messages in thread
From: weiyongjun (A) @ 2020-04-28  3:25 UTC (permalink / raw)
  To: David Lechner, Grygorii Strashko, Andrew Lunn
  Cc: linux-omap, netdev, kernel-janitors

> 
> On 4/27/20 4:40 AM, Wei Yongjun wrote:
> > platform_get_resource() may fail and return NULL, so we should better
> > check it's return value to avoid a NULL pointer dereference a bit
> > later in the code.
> >
> > This is detected by Coccinelle semantic patch.
> >
> > @@
> > expression pdev, res, n, t, e, e1, e2; @@
> >
> > res = \(platform_get_resource\|platform_get_resource_byname\)(pdev, t, n);
> > + if (!res)
> > +   return -EINVAL;
> > ... when != res == NULL
> > e = devm_ioremap(e1, res->start, e2);
> >
> > Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> > ---
> 
> Could we use devm_platform_ioremap_resource() instead?

We cannot use devm_platform_ioremap_resource() here, see
Commit 03f66f067560 ("net: ethernet: ti: davinci_mdio: use devm_ioremap()")

Regards

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-05-01 22:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-27  9:40 [PATCH net-next] drivers: net: davinci_mdio: fix potential NULL dereference in davinci_mdio_probe() Wei Yongjun
2020-04-27 15:16 ` David Lechner
2020-04-29  2:52 ` [PATCH net-next v2] " Wei Yongjun
2020-05-01 22:28   ` David Miller
2020-04-28  3:25 [PATCH net-next] " weiyongjun (A)
2020-04-28  7:30 ` Grygorii Strashko

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).