diff options
Diffstat (limited to 'net/rfkill/rfkill.c')
-rw-r--r-- | net/rfkill/rfkill.c | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/net/rfkill/rfkill.c b/net/rfkill/rfkill.c index b630f358d674..910699c4e04f 100644 --- a/net/rfkill/rfkill.c +++ b/net/rfkill/rfkill.c | |||
@@ -76,6 +76,7 @@ static BLOCKING_NOTIFIER_HEAD(rfkill_notifier_list); | |||
76 | */ | 76 | */ |
77 | int register_rfkill_notifier(struct notifier_block *nb) | 77 | int register_rfkill_notifier(struct notifier_block *nb) |
78 | { | 78 | { |
79 | BUG_ON(!nb); | ||
79 | return blocking_notifier_chain_register(&rfkill_notifier_list, nb); | 80 | return blocking_notifier_chain_register(&rfkill_notifier_list, nb); |
80 | } | 81 | } |
81 | EXPORT_SYMBOL_GPL(register_rfkill_notifier); | 82 | EXPORT_SYMBOL_GPL(register_rfkill_notifier); |
@@ -91,6 +92,7 @@ EXPORT_SYMBOL_GPL(register_rfkill_notifier); | |||
91 | */ | 92 | */ |
92 | int unregister_rfkill_notifier(struct notifier_block *nb) | 93 | int unregister_rfkill_notifier(struct notifier_block *nb) |
93 | { | 94 | { |
95 | BUG_ON(!nb); | ||
94 | return blocking_notifier_chain_unregister(&rfkill_notifier_list, nb); | 96 | return blocking_notifier_chain_unregister(&rfkill_notifier_list, nb); |
95 | } | 97 | } |
96 | EXPORT_SYMBOL_GPL(unregister_rfkill_notifier); | 98 | EXPORT_SYMBOL_GPL(unregister_rfkill_notifier); |
@@ -202,6 +204,9 @@ static int rfkill_toggle_radio(struct rfkill *rfkill, | |||
202 | * RFKILL_STATE_HARD_BLOCKED */ | 204 | * RFKILL_STATE_HARD_BLOCKED */ |
203 | break; | 205 | break; |
204 | default: | 206 | default: |
207 | WARN(1, KERN_WARNING | ||
208 | "rfkill: illegal state %d passed as parameter " | ||
209 | "to rfkill_toggle_radio\n", state); | ||
205 | return -EINVAL; | 210 | return -EINVAL; |
206 | } | 211 | } |
207 | 212 | ||
@@ -236,7 +241,11 @@ static void __rfkill_switch_all(const enum rfkill_type type, | |||
236 | { | 241 | { |
237 | struct rfkill *rfkill; | 242 | struct rfkill *rfkill; |
238 | 243 | ||
239 | if (unlikely(state >= RFKILL_STATE_MAX)) | 244 | if (WARN((state >= RFKILL_STATE_MAX || type >= RFKILL_TYPE_MAX), |
245 | KERN_WARNING | ||
246 | "rfkill: illegal state %d or type %d " | ||
247 | "passed as parameter to __rfkill_switch_all\n", | ||
248 | state, type)) | ||
240 | return; | 249 | return; |
241 | 250 | ||
242 | rfkill_global_states[type].current_state = state; | 251 | rfkill_global_states[type].current_state = state; |
@@ -334,7 +343,11 @@ int rfkill_force_state(struct rfkill *rfkill, enum rfkill_state state) | |||
334 | { | 343 | { |
335 | enum rfkill_state oldstate; | 344 | enum rfkill_state oldstate; |
336 | 345 | ||
337 | if (unlikely(state >= RFKILL_STATE_MAX)) | 346 | BUG_ON(!rfkill); |
347 | if (WARN((state >= RFKILL_STATE_MAX), | ||
348 | KERN_WARNING | ||
349 | "rfkill: illegal state %d passed as parameter " | ||
350 | "to rfkill_force_state\n", state)) | ||
338 | return -EINVAL; | 351 | return -EINVAL; |
339 | 352 | ||
340 | mutex_lock(&rfkill->mutex); | 353 | mutex_lock(&rfkill->mutex); |
@@ -593,10 +606,10 @@ static int rfkill_check_duplicity(const struct rfkill *rfkill) | |||
593 | memset(seen, 0, sizeof(seen)); | 606 | memset(seen, 0, sizeof(seen)); |
594 | 607 | ||
595 | list_for_each_entry(p, &rfkill_list, node) { | 608 | list_for_each_entry(p, &rfkill_list, node) { |
596 | if (p == rfkill) { | 609 | if (WARN((p == rfkill), KERN_WARNING |
597 | WARN_ON(1); | 610 | "rfkill: illegal attempt to register " |
611 | "an already registered rfkill struct\n")) | ||
598 | return -EEXIST; | 612 | return -EEXIST; |
599 | } | ||
600 | set_bit(p->type, seen); | 613 | set_bit(p->type, seen); |
601 | } | 614 | } |
602 | 615 | ||
@@ -664,6 +677,12 @@ struct rfkill * __must_check rfkill_allocate(struct device *parent, | |||
664 | struct rfkill *rfkill; | 677 | struct rfkill *rfkill; |
665 | struct device *dev; | 678 | struct device *dev; |
666 | 679 | ||
680 | if (WARN((type >= RFKILL_TYPE_MAX), | ||
681 | KERN_WARNING | ||
682 | "rfkill: illegal type %d passed as parameter " | ||
683 | "to rfkill_allocate\n", type)) | ||
684 | return NULL; | ||
685 | |||
667 | rfkill = kzalloc(sizeof(struct rfkill), GFP_KERNEL); | 686 | rfkill = kzalloc(sizeof(struct rfkill), GFP_KERNEL); |
668 | if (!rfkill) | 687 | if (!rfkill) |
669 | return NULL; | 688 | return NULL; |
@@ -736,11 +755,12 @@ int __must_check rfkill_register(struct rfkill *rfkill) | |||
736 | struct device *dev = &rfkill->dev; | 755 | struct device *dev = &rfkill->dev; |
737 | int error; | 756 | int error; |
738 | 757 | ||
739 | if (!rfkill->toggle_radio) | 758 | if (WARN((!rfkill || !rfkill->toggle_radio || |
740 | return -EINVAL; | 759 | rfkill->type >= RFKILL_TYPE_MAX || |
741 | if (rfkill->type >= RFKILL_TYPE_MAX) | 760 | rfkill->state >= RFKILL_STATE_MAX), |
742 | return -EINVAL; | 761 | KERN_WARNING |
743 | if (rfkill->state >= RFKILL_STATE_MAX) | 762 | "rfkill: attempt to register a " |
763 | "badly initialized rfkill struct\n")) | ||
744 | return -EINVAL; | 764 | return -EINVAL; |
745 | 765 | ||
746 | snprintf(dev->bus_id, sizeof(dev->bus_id), | 766 | snprintf(dev->bus_id, sizeof(dev->bus_id), |
@@ -775,6 +795,7 @@ EXPORT_SYMBOL(rfkill_register); | |||
775 | */ | 795 | */ |
776 | void rfkill_unregister(struct rfkill *rfkill) | 796 | void rfkill_unregister(struct rfkill *rfkill) |
777 | { | 797 | { |
798 | BUG_ON(!rfkill); | ||
778 | device_del(&rfkill->dev); | 799 | device_del(&rfkill->dev); |
779 | rfkill_remove_switch(rfkill); | 800 | rfkill_remove_switch(rfkill); |
780 | rfkill_led_trigger_unregister(rfkill); | 801 | rfkill_led_trigger_unregister(rfkill); |
@@ -811,9 +832,12 @@ int rfkill_set_default(enum rfkill_type type, enum rfkill_state state) | |||
811 | { | 832 | { |
812 | int error; | 833 | int error; |
813 | 834 | ||
814 | if (type >= RFKILL_TYPE_MAX || | 835 | if (WARN((type >= RFKILL_TYPE_MAX || |
815 | (state != RFKILL_STATE_SOFT_BLOCKED && | 836 | (state != RFKILL_STATE_SOFT_BLOCKED && |
816 | state != RFKILL_STATE_UNBLOCKED)) | 837 | state != RFKILL_STATE_UNBLOCKED)), |
838 | KERN_WARNING | ||
839 | "rfkill: illegal state %d or type %d passed as " | ||
840 | "parameter to rfkill_set_default\n", state, type)) | ||
817 | return -EINVAL; | 841 | return -EINVAL; |
818 | 842 | ||
819 | mutex_lock(&rfkill_mutex); | 843 | mutex_lock(&rfkill_mutex); |