[PATCH] net: xilinx: fix potential NULL dereference in temac_probe()

Florian Fainelli f.fainelli at gmail.com
Mon Jul 13 22:55:32 EDT 2020



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 at 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



More information about the linux-arm-kernel mailing list