]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net: dsa: ksz: ksz8795_spi_probe: fix possible NULL pointer dereference
authorOleksij Rempel <o.rempel@pengutronix.de>
Thu, 29 Apr 2021 11:08:32 +0000 (13:08 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 29 Apr 2021 22:54:35 +0000 (15:54 -0700)
Fix possible NULL pointer dereference in case devm_kzalloc() failed to
allocate memory

Fixes: 9dd2cf8dc0bd ("net: dsa: microchip: Add Microchip KSZ8863 SPI based driver support")
Reported-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/microchip/ksz8795_spi.c

index 85ba12aa82d818ac24f8719dc0043c3c4c113e43..ea7550d1b634d416f207e256335ff458111a847e 100644 (file)
@@ -41,6 +41,9 @@ static int ksz8795_spi_probe(struct spi_device *spi)
        int i, ret = 0;
 
        ksz8 = devm_kzalloc(&spi->dev, sizeof(struct ksz8), GFP_KERNEL);
+       if (!ksz8)
+               return -ENOMEM;
+
        ksz8->priv = spi;
 
        dev = ksz_switch_alloc(&spi->dev, ksz8);