diff options
author | Hans de Goede <hdegoede@redhat.com> | 2015-03-21 19:26:24 +0300 |
---|---|---|
committer | Chanwoo Choi <cw00.choi@samsung.com> | 2015-03-23 05:06:04 +0300 |
commit | 66bee35f29683fc4a9a530a1c56a0ec45e3f7d72 (patch) | |
tree | 79f47f38f1a4802eb8ae789e1b4516b10a424135 /drivers/extcon | |
parent | b9b518f53996b67833b42ca7751b2085b0dc565a (diff) | |
download | linux-66bee35f29683fc4a9a530a1c56a0ec45e3f7d72.tar.xz |
extcon: Fix missing locking when [un]registering notifiers
Since extcon.c is using raw_notifiers it must protect the notifier
list itself when [un]registering notifiers to avoid the list changing while
extcon_update_state is walking the list (through raw_notifier_call_chain).
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
[cw00.choi: Apply this patch to extcon.c driver instead of old extcon-class.c]
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Diffstat (limited to 'drivers/extcon')
-rw-r--r-- | drivers/extcon/extcon.c | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index 752ce1208428..4c9f165e4a04 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c @@ -445,6 +445,9 @@ int extcon_register_interest(struct extcon_specific_cable_nb *obj, const char *extcon_name, const char *cable_name, struct notifier_block *nb) { + unsigned long flags; + int ret; + if (!obj || !cable_name || !nb) return -EINVAL; @@ -462,8 +465,11 @@ int extcon_register_interest(struct extcon_specific_cable_nb *obj, obj->internal_nb.notifier_call = _call_per_cable; - return raw_notifier_chain_register(&obj->edev->nh, + spin_lock_irqsave(&obj->edev->lock, flags); + ret = raw_notifier_chain_register(&obj->edev->nh, &obj->internal_nb); + spin_unlock_irqrestore(&obj->edev->lock, flags); + return ret; } else { struct class_dev_iter iter; struct extcon_dev *extd; @@ -496,10 +502,17 @@ EXPORT_SYMBOL_GPL(extcon_register_interest); */ int extcon_unregister_interest(struct extcon_specific_cable_nb *obj) { + unsigned long flags; + int ret; + if (!obj) return -EINVAL; - return raw_notifier_chain_unregister(&obj->edev->nh, &obj->internal_nb); + spin_lock_irqsave(&obj->edev->lock, flags); + ret = raw_notifier_chain_unregister(&obj->edev->nh, &obj->internal_nb); + spin_unlock_irqrestore(&obj->edev->lock, flags); + + return ret; } EXPORT_SYMBOL_GPL(extcon_unregister_interest); @@ -516,7 +529,14 @@ EXPORT_SYMBOL_GPL(extcon_unregister_interest); int extcon_register_notifier(struct extcon_dev *edev, struct notifier_block *nb) { - return raw_notifier_chain_register(&edev->nh, nb); + unsigned long flags; + int ret; + + spin_lock_irqsave(&edev->lock, flags); + ret = raw_notifier_chain_register(&edev->nh, nb); + spin_unlock_irqrestore(&edev->lock, flags); + + return ret; } EXPORT_SYMBOL_GPL(extcon_register_notifier); @@ -528,7 +548,14 @@ EXPORT_SYMBOL_GPL(extcon_register_notifier); int extcon_unregister_notifier(struct extcon_dev *edev, struct notifier_block *nb) { - return raw_notifier_chain_unregister(&edev->nh, nb); + unsigned long flags; + int ret; + + spin_lock_irqsave(&edev->lock, flags); + ret = raw_notifier_chain_unregister(&edev->nh, nb); + spin_unlock_irqrestore(&edev->lock, flags); + + return ret; } EXPORT_SYMBOL_GPL(extcon_unregister_notifier); |