lkml.org 
[lkml]   [2018]   [Nov]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] staging: pi433: fix potential null dereference
On Sun, Nov 25, 2018 at 10:22:25AM +0100, Michael Straube wrote:
> Add a test for successful call to cdev_alloc() to avoid
> potential null dereference. Issue reported by smatch.
>

Fixes: 874bcba65f9a ("staging: pi433: New driver")


> Signed-off-by: Michael Straube <straube.linux@gmail.com>
> ---
> drivers/staging/pi433/pi433_if.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/staging/pi433/pi433_if.c b/drivers/staging/pi433/pi433_if.c
> index 786478671190..d72de2105053 100644
> --- a/drivers/staging/pi433/pi433_if.c
> +++ b/drivers/staging/pi433/pi433_if.c
> @@ -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

\
 
 \ /
  Last update: 2018-11-26 10:49    [W:0.038 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site