提交 01b4c9a1 编写于 作者: C Chanwoo Choi

extcon: Remove potential problem when calling extcon_register_notifier()

This patch removes the potential problem of extcon_register_notifier()
when edev parameter is NULL. When edev is NULL, this function returns
the first extcon device which includes the sepecific external connector
of second paramter. But, it don't guarantee the same operation in all cases.
To remove this confusion and potential problem, this patch fixes it.
Signed-off-by: NChanwoo Choi <cw00.choi@samsung.com>
上级 dd3a55fc
...@@ -906,35 +906,16 @@ int extcon_register_notifier(struct extcon_dev *edev, unsigned int id, ...@@ -906,35 +906,16 @@ int extcon_register_notifier(struct extcon_dev *edev, unsigned int id,
unsigned long flags; unsigned long flags;
int ret, idx = -EINVAL; int ret, idx = -EINVAL;
if (!nb) if (!edev || !nb)
return -EINVAL; return -EINVAL;
if (edev) { idx = find_cable_index_by_id(edev, id);
idx = find_cable_index_by_id(edev, id); if (idx < 0)
if (idx < 0) return idx;
return idx;
spin_lock_irqsave(&edev->lock, flags);
ret = raw_notifier_chain_register(&edev->nh[idx], nb);
spin_unlock_irqrestore(&edev->lock, flags);
} else {
struct extcon_dev *extd;
mutex_lock(&extcon_dev_list_lock);
list_for_each_entry(extd, &extcon_dev_list, entry) {
idx = find_cable_index_by_id(extd, id);
if (idx >= 0)
break;
}
mutex_unlock(&extcon_dev_list_lock);
if (idx >= 0) { spin_lock_irqsave(&edev->lock, flags);
edev = extd; ret = raw_notifier_chain_register(&edev->nh[idx], nb);
return extcon_register_notifier(extd, id, nb); spin_unlock_irqrestore(&edev->lock, flags);
} else {
ret = -ENODEV;
}
}
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册