net: ethernet: ti: cpsw: add missing sanity check
authorJohan Hovold <johan@kernel.org>
Thu, 17 Nov 2016 16:40:03 +0000 (17:40 +0100)
committerDavid S. Miller <davem@davemloft.net>
Fri, 18 Nov 2016 18:48:53 +0000 (13:48 -0500)
Make sure to check for allocation failures before dereferencing a
NULL-pointer during probe.

Fixes: 649a1688c960 ("net: ethernet: ti: cpsw: create common struct to
hold shared driver data")
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/ti/cpsw.c

index 11b2daef3158a997c1d19009286aec3e68628658..1387299030e417c3cefde84f3d225d84edb1780a 100644 (file)
@@ -2588,6 +2588,9 @@ static int cpsw_probe(struct platform_device *pdev)
        int irq;
 
        cpsw = devm_kzalloc(&pdev->dev, sizeof(struct cpsw_common), GFP_KERNEL);
+       if (!cpsw)
+               return -ENOMEM;
+
        cpsw->dev = &pdev->dev;
 
        ndev = alloc_etherdev_mq(sizeof(struct cpsw_priv), CPSW_MAX_QUEUES);