staging: pi433: fix potential null dereference
PATCH 1/1 staging: pi433: fix potential null dereference
Add a test for successful call to cdev_alloc() to avoid potential null dereference. Issue reported by smatch.
Signed-off-by Michael Straube <[email protected]>
--- drivers/staging/pi433/pi433_if.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/staging/pi433/pi433_if.c +4 -0
@@ -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 );
Signature · 1 line
2.19.2
Quoted 3 lines · Michael Straube
Add a test for successful call to
cdev_alloc()to avoid potential null dereference. Issue reported by smatch.
Fixes 874bcba65f9a ("staging: pi433: New driver")
Quoted 10 lines
Signed-off-by Michael Straube <[email protected]>--- drivers/staging/pi433/pi433_if.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/staging/pi433/pi433_if.c +0
-0
drivers/staging/pi433/pi433_if.c static int pi433_probe(struct spi_device *spi) · line 1254
Quoted 10 lines
drivers/staging/pi433/pi433_if.c +4
-0@@ -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 );
There is a second related bug here if we cdev_add() fails then we should call cdev_del(device->cdev). (cdev_del() does not take a NULL cdev pointer).
regards,
dan carpenter