diff options
author | Chanwoo Choi <cw00.choi@samsung.com> | 2015-06-21 10:48:36 -0400 |
---|---|---|
committer | Chanwoo Choi <cw00.choi@samsung.com> | 2015-08-09 22:48:56 -0400 |
commit | 7eae43aeab27e8f65c0a2e31567fafcfc7aa4649 (patch) | |
tree | 7dba14ecdb9dbd6a81b7f5dfcce52dbe589a096e /drivers/extcon/extcon.c | |
parent | 0ffe8cbd51dafa5ad6686435bb1bd0afdd2b006b (diff) |
extcon: Add exception handling to prevent the NULL pointer access
This patch check whether argument is NULL to prevent NULL pointer access.
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Diffstat (limited to 'drivers/extcon/extcon.c')
-rw-r--r-- | drivers/extcon/extcon.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index d1fb5b4d024a..8301a72b1073 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c | |||
@@ -264,6 +264,9 @@ int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state) | |||
264 | unsigned long flags; | 264 | unsigned long flags; |
265 | bool attached; | 265 | bool attached; |
266 | 266 | ||
267 | if (!edev) | ||
268 | return -EINVAL; | ||
269 | |||
267 | spin_lock_irqsave(&edev->lock, flags); | 270 | spin_lock_irqsave(&edev->lock, flags); |
268 | 271 | ||
269 | if (edev->state != ((edev->state & ~mask) | (state & mask))) { | 272 | if (edev->state != ((edev->state & ~mask) | (state & mask))) { |
@@ -337,6 +340,9 @@ EXPORT_SYMBOL_GPL(extcon_update_state); | |||
337 | */ | 340 | */ |
338 | int extcon_set_state(struct extcon_dev *edev, u32 state) | 341 | int extcon_set_state(struct extcon_dev *edev, u32 state) |
339 | { | 342 | { |
343 | if (!edev) | ||
344 | return -EINVAL; | ||
345 | |||
340 | return extcon_update_state(edev, 0xffffffff, state); | 346 | return extcon_update_state(edev, 0xffffffff, state); |
341 | } | 347 | } |
342 | EXPORT_SYMBOL_GPL(extcon_set_state); | 348 | EXPORT_SYMBOL_GPL(extcon_set_state); |
@@ -350,6 +356,9 @@ int extcon_get_cable_state_(struct extcon_dev *edev, const unsigned int id) | |||
350 | { | 356 | { |
351 | int index; | 357 | int index; |
352 | 358 | ||
359 | if (!edev) | ||
360 | return -EINVAL; | ||
361 | |||
353 | index = find_cable_index_by_id(edev, id); | 362 | index = find_cable_index_by_id(edev, id); |
354 | if (index < 0) | 363 | if (index < 0) |
355 | return index; | 364 | return index; |
@@ -394,6 +403,9 @@ int extcon_set_cable_state_(struct extcon_dev *edev, unsigned int id, | |||
394 | u32 state; | 403 | u32 state; |
395 | int index; | 404 | int index; |
396 | 405 | ||
406 | if (!edev) | ||
407 | return -EINVAL; | ||
408 | |||
397 | index = find_cable_index_by_id(edev, id); | 409 | index = find_cable_index_by_id(edev, id); |
398 | if (index < 0) | 410 | if (index < 0) |
399 | return index; | 411 | return index; |
@@ -436,6 +448,9 @@ struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name) | |||
436 | { | 448 | { |
437 | struct extcon_dev *sd; | 449 | struct extcon_dev *sd; |
438 | 450 | ||
451 | if (!extcon_name) | ||
452 | return ERR_PTR(-EINVAL); | ||
453 | |||
439 | mutex_lock(&extcon_dev_list_lock); | 454 | mutex_lock(&extcon_dev_list_lock); |
440 | list_for_each_entry(sd, &extcon_dev_list, entry) { | 455 | list_for_each_entry(sd, &extcon_dev_list, entry) { |
441 | if (!strcmp(sd->name, extcon_name)) | 456 | if (!strcmp(sd->name, extcon_name)) |
@@ -564,6 +579,9 @@ int extcon_register_notifier(struct extcon_dev *edev, unsigned int id, | |||
564 | unsigned long flags; | 579 | unsigned long flags; |
565 | int ret, idx; | 580 | int ret, idx; |
566 | 581 | ||
582 | if (!edev || !nb) | ||
583 | return -EINVAL; | ||
584 | |||
567 | idx = find_cable_index_by_id(edev, id); | 585 | idx = find_cable_index_by_id(edev, id); |
568 | 586 | ||
569 | spin_lock_irqsave(&edev->lock, flags); | 587 | spin_lock_irqsave(&edev->lock, flags); |
@@ -586,6 +604,9 @@ int extcon_unregister_notifier(struct extcon_dev *edev, unsigned int id, | |||
586 | unsigned long flags; | 604 | unsigned long flags; |
587 | int ret, idx; | 605 | int ret, idx; |
588 | 606 | ||
607 | if (!edev || !nb) | ||
608 | return -EINVAL; | ||
609 | |||
589 | idx = find_cable_index_by_id(edev, id); | 610 | idx = find_cable_index_by_id(edev, id); |
590 | 611 | ||
591 | spin_lock_irqsave(&edev->lock, flags); | 612 | spin_lock_irqsave(&edev->lock, flags); |
@@ -646,6 +667,9 @@ struct extcon_dev *extcon_dev_allocate(const unsigned int *supported_cable) | |||
646 | { | 667 | { |
647 | struct extcon_dev *edev; | 668 | struct extcon_dev *edev; |
648 | 669 | ||
670 | if (!supported_cable) | ||
671 | return ERR_PTR(-EINVAL); | ||
672 | |||
649 | edev = kzalloc(sizeof(*edev), GFP_KERNEL); | 673 | edev = kzalloc(sizeof(*edev), GFP_KERNEL); |
650 | if (!edev) | 674 | if (!edev) |
651 | return ERR_PTR(-ENOMEM); | 675 | return ERR_PTR(-ENOMEM); |
@@ -746,7 +770,7 @@ int extcon_dev_register(struct extcon_dev *edev) | |||
746 | return ret; | 770 | return ret; |
747 | } | 771 | } |
748 | 772 | ||
749 | if (!edev->supported_cable) | 773 | if (!edev || !edev->supported_cable) |
750 | return -EINVAL; | 774 | return -EINVAL; |
751 | 775 | ||
752 | for (; edev->supported_cable[index] != EXTCON_NONE; index++); | 776 | for (; edev->supported_cable[index] != EXTCON_NONE; index++); |
@@ -952,6 +976,9 @@ void extcon_dev_unregister(struct extcon_dev *edev) | |||
952 | { | 976 | { |
953 | int index; | 977 | int index; |
954 | 978 | ||
979 | if (!edev) | ||
980 | return; | ||
981 | |||
955 | mutex_lock(&extcon_dev_list_lock); | 982 | mutex_lock(&extcon_dev_list_lock); |
956 | list_del(&edev->entry); | 983 | list_del(&edev->entry); |
957 | mutex_unlock(&extcon_dev_list_lock); | 984 | mutex_unlock(&extcon_dev_list_lock); |
@@ -1058,6 +1085,9 @@ struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index) | |||
1058 | struct device_node *node; | 1085 | struct device_node *node; |
1059 | struct extcon_dev *edev; | 1086 | struct extcon_dev *edev; |
1060 | 1087 | ||
1088 | if (!dev) | ||
1089 | return ERR_PTR(-EINVAL); | ||
1090 | |||
1061 | if (!dev->of_node) { | 1091 | if (!dev->of_node) { |
1062 | dev_err(dev, "device does not have a device node entry\n"); | 1092 | dev_err(dev, "device does not have a device node entry\n"); |
1063 | return ERR_PTR(-EINVAL); | 1093 | return ERR_PTR(-EINVAL); |