@@ -528,6 +528,7 @@ static void
528528__debug_object_init (void * addr , struct debug_obj_descr * descr , int onstack )
529529{
530530 enum debug_obj_state state ;
531+ bool check_stack = false;
531532 struct debug_bucket * db ;
532533 struct debug_obj * obj ;
533534 unsigned long flags ;
@@ -547,7 +548,7 @@ __debug_object_init(void *addr, struct debug_obj_descr *descr, int onstack)
547548 debug_objects_oom ();
548549 return ;
549550 }
550- debug_object_is_on_stack ( addr , onstack ) ;
551+ check_stack = true ;
551552 }
552553
553554 switch (obj -> state ) {
@@ -558,20 +559,23 @@ __debug_object_init(void *addr, struct debug_obj_descr *descr, int onstack)
558559 break ;
559560
560561 case ODEBUG_STATE_ACTIVE :
561- debug_print_object (obj , "init" );
562562 state = obj -> state ;
563563 raw_spin_unlock_irqrestore (& db -> lock , flags );
564+ debug_print_object (obj , "init" );
564565 debug_object_fixup (descr -> fixup_init , addr , state );
565566 return ;
566567
567568 case ODEBUG_STATE_DESTROYED :
569+ raw_spin_unlock_irqrestore (& db -> lock , flags );
568570 debug_print_object (obj , "init" );
569- break ;
571+ return ;
570572 default :
571573 break ;
572574 }
573575
574576 raw_spin_unlock_irqrestore (& db -> lock , flags );
577+ if (check_stack )
578+ debug_object_is_on_stack (addr , onstack );
575579}
576580
577581/**
@@ -629,6 +633,8 @@ int debug_object_activate(void *addr, struct debug_obj_descr *descr)
629633
630634 obj = lookup_object (addr , db );
631635 if (obj ) {
636+ bool print_object = false;
637+
632638 switch (obj -> state ) {
633639 case ODEBUG_STATE_INIT :
634640 case ODEBUG_STATE_INACTIVE :
@@ -637,25 +643,28 @@ int debug_object_activate(void *addr, struct debug_obj_descr *descr)
637643 break ;
638644
639645 case ODEBUG_STATE_ACTIVE :
640- debug_print_object (obj , "activate" );
641646 state = obj -> state ;
642647 raw_spin_unlock_irqrestore (& db -> lock , flags );
648+ debug_print_object (obj , "activate" );
643649 ret = debug_object_fixup (descr -> fixup_activate , addr , state );
644650 return ret ? 0 : - EINVAL ;
645651
646652 case ODEBUG_STATE_DESTROYED :
647- debug_print_object ( obj , "activate" ) ;
653+ print_object = true ;
648654 ret = - EINVAL ;
649655 break ;
650656 default :
651657 ret = 0 ;
652658 break ;
653659 }
654660 raw_spin_unlock_irqrestore (& db -> lock , flags );
661+ if (print_object )
662+ debug_print_object (obj , "activate" );
655663 return ret ;
656664 }
657665
658666 raw_spin_unlock_irqrestore (& db -> lock , flags );
667+
659668 /*
660669 * We are here when a static object is activated. We
661670 * let the type specific code confirm whether this is
@@ -687,6 +696,7 @@ void debug_object_deactivate(void *addr, struct debug_obj_descr *descr)
687696 struct debug_bucket * db ;
688697 struct debug_obj * obj ;
689698 unsigned long flags ;
699+ bool print_object = false;
690700
691701 if (!debug_objects_enabled )
692702 return ;
@@ -704,24 +714,27 @@ void debug_object_deactivate(void *addr, struct debug_obj_descr *descr)
704714 if (!obj -> astate )
705715 obj -> state = ODEBUG_STATE_INACTIVE ;
706716 else
707- debug_print_object ( obj , "deactivate" ) ;
717+ print_object = true ;
708718 break ;
709719
710720 case ODEBUG_STATE_DESTROYED :
711- debug_print_object ( obj , "deactivate" ) ;
721+ print_object = true ;
712722 break ;
713723 default :
714724 break ;
715725 }
716- } else {
726+ }
727+
728+ raw_spin_unlock_irqrestore (& db -> lock , flags );
729+ if (!obj ) {
717730 struct debug_obj o = { .object = addr ,
718731 .state = ODEBUG_STATE_NOTAVAILABLE ,
719732 .descr = descr };
720733
721734 debug_print_object (& o , "deactivate" );
735+ } else if (print_object ) {
736+ debug_print_object (obj , "deactivate" );
722737 }
723-
724- raw_spin_unlock_irqrestore (& db -> lock , flags );
725738}
726739EXPORT_SYMBOL_GPL (debug_object_deactivate );
727740
@@ -736,6 +749,7 @@ void debug_object_destroy(void *addr, struct debug_obj_descr *descr)
736749 struct debug_bucket * db ;
737750 struct debug_obj * obj ;
738751 unsigned long flags ;
752+ bool print_object = false;
739753
740754 if (!debug_objects_enabled )
741755 return ;
@@ -755,20 +769,22 @@ void debug_object_destroy(void *addr, struct debug_obj_descr *descr)
755769 obj -> state = ODEBUG_STATE_DESTROYED ;
756770 break ;
757771 case ODEBUG_STATE_ACTIVE :
758- debug_print_object (obj , "destroy" );
759772 state = obj -> state ;
760773 raw_spin_unlock_irqrestore (& db -> lock , flags );
774+ debug_print_object (obj , "destroy" );
761775 debug_object_fixup (descr -> fixup_destroy , addr , state );
762776 return ;
763777
764778 case ODEBUG_STATE_DESTROYED :
765- debug_print_object ( obj , "destroy" ) ;
779+ print_object = true ;
766780 break ;
767781 default :
768782 break ;
769783 }
770784out_unlock :
771785 raw_spin_unlock_irqrestore (& db -> lock , flags );
786+ if (print_object )
787+ debug_print_object (obj , "destroy" );
772788}
773789EXPORT_SYMBOL_GPL (debug_object_destroy );
774790
@@ -797,9 +813,9 @@ void debug_object_free(void *addr, struct debug_obj_descr *descr)
797813
798814 switch (obj -> state ) {
799815 case ODEBUG_STATE_ACTIVE :
800- debug_print_object (obj , "free" );
801816 state = obj -> state ;
802817 raw_spin_unlock_irqrestore (& db -> lock , flags );
818+ debug_print_object (obj , "free" );
803819 debug_object_fixup (descr -> fixup_free , addr , state );
804820 return ;
805821 default :
@@ -872,6 +888,7 @@ debug_object_active_state(void *addr, struct debug_obj_descr *descr,
872888 struct debug_bucket * db ;
873889 struct debug_obj * obj ;
874890 unsigned long flags ;
891+ bool print_object = false;
875892
876893 if (!debug_objects_enabled )
877894 return ;
@@ -887,22 +904,25 @@ debug_object_active_state(void *addr, struct debug_obj_descr *descr,
887904 if (obj -> astate == expect )
888905 obj -> astate = next ;
889906 else
890- debug_print_object ( obj , "active_state" ) ;
907+ print_object = true ;
891908 break ;
892909
893910 default :
894- debug_print_object ( obj , "active_state" ) ;
911+ print_object = true ;
895912 break ;
896913 }
897- } else {
914+ }
915+
916+ raw_spin_unlock_irqrestore (& db -> lock , flags );
917+ if (!obj ) {
898918 struct debug_obj o = { .object = addr ,
899919 .state = ODEBUG_STATE_NOTAVAILABLE ,
900920 .descr = descr };
901921
902922 debug_print_object (& o , "active_state" );
923+ } else if (print_object ) {
924+ debug_print_object (obj , "active_state" );
903925 }
904-
905- raw_spin_unlock_irqrestore (& db -> lock , flags );
906926}
907927EXPORT_SYMBOL_GPL (debug_object_active_state );
908928
@@ -937,10 +957,10 @@ static void __debug_check_no_obj_freed(const void *address, unsigned long size)
937957
938958 switch (obj -> state ) {
939959 case ODEBUG_STATE_ACTIVE :
940- debug_print_object (obj , "free" );
941960 descr = obj -> descr ;
942961 state = obj -> state ;
943962 raw_spin_unlock_irqrestore (& db -> lock , flags );
963+ debug_print_object (obj , "free" );
944964 debug_object_fixup (descr -> fixup_free ,
945965 (void * ) oaddr , state );
946966 goto repeat ;
0 commit comments