From: iceberg <strakh@ispras.ru>
To: Jonathan Corbet <corbet@lwn.net>,
Steven Rostedt <rostedt@goodmis.org>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Fwd: Re: [PATCH] fix lock imbalances in /drivers/media/video/cafe_ccic.c
Date: Fri, 11 Sep 2009 18:13:21 +0000 [thread overview]
Message-ID: <200909111813.21232.strakh@ispras.ru> (raw)
On Thu, Sep 10, 2009 at 09:30:03AM -0600, Jonathan Corbet wrote:
> On Thu, 10 Sep 2009 18:37:34 +0000
> iceberg <strakh@ispras.ru> wrote:
>
> > In ./drivers/media/video/cafe_ccic.c, in function cafe_pci_probe:
> > Mutex must be unlocked before exit
> > 1. On paths starting with mutex lock in line 1912, then continuing in
lines:
> > 1929, 1936 (goto unreg) and 1940 (goto iounmap) .
> > 2. On path starting in line 1971 mutex lock, and then continuing in
line 1978
> > (goto out_smbus) mutex.
>
> That's a definite bug, but I hate all those unlocks in the error
> branches. As it happens, we don't really need the mutex until the
> device has been exposed to the rest of the kernel, so I propose the
> following as a better patch.
>
> Thanks for pointing this out,
If we can first pair of mutex_lock and mutex_unlock:
Fix lock imbalances in function device_authorization.
Signed-off-by: Alexander Strakh <strakh@ispras.ru>
---
diff --git a/./drivers/media/video/cafe_ccic.c
b/../b/drivers/media/video/cafe_ccic.c
index c4d181d..4c6bc86 100644
--- a/./drivers/media/video/cafe_ccic.c
+++ b/../b/drivers/media/video/cafe_ccic.c
@@ -1909,7 +1909,6 @@ static int cafe_pci_probe(struct pci_dev *pdev,
goto out_free;
mutex_init(&cam->s_mutex);
- mutex_lock(&cam->s_mutex);
spin_lock_init(&cam->dev_lock);
cam->state = S_NOTREADY;
cafe_set_config_needed(cam, 1);
@@ -1949,7 +1948,6 @@ static int cafe_pci_probe(struct pci_dev *pdev,
* because the sensor could attach in this call chain, leading to
* unsightly deadlocks.
*/
- mutex_unlock(&cam->s_mutex); /* attach can deadlock */
ret = cafe_smbus_setup(cam);
if (ret)
goto out_freeirq;
@@ -1975,7 +1973,7 @@ static int cafe_pci_probe(struct pci_dev *pdev,
cam->vdev.v4l2_dev = &cam->v4l2_dev;
ret = video_register_device(&cam->vdev, VFL_TYPE_GRABBER, -1);
if (ret)
- goto out_smbus;
+ goto out_unlock;
video_set_drvdata(&cam->vdev, cam);
/*
@@ -1990,6 +1988,8 @@ static int cafe_pci_probe(struct pci_dev *pdev,
mutex_unlock(&cam->s_mutex);
return 0;
+out_unlock:
+ mutex_unlock(&cam->s_mutex);
out_smbus:
cafe_smbus_shutdown(cam);
out_freeirq:
reply other threads:[~2009-09-11 14:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=200909111813.21232.strakh@ispras.ru \
--to=strakh@ispras.ru \
--cc=corbet@lwn.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=rostedt@goodmis.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®