linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: pi433: fix potential null dereference
@ 2018-11-25  9:22 Michael Straube
  2018-11-26  9:47 ` Dan Carpenter
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Straube @ 2018-11-25  9:22 UTC (permalink / raw)
  To: gregkh; +Cc: linux, devel, linux-kernel, Michael Straube

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>
---
 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);
-- 
2.19.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] staging: pi433: fix potential null dereference
  2018-11-25  9:22 [PATCH] staging: pi433: fix potential null dereference Michael Straube
@ 2018-11-26  9:47 ` Dan Carpenter
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2018-11-26  9:47 UTC (permalink / raw)
  To: Michael Straube; +Cc: gregkh, devel, linux, linux-kernel

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-11-26  9:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-25  9:22 [PATCH] staging: pi433: fix potential null dereference Michael Straube
2018-11-26  9:47 ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).