linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] Media: radio: si470x: remove double mutex lock
@ 2011-01-23  9:16 Alexander Strakh
  2011-01-24  6:59 ` Tobias Lorenz
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Strakh @ 2011-01-23  9:16 UTC (permalink / raw)
  To: mchehab
  Cc: tobias.lorenz, jy0922.shim, linux-media, linux-kernel,
	Alexander Strakh, Alexander Strakh

From: Alexander Strakh <cromlehg@gmail.com>


1. First mutex_lock on &radio->lock in line 441
2. Second in line 462

I think that mutex in line 462 is not needed. In kernel v2.6.36.3 function si470
x_rds_on contains mutex_lock/mutex_unlock. Have no mutex_lock in line 441. In kernel v2.6.37 mutex_lock/mutex_unlock has been moved from si470x_rds_on to fops_read. But old mutex_lock (line 462) forgot to remove. 

 433static ssize_t si470x_fops_read(struct file *file, char __user *buf,
 434                size_t count, loff_t *ppos)
 435{
....
 441        mutex_lock(&radio->lock);
 442        if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0)
 443                si470x_rds_on(radio);
 444
 445        /* block if no new data available */
 446        while (radio->wr_index == radio->rd_index) {
 447                if (file->f_flags & O_NONBLOCK) {
 448                        retval = -EWOULDBLOCK;
 449                        goto done;
 450                }
 451                if (wait_event_interruptible(radio->read_queue,
 452                        radio->wr_index != radio->rd_index) < 0) {
 453                        retval = -EINTR;
 454                        goto done;
 455                }
 456        }
 457
 458        /* calculate block count from byte count */
 459        count /= 3;
 460
 461        /* copy RDS block out of internal buffer and to user buffer */
 462        mutex_lock(&radio->lock);

Found by Linux Device Drivers Verification Project

Remove second mutex_lock from fops_read

Signed-off-by: Alexander Strakh <strakh@ispras.ru>
---
 drivers/media/radio/si470x/radio-si470x-common.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/drivers/media/radio/si470x/radio-si470x-common.c b/drivers/media/radio/si470x/radio-si470x-common.c
index 60c176f..38ae6cd 100644
--- a/drivers/media/radio/si470x/radio-si470x-common.c
+++ b/drivers/media/radio/si470x/radio-si470x-common.c
@@ -460,7 +460,6 @@ static ssize_t si470x_fops_read(struct file *file, char __user *buf,
 	count /= 3;
 
 	/* copy RDS block out of internal buffer and to user buffer */
-	mutex_lock(&radio->lock);
 	while (block_count < count) {
 		if (radio->rd_index == radio->wr_index)
 			break;
-- 
1.7.1


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

* Re: [PATCH 1/1] Media: radio: si470x: remove double mutex lock
  2011-01-23  9:16 [PATCH 1/1] Media: radio: si470x: remove double mutex lock Alexander Strakh
@ 2011-01-24  6:59 ` Tobias Lorenz
  0 siblings, 0 replies; 2+ messages in thread
From: Tobias Lorenz @ 2011-01-24  6:59 UTC (permalink / raw)
  To: Alexander Strakh
  Cc: mchehab, jy0922.shim, linux-media, linux-kernel, Alexander Strakh

Hi,

good catch! Thanks.

Acked-by: Tobias Lorenz <tobias.lorenz@gmx.net>

Bye,
Toby

On Sun, 23 Jan 2011 12:16:54 +0300, Alexander Strakh <cromlehg@gmail.com>
wrote:
> From: Alexander Strakh <cromlehg@gmail.com>
> 
> 
> 1. First mutex_lock on &radio->lock in line 441
> 2. Second in line 462
> 
> I think that mutex in line 462 is not needed. In kernel v2.6.36.3
function
> si470
> x_rds_on contains mutex_lock/mutex_unlock. Have no mutex_lock in line
441.
> In kernel v2.6.37 mutex_lock/mutex_unlock has been moved from
si470x_rds_on
> to fops_read. But old mutex_lock (line 462) forgot to remove. 
> 
>  433static ssize_t si470x_fops_read(struct file *file, char __user *buf,
>  434                size_t count, loff_t *ppos)
>  435{
> ....
>  441        mutex_lock(&radio->lock);
>  442        if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0)
>  443                si470x_rds_on(radio);
>  444
>  445        /* block if no new data available */
>  446        while (radio->wr_index == radio->rd_index) {
>  447                if (file->f_flags & O_NONBLOCK) {
>  448                        retval = -EWOULDBLOCK;
>  449                        goto done;
>  450                }
>  451                if (wait_event_interruptible(radio->read_queue,
>  452                        radio->wr_index != radio->rd_index) < 0) {
>  453                        retval = -EINTR;
>  454                        goto done;
>  455                }
>  456        }
>  457
>  458        /* calculate block count from byte count */
>  459        count /= 3;
>  460
>  461        /* copy RDS block out of internal buffer and to user buffer
*/
>  462        mutex_lock(&radio->lock);
> 
> Found by Linux Device Drivers Verification Project
> 
> Remove second mutex_lock from fops_read
> 
> Signed-off-by: Alexander Strakh <strakh@ispras.ru>
> ---
>  drivers/media/radio/si470x/radio-si470x-common.c |    1 -
>  1 files changed, 0 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/media/radio/si470x/radio-si470x-common.c
> b/drivers/media/radio/si470x/radio-si470x-common.c
> index 60c176f..38ae6cd 100644
> --- a/drivers/media/radio/si470x/radio-si470x-common.c
> +++ b/drivers/media/radio/si470x/radio-si470x-common.c
> @@ -460,7 +460,6 @@ static ssize_t si470x_fops_read(struct file *file,
> char __user *buf,
>  	count /= 3;
>  
>  	/* copy RDS block out of internal buffer and to user buffer */
> -	mutex_lock(&radio->lock);
>  	while (block_count < count) {
>  		if (radio->rd_index == radio->wr_index)
>  			break;

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

end of thread, other threads:[~2011-01-24  6:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-23  9:16 [PATCH 1/1] Media: radio: si470x: remove double mutex lock Alexander Strakh
2011-01-24  6:59 ` Tobias Lorenz

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).