diff options
Diffstat (limited to 'lib/debugobjects.c')
| -rw-r--r-- | lib/debugobjects.c | 92 |
1 files changed, 53 insertions, 39 deletions
diff --git a/lib/debugobjects.c b/lib/debugobjects.c index 519b5a10fd70..a8e12601eb37 100644 --- a/lib/debugobjects.c +++ b/lib/debugobjects.c | |||
| @@ -269,16 +269,15 @@ static void debug_print_object(struct debug_obj *obj, char *msg) | |||
| 269 | * Try to repair the damage, so we have a better chance to get useful | 269 | * Try to repair the damage, so we have a better chance to get useful |
| 270 | * debug output. | 270 | * debug output. |
| 271 | */ | 271 | */ |
| 272 | static int | 272 | static bool |
| 273 | debug_object_fixup(int (*fixup)(void *addr, enum debug_obj_state state), | 273 | debug_object_fixup(bool (*fixup)(void *addr, enum debug_obj_state state), |
| 274 | void * addr, enum debug_obj_state state) | 274 | void * addr, enum debug_obj_state state) |
| 275 | { | 275 | { |
| 276 | int fixed = 0; | 276 | if (fixup && fixup(addr, state)) { |
| 277 | 277 | debug_objects_fixups++; | |
| 278 | if (fixup) | 278 | return true; |
| 279 | fixed = fixup(addr, state); | 279 | } |
| 280 | debug_objects_fixups += fixed; | 280 | return false; |
| 281 | return fixed; | ||
| 282 | } | 281 | } |
| 283 | 282 | ||
| 284 | static void debug_object_is_on_stack(void *addr, int onstack) | 283 | static void debug_object_is_on_stack(void *addr, int onstack) |
| @@ -416,7 +415,7 @@ int debug_object_activate(void *addr, struct debug_obj_descr *descr) | |||
| 416 | state = obj->state; | 415 | state = obj->state; |
| 417 | raw_spin_unlock_irqrestore(&db->lock, flags); | 416 | raw_spin_unlock_irqrestore(&db->lock, flags); |
| 418 | ret = debug_object_fixup(descr->fixup_activate, addr, state); | 417 | ret = debug_object_fixup(descr->fixup_activate, addr, state); |
| 419 | return ret ? -EINVAL : 0; | 418 | return ret ? 0 : -EINVAL; |
| 420 | 419 | ||
| 421 | case ODEBUG_STATE_DESTROYED: | 420 | case ODEBUG_STATE_DESTROYED: |
| 422 | debug_print_object(obj, "activate"); | 421 | debug_print_object(obj, "activate"); |
| @@ -432,14 +431,21 @@ int debug_object_activate(void *addr, struct debug_obj_descr *descr) | |||
| 432 | 431 | ||
| 433 | raw_spin_unlock_irqrestore(&db->lock, flags); | 432 | raw_spin_unlock_irqrestore(&db->lock, flags); |
| 434 | /* | 433 | /* |
| 435 | * This happens when a static object is activated. We | 434 | * We are here when a static object is activated. We |
| 436 | * let the type specific code decide whether this is | 435 | * let the type specific code confirm whether this is |
| 437 | * true or not. | 436 | * true or not. if true, we just make sure that the |
| 437 | * static object is tracked in the object tracker. If | ||
| 438 | * not, this must be a bug, so we try to fix it up. | ||
| 438 | */ | 439 | */ |
| 439 | if (debug_object_fixup(descr->fixup_activate, addr, | 440 | if (descr->is_static_object && descr->is_static_object(addr)) { |
| 440 | ODEBUG_STATE_NOTAVAILABLE)) { | 441 | /* track this static object */ |
| 442 | debug_object_init(addr, descr); | ||
| 443 | debug_object_activate(addr, descr); | ||
| 444 | } else { | ||
| 441 | debug_print_object(&o, "activate"); | 445 | debug_print_object(&o, "activate"); |
| 442 | return -EINVAL; | 446 | ret = debug_object_fixup(descr->fixup_activate, addr, |
| 447 | ODEBUG_STATE_NOTAVAILABLE); | ||
| 448 | return ret ? 0 : -EINVAL; | ||
| 443 | } | 449 | } |
| 444 | return 0; | 450 | return 0; |
| 445 | } | 451 | } |
| @@ -603,12 +609,18 @@ void debug_object_assert_init(void *addr, struct debug_obj_descr *descr) | |||
| 603 | 609 | ||
| 604 | raw_spin_unlock_irqrestore(&db->lock, flags); | 610 | raw_spin_unlock_irqrestore(&db->lock, flags); |
| 605 | /* | 611 | /* |
| 606 | * Maybe the object is static. Let the type specific | 612 | * Maybe the object is static, and we let the type specific |
| 607 | * code decide what to do. | 613 | * code confirm. Track this static object if true, else invoke |
| 614 | * fixup. | ||
| 608 | */ | 615 | */ |
| 609 | if (debug_object_fixup(descr->fixup_assert_init, addr, | 616 | if (descr->is_static_object && descr->is_static_object(addr)) { |
| 610 | ODEBUG_STATE_NOTAVAILABLE)) | 617 | /* Track this static object */ |
| 618 | debug_object_init(addr, descr); | ||
| 619 | } else { | ||
| 611 | debug_print_object(&o, "assert_init"); | 620 | debug_print_object(&o, "assert_init"); |
| 621 | debug_object_fixup(descr->fixup_assert_init, addr, | ||
| 622 | ODEBUG_STATE_NOTAVAILABLE); | ||
| 623 | } | ||
| 612 | return; | 624 | return; |
| 613 | } | 625 | } |
| 614 | 626 | ||
| @@ -793,11 +805,18 @@ struct self_test { | |||
| 793 | 805 | ||
| 794 | static __initdata struct debug_obj_descr descr_type_test; | 806 | static __initdata struct debug_obj_descr descr_type_test; |
| 795 | 807 | ||
| 808 | static bool __init is_static_object(void *addr) | ||
| 809 | { | ||
| 810 | struct self_test *obj = addr; | ||
| 811 | |||
| 812 | return obj->static_init; | ||
| 813 | } | ||
| 814 | |||
| 796 | /* | 815 | /* |
| 797 | * fixup_init is called when: | 816 | * fixup_init is called when: |
| 798 | * - an active object is initialized | 817 | * - an active object is initialized |
| 799 | */ | 818 | */ |
| 800 | static int __init fixup_init(void *addr, enum debug_obj_state state) | 819 | static bool __init fixup_init(void *addr, enum debug_obj_state state) |
| 801 | { | 820 | { |
| 802 | struct self_test *obj = addr; | 821 | struct self_test *obj = addr; |
| 803 | 822 | ||
| @@ -805,37 +824,31 @@ static int __init fixup_init(void *addr, enum debug_obj_state state) | |||
| 805 | case ODEBUG_STATE_ACTIVE: | 824 | case ODEBUG_STATE_ACTIVE: |
| 806 | debug_object_deactivate(obj, &descr_type_test); | 825 | debug_object_deactivate(obj, &descr_type_test); |
| 807 | debug_object_init(obj, &descr_type_test); | 826 | debug_object_init(obj, &descr_type_test); |
| 808 | return 1; | 827 | return true; |
| 809 | default: | 828 | default: |
| 810 | return 0; | 829 | return false; |
| 811 | } | 830 | } |
| 812 | } | 831 | } |
| 813 | 832 | ||
| 814 | /* | 833 | /* |
| 815 | * fixup_activate is called when: | 834 | * fixup_activate is called when: |
| 816 | * - an active object is activated | 835 | * - an active object is activated |
| 817 | * - an unknown object is activated (might be a statically initialized object) | 836 | * - an unknown non-static object is activated |
| 818 | */ | 837 | */ |
| 819 | static int __init fixup_activate(void *addr, enum debug_obj_state state) | 838 | static bool __init fixup_activate(void *addr, enum debug_obj_state state) |
| 820 | { | 839 | { |
| 821 | struct self_test *obj = addr; | 840 | struct self_test *obj = addr; |
| 822 | 841 | ||
| 823 | switch (state) { | 842 | switch (state) { |
| 824 | case ODEBUG_STATE_NOTAVAILABLE: | 843 | case ODEBUG_STATE_NOTAVAILABLE: |
| 825 | if (obj->static_init == 1) { | 844 | return true; |
| 826 | debug_object_init(obj, &descr_type_test); | ||
| 827 | debug_object_activate(obj, &descr_type_test); | ||
| 828 | return 0; | ||
| 829 | } | ||
| 830 | return 1; | ||
| 831 | |||
| 832 | case ODEBUG_STATE_ACTIVE: | 845 | case ODEBUG_STATE_ACTIVE: |
| 833 | debug_object_deactivate(obj, &descr_type_test); | 846 | debug_object_deactivate(obj, &descr_type_test); |
| 834 | debug_object_activate(obj, &descr_type_test); | 847 | debug_object_activate(obj, &descr_type_test); |
| 835 | return 1; | 848 | return true; |
| 836 | 849 | ||
| 837 | default: | 850 | default: |
| 838 | return 0; | 851 | return false; |
| 839 | } | 852 | } |
| 840 | } | 853 | } |
| 841 | 854 | ||
| @@ -843,7 +856,7 @@ static int __init fixup_activate(void *addr, enum debug_obj_state state) | |||
| 843 | * fixup_destroy is called when: | 856 | * fixup_destroy is called when: |
| 844 | * - an active object is destroyed | 857 | * - an active object is destroyed |
| 845 | */ | 858 | */ |
| 846 | static int __init fixup_destroy(void *addr, enum debug_obj_state state) | 859 | static bool __init fixup_destroy(void *addr, enum debug_obj_state state) |
| 847 | { | 860 | { |
| 848 | struct self_test *obj = addr; | 861 | struct self_test *obj = addr; |
| 849 | 862 | ||
| @@ -851,9 +864,9 @@ static int __init fixup_destroy(void *addr, enum debug_obj_state state) | |||
| 851 | case ODEBUG_STATE_ACTIVE: | 864 | case ODEBUG_STATE_ACTIVE: |
| 852 | debug_object_deactivate(obj, &descr_type_test); | 865 | debug_object_deactivate(obj, &descr_type_test); |
| 853 | debug_object_destroy(obj, &descr_type_test); | 866 | debug_object_destroy(obj, &descr_type_test); |
| 854 | return 1; | 867 | return true; |
| 855 | default: | 868 | default: |
| 856 | return 0; | 869 | return false; |
| 857 | } | 870 | } |
| 858 | } | 871 | } |
| 859 | 872 | ||
| @@ -861,7 +874,7 @@ static int __init fixup_destroy(void *addr, enum debug_obj_state state) | |||
| 861 | * fixup_free is called when: | 874 | * fixup_free is called when: |
| 862 | * - an active object is freed | 875 | * - an active object is freed |
| 863 | */ | 876 | */ |
| 864 | static int __init fixup_free(void *addr, enum debug_obj_state state) | 877 | static bool __init fixup_free(void *addr, enum debug_obj_state state) |
| 865 | { | 878 | { |
| 866 | struct self_test *obj = addr; | 879 | struct self_test *obj = addr; |
| 867 | 880 | ||
| @@ -869,9 +882,9 @@ static int __init fixup_free(void *addr, enum debug_obj_state state) | |||
| 869 | case ODEBUG_STATE_ACTIVE: | 882 | case ODEBUG_STATE_ACTIVE: |
| 870 | debug_object_deactivate(obj, &descr_type_test); | 883 | debug_object_deactivate(obj, &descr_type_test); |
| 871 | debug_object_free(obj, &descr_type_test); | 884 | debug_object_free(obj, &descr_type_test); |
| 872 | return 1; | 885 | return true; |
| 873 | default: | 886 | default: |
| 874 | return 0; | 887 | return false; |
| 875 | } | 888 | } |
| 876 | } | 889 | } |
| 877 | 890 | ||
| @@ -917,6 +930,7 @@ out: | |||
| 917 | 930 | ||
| 918 | static __initdata struct debug_obj_descr descr_type_test = { | 931 | static __initdata struct debug_obj_descr descr_type_test = { |
| 919 | .name = "selftest", | 932 | .name = "selftest", |
| 933 | .is_static_object = is_static_object, | ||
| 920 | .fixup_init = fixup_init, | 934 | .fixup_init = fixup_init, |
| 921 | .fixup_activate = fixup_activate, | 935 | .fixup_activate = fixup_activate, |
| 922 | .fixup_destroy = fixup_destroy, | 936 | .fixup_destroy = fixup_destroy, |
