From: Roger Quadros <rogerq@ti.com>
To: <cw00.choi@samsung.com>
Cc: <linux-omap@vger.kernel.org>, <linux-usb@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, Roger Quadros <rogerq@ti.com>
Subject: [PATCH 2/2] extcon: Fix extcon_cable_get_state() from getting old state after notification
Date: Mon, 6 Jul 2015 17:46:58 +0300 [thread overview]
Message-ID: <1436194018-18696-3-git-send-email-rogerq@ti.com> (raw)
In-Reply-To: <1436194018-18696-1-git-send-email-rogerq@ti.com>
Currently the extcon code notifiers the interested listeners
before it updates the extcon state with the new state.
This will cause the listeners that use extcon_cable_get_state()
to get the stale state and loose the new state.
Fix this by first changing the extcon state variable and then
notifying listeners.
Signed-off-by: Roger Quadros <rogerq@ti.com>
---
drivers/extcon/extcon.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
index 868c6e2..26d1e1e 100644
--- a/drivers/extcon/extcon.c
+++ b/drivers/extcon/extcon.c
@@ -275,19 +275,25 @@ int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state)
spin_lock_irqsave(&edev->lock, flags);
if (edev->state != ((edev->state & ~mask) | (state & mask))) {
+ u32 old_state;
+
if (check_mutually_exclusive(edev, (edev->state & ~mask) |
(state & mask))) {
spin_unlock_irqrestore(&edev->lock, flags);
return -EPERM;
}
+ old_state = edev->state;
+ edev->state &= ~mask;
+ edev->state |= state & mask;
+
for (index = 0; index < edev->max_supported; index++) {
- if (is_extcon_changed(edev->state, state, index, &attached))
- raw_notifier_call_chain(&edev->nh[index], attached, edev);
+ if (is_extcon_changed(old_state, edev->state, index,
+ &attached))
+ raw_notifier_call_chain(&edev->nh[index],
+ attached, edev);
}
- edev->state &= ~mask;
- edev->state |= state & mask;
/* This could be in interrupt handler */
prop_buf = (char *)get_zeroed_page(GFP_ATOMIC);
--
2.1.4
next prev parent reply other threads:[~2015-07-06 14:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-06 14:46 [PATCH 0/2] extcon: fixes for v4.2-rc1 Roger Quadros
2015-07-06 14:46 ` [PATCH 1/2] extcon: fix hang and extcon_get/set_cable_state() Roger Quadros
2015-07-07 12:40 ` Ivan T. Ivanov
2015-07-07 12:58 ` Roger Quadros
2015-07-07 13:06 ` [PATCH v2 " Roger Quadros
2015-07-07 14:04 ` Ivan T. Ivanov
2015-07-10 15:54 ` Chanwoo Choi
2015-07-27 10:39 ` Roger Quadros
2015-07-27 23:26 ` Chanwoo Choi
2015-07-31 3:43 ` Chanwoo Choi
2015-07-06 14:46 ` Roger Quadros [this message]
2015-07-31 6:38 ` [PATCH 2/2] extcon: Fix extcon_cable_get_state() from getting old state after notification Chanwoo Choi
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=1436194018-18696-3-git-send-email-rogerq@ti.com \
--to=rogerq@ti.com \
--cc=cw00.choi@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux-usb@vger.kernel.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®