From: Dan Carpenter <dan.carpenter@oracle.com>
To: Michael Straube <straube.linux@gmail.com>
Cc: gregkh@linuxfoundation.org, devel@driverdev.osuosl.org,
linux@wolf-entwicklungen.de, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: pi433: fix potential null dereference
Date: Mon, 26 Nov 2018 12:47:45 +0300 [thread overview]
Message-ID: <20181126094745.GF3088@unbuntlaptop> (raw)
In-Reply-To: <20181125092225.10188-1-straube.linux@gmail.com>
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
prev parent reply other threads:[~2018-11-26 9:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-25 9:22 [PATCH] staging: pi433: fix potential null dereference Michael Straube
2018-11-26 9:47 ` Dan Carpenter [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181126094745.GF3088@unbuntlaptop \
--to=dan.carpenter@oracle.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@wolf-entwicklungen.de \
--cc=straube.linux@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox