From: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
To: linux-iio@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org,
dianders@chromium.org, gregkh@linuxfoundation.org,
naveenkrishna.ch@gmail.com, lars@metafoo.de
Subject: [RFC: PATCH 2/2] iio: adc: exynos_adc: Handle timeout and race conditions
Date: Fri, 15 Mar 2013 21:56:41 +0530 [thread overview]
Message-ID: <1363364801-23684-1-git-send-email-ch.naveen@samsung.com> (raw)
This patch does the following
1. Handle the return values of wait_for_completion_interruptible_timeout
2. Add spin locks to avoid race conditions during ISR.
Signed-off-by: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
Cc: Doug Anderson <dianders@chromium.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>
---
Discussion thread for this patch can be found at
http://www.gossamer-threads.com/lists/linux/kernel/1693284?page=last
I've not seen any reference to spin lock usage in IIO.
Kindly, suggest me if there is a better way to avoid the race.
Thanks,
Naveen
drivers/iio/adc/exynos_adc.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
index ed6fdd7..4de28ae 100644
--- a/drivers/iio/adc/exynos_adc.c
+++ b/drivers/iio/adc/exynos_adc.c
@@ -91,6 +91,7 @@ struct exynos_adc {
struct completion completion;
+ spinlock_t reg_lock;
u32 value;
unsigned int version;
};
@@ -117,7 +118,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
long mask)
{
struct exynos_adc *info = iio_priv(indio_dev);
- unsigned long timeout;
+ long timeout;
u32 con1, con2;
if (mask != IIO_CHAN_INFO_RAW)
@@ -143,15 +144,19 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
ADC_V1_CON(info->regs));
}
+ INIT_COMPLETION(info->completion);
+
timeout = wait_for_completion_interruptible_timeout
(&info->completion, EXYNOS_ADC_TIMEOUT);
+
*val = info->value;
mutex_unlock(&indio_dev->mlock);
if (timeout == 0)
return -ETIMEDOUT;
-
+ else if (timeout < 0)
+ return timeout;
return IIO_VAL_INT;
}
@@ -159,6 +164,8 @@ static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
{
struct exynos_adc *info = (struct exynos_adc *)dev_id;
+ spin_lock(&info->reg_lock);
+
/* Read value */
info->value = readl(ADC_V1_DATX(info->regs)) &
ADC_DATX_MASK;
@@ -170,6 +177,8 @@ static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
complete(&info->completion);
+ spin_unlock(&info->reg_lock);
+
return IRQ_HANDLED;
}
@@ -327,6 +336,7 @@ static int exynos_adc_probe(struct platform_device *pdev)
else
indio_dev->num_channels = MAX_ADC_V2_CHANNELS;
+ spin_lock_init(&info->reg_lock);
ret = iio_device_register(indio_dev);
if (ret)
goto err_irq;
--
1.7.9.5
next reply other threads:[~2013-03-15 16:29 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-15 16:26 Naveen Krishna Chatradhi [this message]
[not found] ` <1363364801-23684-1-git-send-email-ch.naveen-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2013-03-15 21:53 ` [RFC: PATCH 2/2] iio: adc: exynos_adc: Handle timeout and race conditions Lars-Peter Clausen
2013-03-16 0:37 ` Doug Anderson
[not found] ` <CAD=FV=V+-DwCjGoookySCazazBBYOoRO+=G5Q_WXAw+SrXNc-A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-03-16 14:41 ` Lars-Peter Clausen
[not found] ` <5144849A.8050907-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2013-04-03 17:06 ` Doug Anderson
2013-04-05 8:53 ` Lars-Peter Clausen
[not found] ` <515E90FD.10006-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2013-04-05 14:56 ` Doug Anderson
2013-04-05 16:38 ` Lars-Peter Clausen
2013-04-04 4:06 ` [PATCH] iio: adc: exynos_adc: Handle timeout issues Naveen Krishna Chatradhi
[not found] ` <1365048389-6364-1-git-send-email-naveenkrishna.ch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-04-13 4:36 ` Naveen Krishna Ch
[not found] ` <CAHfPSqAVUVdFwtMxJYCGaPv_+iO_GEc9_UGNXwuSj9uu_fB81g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-04-15 16:01 ` Doug Anderson
2013-05-02 18:01 ` [PATCH v2] " Naveen Krishna Chatradhi
[not found] ` <1367517663-12225-1-git-send-email-naveenkrishna.ch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-05-02 18:10 ` Tomasz Figa
2013-05-02 18:22 ` Naveen Krishna Ch
[not found] ` <CAHfPSqCc81765zQVur=AtW2Cf+taYef=LYJK008i03cmYPu0WQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-05-02 18:36 ` Tomasz Figa
2013-10-11 8:23 ` [PATCH v3] iio: exynos_adc: use wait_for_completion_timeout instead of interruptible Naveen Krishna Chatradhi
[not found] ` <1381479821-17276-1-git-send-email-ch.naveen-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2013-10-11 14:30 ` Lars-Peter Clausen
[not found] ` <52580B95.5010603-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2013-10-12 6:40 ` Naveen Krishna Ch
2013-10-15 5:15 ` [PATCH v4] " Naveen Krishna Chatradhi
2013-10-25 15:42 ` Doug Anderson
2013-10-28 5:41 ` [PATCH v5] " Naveen Krishna Chatradhi
2013-11-05 9:45 ` [PATCH v6] " Naveen Krishna Chatradhi
[not found] ` <1383644730-23228-1-git-send-email-ch.naveen-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2013-11-10 12:48 ` Tomasz Figa
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=1363364801-23684-1-git-send-email-ch.naveen@samsung.com \
--to=ch.naveen@samsung.com \
--cc=dianders@chromium.org \
--cc=gregkh@linuxfoundation.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=naveenkrishna.ch@gmail.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;
as well as URLs for NNTP newsgroup(s).