aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDu, Changbin <changbin.du@intel.com>2016-05-19 20:09:20 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-05-19 22:12:14 -0400
commitb1e4d9d82df8ab9097f80aa208c40eab6fc29858 (patch)
treeb62106f744b91e4851dc50059ed5ce5f19ead66e
parentb21e91c305bcebf55b7a34638e5885528f3fb453 (diff)
debugobjects: make fixup functions return bool instead of int
I am going to introduce debugobjects infrastructure to USB subsystem. But before this, I found the code of debugobjects could be improved. This patchset will make fixup functions return bool type instead of int. Because fixup only need report success or no. boolean is the 'real' type. This patch (of 7): The object debugging infrastructure core provides some fixup callbacks for the subsystem who use it. These callbacks are called from the debug code whenever a problem in debug_object_init is detected. And debugobjects core suppose them returns 1 when the fixup was successful, otherwise 0. So the return type is boolean. A bad thing is that debug_object_fixup use the return value for arithmetic operation. It confused me that what is the reall return type. Reading over the whole code, I found some place do use the return value incorrectly(see next patch). So why use bool type instead? Signed-off-by: Du, Changbin <changbin.du@intel.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Josh Triplett <josh@kernel.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Tejun Heo <tj@kernel.org> Cc: Christian Borntraeger <borntraeger@de.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--include/linux/debugobjects.h15
-rw-r--r--lib/debugobjects.c43
2 files changed, 29 insertions, 29 deletions
diff --git a/include/linux/debugobjects.h b/include/linux/debugobjects.h
index 98ffcbd4888e..a899f10c9365 100644
--- a/include/linux/debugobjects.h
+++ b/include/linux/debugobjects.h
@@ -39,7 +39,8 @@ struct debug_obj {
39 * @debug_hint: function returning address, which have associated 39 * @debug_hint: function returning address, which have associated
40 * kernel symbol, to allow identify the object 40 * kernel symbol, to allow identify the object
41 * @fixup_init: fixup function, which is called when the init check 41 * @fixup_init: fixup function, which is called when the init check
42 * fails 42 * fails. All fixup functions must return true if fixup
43 * was successful, otherwise return false
43 * @fixup_activate: fixup function, which is called when the activate check 44 * @fixup_activate: fixup function, which is called when the activate check
44 * fails 45 * fails
45 * @fixup_destroy: fixup function, which is called when the destroy check 46 * @fixup_destroy: fixup function, which is called when the destroy check
@@ -51,12 +52,12 @@ struct debug_obj {
51 */ 52 */
52struct debug_obj_descr { 53struct debug_obj_descr {
53 const char *name; 54 const char *name;
54 void *(*debug_hint) (void *addr); 55 void *(*debug_hint)(void *addr);
55 int (*fixup_init) (void *addr, enum debug_obj_state state); 56 bool (*fixup_init)(void *addr, enum debug_obj_state state);
56 int (*fixup_activate) (void *addr, enum debug_obj_state state); 57 bool (*fixup_activate)(void *addr, enum debug_obj_state state);
57 int (*fixup_destroy) (void *addr, enum debug_obj_state state); 58 bool (*fixup_destroy)(void *addr, enum debug_obj_state state);
58 int (*fixup_free) (void *addr, enum debug_obj_state state); 59 bool (*fixup_free)(void *addr, enum debug_obj_state state);
59 int (*fixup_assert_init)(void *addr, enum debug_obj_state state); 60 bool (*fixup_assert_init)(void *addr, enum debug_obj_state state);
60}; 61};
61 62
62#ifdef CONFIG_DEBUG_OBJECTS 63#ifdef CONFIG_DEBUG_OBJECTS
diff --git a/lib/debugobjects.c b/lib/debugobjects.c
index 519b5a10fd70..a9cee165cf25 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 */
272static int 272static bool
273debug_object_fixup(int (*fixup)(void *addr, enum debug_obj_state state), 273debug_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
284static void debug_object_is_on_stack(void *addr, int onstack) 283static void debug_object_is_on_stack(void *addr, int onstack)
@@ -797,7 +796,7 @@ static __initdata struct debug_obj_descr descr_type_test;
797 * fixup_init is called when: 796 * fixup_init is called when:
798 * - an active object is initialized 797 * - an active object is initialized
799 */ 798 */
800static int __init fixup_init(void *addr, enum debug_obj_state state) 799static bool __init fixup_init(void *addr, enum debug_obj_state state)
801{ 800{
802 struct self_test *obj = addr; 801 struct self_test *obj = addr;
803 802
@@ -805,9 +804,9 @@ static int __init fixup_init(void *addr, enum debug_obj_state state)
805 case ODEBUG_STATE_ACTIVE: 804 case ODEBUG_STATE_ACTIVE:
806 debug_object_deactivate(obj, &descr_type_test); 805 debug_object_deactivate(obj, &descr_type_test);
807 debug_object_init(obj, &descr_type_test); 806 debug_object_init(obj, &descr_type_test);
808 return 1; 807 return true;
809 default: 808 default:
810 return 0; 809 return false;
811 } 810 }
812} 811}
813 812
@@ -816,7 +815,7 @@ static int __init fixup_init(void *addr, enum debug_obj_state state)
816 * - an active object is activated 815 * - an active object is activated
817 * - an unknown object is activated (might be a statically initialized object) 816 * - an unknown object is activated (might be a statically initialized object)
818 */ 817 */
819static int __init fixup_activate(void *addr, enum debug_obj_state state) 818static bool __init fixup_activate(void *addr, enum debug_obj_state state)
820{ 819{
821 struct self_test *obj = addr; 820 struct self_test *obj = addr;
822 821
@@ -825,17 +824,17 @@ static int __init fixup_activate(void *addr, enum debug_obj_state state)
825 if (obj->static_init == 1) { 824 if (obj->static_init == 1) {
826 debug_object_init(obj, &descr_type_test); 825 debug_object_init(obj, &descr_type_test);
827 debug_object_activate(obj, &descr_type_test); 826 debug_object_activate(obj, &descr_type_test);
828 return 0; 827 return false;
829 } 828 }
830 return 1; 829 return true;
831 830
832 case ODEBUG_STATE_ACTIVE: 831 case ODEBUG_STATE_ACTIVE:
833 debug_object_deactivate(obj, &descr_type_test); 832 debug_object_deactivate(obj, &descr_type_test);
834 debug_object_activate(obj, &descr_type_test); 833 debug_object_activate(obj, &descr_type_test);
835 return 1; 834 return true;
836 835
837 default: 836 default:
838 return 0; 837 return false;
839 } 838 }
840} 839}
841 840
@@ -843,7 +842,7 @@ static int __init fixup_activate(void *addr, enum debug_obj_state state)
843 * fixup_destroy is called when: 842 * fixup_destroy is called when:
844 * - an active object is destroyed 843 * - an active object is destroyed
845 */ 844 */
846static int __init fixup_destroy(void *addr, enum debug_obj_state state) 845static bool __init fixup_destroy(void *addr, enum debug_obj_state state)
847{ 846{
848 struct self_test *obj = addr; 847 struct self_test *obj = addr;
849 848
@@ -851,9 +850,9 @@ static int __init fixup_destroy(void *addr, enum debug_obj_state state)
851 case ODEBUG_STATE_ACTIVE: 850 case ODEBUG_STATE_ACTIVE:
852 debug_object_deactivate(obj, &descr_type_test); 851 debug_object_deactivate(obj, &descr_type_test);
853 debug_object_destroy(obj, &descr_type_test); 852 debug_object_destroy(obj, &descr_type_test);
854 return 1; 853 return true;
855 default: 854 default:
856 return 0; 855 return false;
857 } 856 }
858} 857}
859 858
@@ -861,7 +860,7 @@ static int __init fixup_destroy(void *addr, enum debug_obj_state state)
861 * fixup_free is called when: 860 * fixup_free is called when:
862 * - an active object is freed 861 * - an active object is freed
863 */ 862 */
864static int __init fixup_free(void *addr, enum debug_obj_state state) 863static bool __init fixup_free(void *addr, enum debug_obj_state state)
865{ 864{
866 struct self_test *obj = addr; 865 struct self_test *obj = addr;
867 866
@@ -869,9 +868,9 @@ static int __init fixup_free(void *addr, enum debug_obj_state state)
869 case ODEBUG_STATE_ACTIVE: 868 case ODEBUG_STATE_ACTIVE:
870 debug_object_deactivate(obj, &descr_type_test); 869 debug_object_deactivate(obj, &descr_type_test);
871 debug_object_free(obj, &descr_type_test); 870 debug_object_free(obj, &descr_type_test);
872 return 1; 871 return true;
873 default: 872 default:
874 return 0; 873 return false;
875 } 874 }
876} 875}
877 876