staging: pi433: fix potential null dereference
authorMichael Straube <straube.linux@gmail.com>
Sun, 25 Nov 2018 09:22:25 +0000 (10:22 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 26 Nov 2018 19:59:05 +0000 (20:59 +0100)
Add a test for successful call to cdev_alloc() to avoid
potential null dereference. Issue reported by smatch.

Signed-off-by: Michael Straube <straube.linux@gmail.com>
Fixes: 874bcba65f9a ("staging: pi433: New driver")
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/pi433/pi433_if.c

index 786478671190da8f9485cabba5006fb671c93236..d72de21050533de3b9840d87c277a016567ea5a3 100644 (file)
@@ -1245,6 +1245,10 @@ static int pi433_probe(struct spi_device *spi)
 
        /* create cdev */
        device->cdev = cdev_alloc();
+       if (!device->cdev) {
+               dev_dbg(device->dev, "allocation of cdev failed");
+               goto cdev_failed;
+       }
        device->cdev->owner = THIS_MODULE;
        cdev_init(device->cdev, &pi433_fops);
        retval = cdev_add(device->cdev, device->devt, 1);