aboutsummaryrefslogtreecommitdiff
path: root/drivers/extcon
diff options
context:
space:
mode:
authorRoger Quadros <rogerq@ti.com>2015-07-06 17:46:58 +0300
committerChanwoo Choi <cw00.choi@samsung.com>2015-07-31 15:18:41 +0900
commitf7a898117aebf3d52370fe637f4d7aff7a237afc (patch)
tree58c9f79a9b713efb39c1507b9dafa64f4a616f4b /drivers/extcon
parentbe052cc87745e01846fb036eb81567c784439078 (diff)
extcon: Fix extcon_cable_get_state() from getting old state after notification
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> Tested-by: Ivan T. Ivanov <ivan.ivanov@linaro.org> Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Diffstat (limited to 'drivers/extcon')
-rw-r--r--drivers/extcon/extcon.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
index 0e2af1728965..43b57b02d050 100644
--- a/drivers/extcon/extcon.c
+++ b/drivers/extcon/extcon.c
@@ -275,20 +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;
}
- 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);
- }
-
+ old_state = edev->state;
edev->state &= ~mask;
edev->state |= state & mask;
+ for (index = 0; index < edev->max_supported; index++) {
+ if (is_extcon_changed(old_state, edev->state, index,
+ &attached))
+ raw_notifier_call_chain(&edev->nh[index],
+ attached, edev);
+ }
+
/* This could be in interrupt handler */
prop_buf = (char *)get_zeroed_page(GFP_ATOMIC);
if (prop_buf) {