소스 검색

extcon: Check for incorrect connection type in notifier register

If we call extcon_register_notifier() with the wrong cable type,
it blows up with an oops instead of returning an error code.
Let's be nice and fail gracefully given that the consumer might
not know if the cable is supported by the extcon provider.

Signed-off-by: Stephen Boyd <stephen.boyd@linaro.org>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Stephen Boyd 9 년 전
부모
커밋
a05f44c89e
1개의 변경된 파일4개의 추가작업 그리고 0개의 파일을 삭제
  1. 4 0
      drivers/extcon/extcon.c

+ 4 - 0
drivers/extcon/extcon.c

@@ -415,6 +415,8 @@ int extcon_register_notifier(struct extcon_dev *edev, unsigned int id,
 
 	if (edev) {
 		idx = find_cable_index_by_id(edev, id);
+		if (idx < 0)
+			return idx;
 
 		spin_lock_irqsave(&edev->lock, flags);
 		ret = raw_notifier_chain_register(&edev->nh[idx], nb);
@@ -458,6 +460,8 @@ int extcon_unregister_notifier(struct extcon_dev *edev, unsigned int id,
 		return -EINVAL;
 
 	idx = find_cable_index_by_id(edev, id);
+	if (idx < 0)
+		return idx;
 
 	spin_lock_irqsave(&edev->lock, flags);
 	ret = raw_notifier_chain_unregister(&edev->nh[idx], nb);