Message ID | 1436194018-18696-3-git-send-email-rogerq@ti.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Hi Roger, On 07/06/2015 11:46 PM, Roger Quadros wrote: > 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(-) Applied it. Thanks, Chanwoo Choi > > 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); > -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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);
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(-)