netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: xilinx: fix potential NULL dereference in temac_probe()
@ 2020-07-14  2:23 Xu Wang
  2020-07-14  2:55 ` Florian Fainelli
  0 siblings, 1 reply; 3+ messages in thread
From: Xu Wang @ 2020-07-14  2:23 UTC (permalink / raw)
  To: davem, kuba, michal.simek, esben, hkallweit1, f.fainelli, vulab,
	weiyongjun1, netdev, linux-arm-kernel
  Cc: linux-kernel

platform_get_resource() may return NULL, add proper
check to avoid potential NULL dereferencing.

Signed-off-by: Xu Wang <vulab@iscas.ac.cn>
---
 drivers/net/ethernet/xilinx/ll_temac_main.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/xilinx/ll_temac_main.c b/drivers/net/ethernet/xilinx/ll_temac_main.c
index 929244064abd..85a767fa2ecf 100644
--- a/drivers/net/ethernet/xilinx/ll_temac_main.c
+++ b/drivers/net/ethernet/xilinx/ll_temac_main.c
@@ -1408,6 +1408,8 @@ static int temac_probe(struct platform_device *pdev)
 
 	/* map device registers */
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
 	lp->regs = devm_ioremap(&pdev->dev, res->start,
 					resource_size(res));
 	if (!lp->regs) {
@@ -1503,6 +1505,8 @@ static int temac_probe(struct platform_device *pdev)
 	} else if (pdata) {
 		/* 2nd memory resource specifies DMA registers */
 		res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+		if (!res)
+			return -EINVAL;
 		lp->sdma_regs = devm_ioremap(&pdev->dev, res->start,
 						     resource_size(res));
 		if (!lp->sdma_regs) {
-- 
2.17.1


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

* Re: [PATCH] net: xilinx: fix potential NULL dereference in temac_probe()
  2020-07-14  2:23 [PATCH] net: xilinx: fix potential NULL dereference in temac_probe() Xu Wang
@ 2020-07-14  2:55 ` Florian Fainelli
  0 siblings, 0 replies; 3+ messages in thread
From: Florian Fainelli @ 2020-07-14  2:55 UTC (permalink / raw)
  To: Xu Wang, davem, kuba, michal.simek, esben, hkallweit1,
	weiyongjun1, netdev, linux-arm-kernel
  Cc: linux-kernel



On 7/13/2020 7:23 PM, Xu Wang wrote:
> platform_get_resource() may return NULL, add proper
> check to avoid potential NULL dereferencing.
> 
> Signed-off-by: Xu Wang <vulab@iscas.ac.cn>
> ---

If you use devm_ioremap_resource() you can remove the !res check
entirely which would be equally acceptable as a fix.

>  drivers/net/ethernet/xilinx/ll_temac_main.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/net/ethernet/xilinx/ll_temac_main.c b/drivers/net/ethernet/xilinx/ll_temac_main.c
> index 929244064abd..85a767fa2ecf 100644
> --- a/drivers/net/ethernet/xilinx/ll_temac_main.c
> +++ b/drivers/net/ethernet/xilinx/ll_temac_main.c
> @@ -1408,6 +1408,8 @@ static int temac_probe(struct platform_device *pdev)
>  
>  	/* map device registers */
>  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	if (!res)
> +		return -EINVAL;
>  	lp->regs = devm_ioremap(&pdev->dev, res->start,
>  					resource_size(res));
>  	if (!lp->regs) {
> @@ -1503,6 +1505,8 @@ static int temac_probe(struct platform_device *pdev)
>  	} else if (pdata) {
>  		/* 2nd memory resource specifies DMA registers */
>  		res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
> +		if (!res)
> +			return -EINVAL;
>  		lp->sdma_regs = devm_ioremap(&pdev->dev, res->start,
>  						     resource_size(res));
>  		if (!lp->sdma_regs) {
> 

-- 
Florian

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

* Re: [PATCH] net: xilinx: fix potential NULL dereference in temac_probe()
@ 2020-07-14  9:42 Markus Elfring
  0 siblings, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2020-07-14  9:42 UTC (permalink / raw)
  To: Florian Fainelli, Xu Wang, linux-arm-kernel, netdev
  Cc: linux-kernel, David S. Miller, Esben Haabendal, Heiner Kallweit,
	Jakub Kicinski, Michal Simek, Wei Yongjun

> If you use devm_ioremap_resource() you can remove the !res check
> entirely which would be equally acceptable as a fix.

Would you like to use the wrapper function “devm_platform_get_and_ioremap_resource” then?
https://elixir.bootlin.com/linux/v5.8-rc4/source/drivers/base/platform.c#L66
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/base/platform.c?id=0dc589da873b58b70f4caf4b070fb0cf70fdd1dc#n66

Regards,
Markus

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

end of thread, other threads:[~2020-07-14  9:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-14  2:23 [PATCH] net: xilinx: fix potential NULL dereference in temac_probe() Xu Wang
2020-07-14  2:55 ` Florian Fainelli
2020-07-14  9:42 Markus Elfring

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