public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Simon Arlott <simon@fire.lp0.eu>
Cc: linux-kernel@vger.kernel.org, mchehab@infradead.org,
	linux-dvb@linuxtv.org
Subject: Re: [PATCH] dvb-core: Fix potential mutex_unlock without mutex_lock in dvb_dvr_read
Date: Thu, 30 Apr 2009 13:18:18 -0700	[thread overview]
Message-ID: <20090430131818.d8aded42.akpm@linux-foundation.org> (raw)
In-Reply-To: <49F0A61D.1010002@simon.arlott.org.uk>

On Thu, 23 Apr 2009 18:32:13 +0100
Simon Arlott <simon@fire.lp0.eu> wrote:

> dvb_dvr_read may unlock the dmxdev mutex and return -ENODEV,
> except this function is a file op and will never be called
> with the mutex held.
> 
> There's existing mutex_lock and mutex_unlock around the actual
> read but it's commented out. These should probably be uncommented
> but the read blocks and this could block another non-blocking
> reader on the mutex instead.
> 
> This change comments out the extra mutex_unlock.
> 
> Signed-off-by: Simon Arlott <simon@fire.lp0.eu>
> ---
> This has been on my TODO list for far too long... I did come
> up with a mutex_trylock/mutex_lock_interruptible version but
> claiming that it'll block when it may not doesn't make sense
> (and any blocking read would cause all non-blocking reads to
> continually return -EWOULDBLOCK until there is data).
> 
>  drivers/media/dvb/dvb-core/dmxdev.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/media/dvb/dvb-core/dmxdev.c b/drivers/media/dvb/dvb-core/dmxdev.c
> index c35fbb8..d6d098a 100644
> --- a/drivers/media/dvb/dvb-core/dmxdev.c
> +++ b/drivers/media/dvb/dvb-core/dmxdev.c
> @@ -247,7 +247,7 @@ static ssize_t dvb_dvr_read(struct file *file, char __user *buf, size_t count,
>  	int ret;
>  
>  	if (dmxdev->exit) {
> -		mutex_unlock(&dmxdev->mutex);
> +		//mutex_unlock(&dmxdev->mutex);
>  		return -ENODEV;
>  	}

Is there any value in retaining all the commented-out lock operations,
or can we zap 'em?

--- a/drivers/media/dvb/dvb-core/dmxdev.c~dvb-core-fix-potential-mutex_unlock-without-mutex_lock-in-dvb_dvr_read-fix
+++ a/drivers/media/dvb/dvb-core/dmxdev.c
@@ -244,19 +244,13 @@ static ssize_t dvb_dvr_read(struct file 
 {
 	struct dvb_device *dvbdev = file->private_data;
 	struct dmxdev *dmxdev = dvbdev->priv;
-	int ret;
 
-	if (dmxdev->exit) {
-		//mutex_unlock(&dmxdev->mutex);
+	if (dmxdev->exit)
 		return -ENODEV;
-	}
 
-	//mutex_lock(&dmxdev->mutex);
-	ret = dvb_dmxdev_buffer_read(&dmxdev->dvr_buffer,
-				     file->f_flags & O_NONBLOCK,
-				     buf, count, ppos);
-	//mutex_unlock(&dmxdev->mutex);
-	return ret;
+	return dvb_dmxdev_buffer_read(&dmxdev->dvr_buffer,
+				      file->f_flags & O_NONBLOCK,
+				      buf, count, ppos);
 }
 
 static int dvb_dvr_set_buffer_size(struct dmxdev *dmxdev,
_


  reply	other threads:[~2009-04-30 20:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-23 17:32 [PATCH] dvb-core: Fix potential mutex_unlock without mutex_lock in dvb_dvr_read Simon Arlott
2009-04-30 20:18 ` Andrew Morton [this message]
2009-04-30 21:42   ` Simon Arlott
2009-04-30 21:48     ` Andrew Morton
2009-04-30 21:54       ` Devin Heitmueller

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=20090430131818.d8aded42.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=linux-dvb@linuxtv.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@infradead.org \
    --cc=simon@fire.lp0.eu \
    /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