]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net: ll_temac: check the return value of devm_kmalloc()
authorXiaoke Wang <xkernel.wang@foxmail.com>
Fri, 18 Feb 2022 02:19:39 +0000 (10:19 +0800)
committerDavid S. Miller <davem@davemloft.net>
Fri, 18 Feb 2022 12:00:44 +0000 (12:00 +0000)
devm_kmalloc() returns a pointer to allocated memory on success, NULL
on failure. While lp->indirect_lock is allocated by devm_kmalloc()
without proper check. It is better to check the value of it to
prevent potential wrong memory access.

Fixes: abb9098d3898 ("net: ll_temac: Support indirect_mutex share within TEMAC IP")
Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/xilinx/ll_temac_main.c

index b900ab5aef2a8fa578c1649c0f1fee4fdfb415a7..64c7e26c3b75488f1ffd7dc6a33f308bea0299a6 100644 (file)
@@ -1433,6 +1433,8 @@ static int temac_probe(struct platform_device *pdev)
                lp->indirect_lock = devm_kmalloc(&pdev->dev,
                                                 sizeof(*lp->indirect_lock),
                                                 GFP_KERNEL);
+               if (!lp->indirect_lock)
+                       return -ENOMEM;
                spin_lock_init(lp->indirect_lock);
        }