All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Weinberger <richard@nod.at>
To: Harald Geyer <harald@ccbib.org>
Cc: jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de,
	pmeerw@pmeerw.net, sanjeev_sharma@mentor.com,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] iio: dht11: Add locking
Date: Tue, 02 Dec 2014 11:52:14 +0100	[thread overview]
Message-ID: <547D99DE.6030309@nod.at> (raw)
In-Reply-To: <E1XvkMu-000137-KP@stardust.g4.wien.funkfeuer.at>

Harald,

Am 02.12.2014 um 11:07 schrieb Harald Geyer:
> Hi Richard,
> 
> thanks for the patch. Comments inline.
> 
> Richard Weinberger writes:
>> Protect the read function from concurrent reads.
>>
>> Signed-off-by: Richard Weinberger <richard@nod.at>
>> ---
>>  drivers/iio/humidity/dht11.c | 19 ++++++++++++++-----
>>  1 file changed, 14 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/iio/humidity/dht11.c b/drivers/iio/humidity/dht11.c
>> index 623c145..7636e66 100644
>> --- a/drivers/iio/humidity/dht11.c
>> +++ b/drivers/iio/humidity/dht11.c
> 
> #include <linux/mutex.h>
> 
>> @@ -57,6 +57,7 @@ struct dht11 {
>>  	int				irq;
>>  
>>  	struct completion		completion;
>> +	struct mutex			lock;
>>  
>>  	s64				timestamp;
>>  	int				temperature;
>> @@ -146,16 +147,17 @@ static int dht11_read_raw(struct iio_dev *iio_dev,
>>  	int ret;
>>  
>>  	if (dht11->timestamp + DHT11_DATA_VALID_TIME < iio_get_time_ns()) {
>> +		mutex_lock(&dht11->lock);
> 
> Move the locking out of the if statement.

Care to explain why?

But I found another issue in my patch.
The "dht11->num_edges = -1;" before "return ret" needs to go into the locked area.
Will send an updated version soon.

> BTW, it seems that there is already locking around read_raw() in the
> in-kernel consumer interface but not in the sysfs interface. Is there
> any reason for this difference?

Dunno. :-)

Thanks,
//richard

  reply	other threads:[~2014-12-02 10:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-01 20:27 [PATCH 1/2] iio: dht11: Add locking Richard Weinberger
2014-12-01 20:27 ` [PATCH 2/2] iio: dht11: IRQ fixes Richard Weinberger
2014-12-02 10:19   ` Harald Geyer
2014-12-02 10:54     ` Richard Weinberger
2014-12-02 12:58       ` Harald Geyer
2014-12-02 18:12         ` Richard Weinberger
2014-12-02 19:49           ` Harald Geyer
2014-12-02 20:39             ` Richard Weinberger
2014-12-03 20:14           ` Hartmut Knaack
2014-12-02 10:07 ` [PATCH 1/2] iio: dht11: Add locking Harald Geyer
2014-12-02 10:52   ` Richard Weinberger [this message]
2014-12-02 12:14     ` Harald Geyer
2014-12-02 17:58       ` Richard Weinberger

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=547D99DE.6030309@nod.at \
    --to=richard@nod.at \
    --cc=harald@ccbib.org \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    --cc=sanjeev_sharma@mentor.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.