From: Trent Piepho <xyzzy@speakeasy.org>
To: Adrian Bunk <bunk@stusta.de>
Cc: Michal CIJOML Semler <cijoml@volny.cz>,
Markus Rechberger <markus.rechberger@amd.com>,
Mauro Carvalho Chehab <mchehab@infradead.org>,
v4l-dvb-maintainer@linuxtv.org, linux-kernel@vger.kernel.org
Subject: Re: [v4l-dvb-maintainer] drivers/media/dvb/dvb-core/dvb_net.c: check-after-use
Date: Fri, 15 Jun 2007 16:58:04 -0700 (PDT) [thread overview]
Message-ID: <Pine.LNX.4.58.0706151621000.4914@shell4.speakeasy.net> (raw)
In-Reply-To: <20070615210031.GK3588@stusta.de>
On Fri, 15 Jun 2007, Adrian Bunk wrote:
> The Coverity checker spotted the following obvious check-after-use in
> drivers/media/dvb/dvb-core/dvb_net.c:
I spotted it before the patch was even applied:
http://www.linuxtv.org/pipermail/v4l-dvb-maintainer/2007-April/003917.html
If only coverity would get people to fix their bugs too.
I'm almost certain the check for !dvbdev ( = file->private_data) is not
necessary.
If you trace it, starting from the beginning:
dvb device is created:
dvbdev.c:425 cdev_init(&dvb_device_cdev, &dvb_device_fops);
dvb_device_fops defined:
dvbdev.c:117 static struct file_operations dvb_device_fops =
dvbdev.c:118 {
dvbdev.c:119 .owner = THIS_MODULE,
dvbdev.c:120 .open = dvb_device_open,
dvbdev.c:121 };
BTW, this struct should be const, no? In fact, why not make it a static
local to "__init init_dvbdev()", the only place it's used? That way it
will go into the init.data section, right?
Anyway, the relevant code for dvb_device_open:
dvbdev.c:87 static int dvb_device_open(struct inode *inode, struct file *file)
dvbdev.c:91 dvbdev = dvbdev_find_device (iminor(inode));
dvbdev.c:93 if (dvbdev && dvbdev->fops) {
dvbdev.c:101 file->private_data = dvbdev;
dvbdev.c:111 return err;
dvbdev.c:112 }
dvbdev.c:113 return -ENODEV;
So file->private_data must be non-NULL when the file is opened, or the open
function for the dvb device will return ENODEV.
The only code code in the dvb tree that assigns to private_data that I
could find is in the open function for dmx devices, and it doesn't apply to
dvb net devices and can't set private_data to NULL anyway.
So, if there file->private_data starts as non-NULL, and there is no code
that changes it, it can't ever be non-NULL, right?
BTW, I hate checks for a pointer being NULL if it's not actually part of
the design that the pointer can be NULL. It just clutters the code, as
other programmers see the check and they need to handle the pointer being
NULL too. And if there is a bug and the pointer is NULL, the check doesn't
fix the bug it just masks it. The farther it is from a bug's cause to the
point it's detected, the harder it is to fix.
Here is a patch to fix it. Actually, there is still a check-after-use
after the patch, but is Coverity smart enough to find it?
--------------------------------------------------------------------------
diff -r 2f04637aaea8 linux/drivers/media/dvb/dvb-core/dvb_net.c
--- a/linux/drivers/media/dvb/dvb-core/dvb_net.c Fri Jun 08 08:58:41 2007 -0300
+++ b/linux/drivers/media/dvb/dvb-core/dvb_net.c Fri Jun 15 15:34:08 2007 -0700
@@ -1502,18 +1502,9 @@ static int dvb_net_close(struct inode *i
struct dvb_device *dvbdev = file->private_data;
struct dvb_net *dvbnet = dvbdev->priv;
- if (!dvbdev)
- return -ENODEV;
-
- if ((file->f_flags & O_ACCMODE) == O_RDONLY) {
- dvbdev->readers++;
- } else {
- dvbdev->writers++;
- }
-
- dvbdev->users++;
-
- if(dvbdev->users == 1 && dvbnet->exit==1) {
+ dvb_generic_release(inode, file);
+
+ if(dvbdev->users == 1 && dvbnet->exit == 1) {
fops_put(file->f_op);
file->f_op = NULL;
wake_up(&dvbdev->wait_queue);
prev parent reply other threads:[~2007-06-15 23:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-15 21:00 Adrian Bunk
2007-06-15 23:58 ` Trent Piepho [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=Pine.LNX.4.58.0706151621000.4914@shell4.speakeasy.net \
--to=xyzzy@speakeasy.org \
--cc=bunk@stusta.de \
--cc=cijoml@volny.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=markus.rechberger@amd.com \
--cc=mchehab@infradead.org \
--cc=v4l-dvb-maintainer@linuxtv.org \
/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
all inboxes | Powered by JetHome®