From: Jonathan Cameron <jic23@kernel.org>
To: Pavel Andrianov <andrianov@ispras.ru>
Cc: Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
Alexander Koch <mail@alexanderkoch.net>,
Vaishali Thakkar <vaishali.thakkar@oracle.com>,
ldv-project@linuxtesting.org,
Andreas Dannenberg <dannenberg@ti.com>
Subject: Re: A potential bug in drivers/iio/light/opt3001.ko
Date: Sat, 3 Sep 2016 17:38:44 +0100 [thread overview]
Message-ID: <61728463-8bd8-c68e-ef4a-7a3e0ddd7899@kernel.org> (raw)
In-Reply-To: <e5806302-9d1b-b262-766a-e64ca9a0159c@ispras.ru>
On 31/08/16 11:23, Pavel Andrianov wrote:
> Hi!
>
> There is a bug in drivers/iio/light/opt3001.ko. Regard such case:
>
> Thread 1 Thread 2
> -> opt3001_read_raw
> -> mutex_lock(&opt->lock)
> -> opt3001_get_lux()
> ..
> ->i2c_smbus_write_word_swapped()
> Now an interrupt comes
> -> opt3001_irq
> -> mutex_lock(&opt->lock)
>
> This is a deadlock, as the flag ok_to_ignore_lock has not been set yet.
Good find. Will need reordering to set the ok_to_ignore_lock first.
Whether it ever actually happens will depend on just how long that EOC
interrupt takes to happen. Still it's a theoretical problem with
a fairly simple fix so let's fix it.
>
> Regard another case:
>
> Thread 1 Thread 2
> -> opt3001_read_raw
> -> mutex_lock(&opt->lock)
> -> opt3001_get_lux()
> ..
> -> i2c_smbus_write_word_swapped()
> opt->ok_to_ignore_lock = true;
> Now an interrupt comes
> -> opt3001_irq
> ..
> opt->result_ready = true
> wake_up()
> opt->result_ready = false;
> wait_event_timeout()
>
> In this case the first thread misses the result and waits until timeout expires.
>
Agreed - looks like some reordering is needed here as well.
Jonathan
next prev parent reply other threads:[~2016-09-03 16:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-31 10:23 Pavel Andrianov
2016-09-03 16:38 ` Jonathan Cameron [this message]
2016-09-05 14:15 ` Pavel Andrianov
2016-09-05 20:04 ` Jonathan Cameron
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=61728463-8bd8-c68e-ef4a-7a3e0ddd7899@kernel.org \
--to=jic23@kernel.org \
--cc=andrianov@ispras.ru \
--cc=dannenberg@ti.com \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=ldv-project@linuxtesting.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mail@alexanderkoch.net \
--cc=pmeerw@pmeerw.net \
--cc=vaishali.thakkar@oracle.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
Powered by JetHome