@@ -426,6 +426,9 @@ static void klp_free_object_dynamic(struct klp_object *obj)
426426 kfree (obj );
427427}
428428
429+ static struct kobj_type klp_ktype_object ;
430+ static struct kobj_type klp_ktype_func ;
431+
429432static struct klp_object * klp_alloc_object_dynamic (const char * name )
430433{
431434 struct klp_object * obj ;
@@ -443,6 +446,7 @@ static struct klp_object *klp_alloc_object_dynamic(const char *name)
443446 }
444447
445448 INIT_LIST_HEAD (& obj -> func_list );
449+ kobject_init (& obj -> kobj , & klp_ktype_object );
446450 obj -> dynamic = true;
447451
448452 return obj ;
@@ -471,6 +475,7 @@ static struct klp_func *klp_alloc_func_nop(struct klp_func *old_func,
471475 }
472476 }
473477
478+ kobject_init (& func -> kobj , & klp_ktype_func );
474479 /*
475480 * func->new_func is same as func->old_func. These addresses are
476481 * set when the object is loaded, see klp_init_object_loaded().
@@ -588,13 +593,7 @@ static void __klp_free_funcs(struct klp_object *obj, bool nops_only)
588593 continue ;
589594
590595 list_del (& func -> node );
591-
592- /* Might be called from klp_init_patch() error path. */
593- if (func -> kobj_added ) {
594- kobject_put (& func -> kobj );
595- } else if (func -> nop ) {
596- klp_free_func_nop (func );
597- }
596+ kobject_put (& func -> kobj );
598597 }
599598}
600599
@@ -624,13 +623,7 @@ static void __klp_free_objects(struct klp_patch *patch, bool nops_only)
624623 continue ;
625624
626625 list_del (& obj -> node );
627-
628- /* Might be called from klp_init_patch() error path. */
629- if (obj -> kobj_added ) {
630- kobject_put (& obj -> kobj );
631- } else if (obj -> dynamic ) {
632- klp_free_object_dynamic (obj );
633- }
626+ kobject_put (& obj -> kobj );
634627 }
635628}
636629
@@ -675,10 +668,8 @@ static void klp_free_patch_finish(struct klp_patch *patch)
675668 * this is called when the patch gets disabled and it
676669 * cannot get enabled again.
677670 */
678- if (patch -> kobj_added ) {
679- kobject_put (& patch -> kobj );
680- wait_for_completion (& patch -> finish );
681- }
671+ kobject_put (& patch -> kobj );
672+ wait_for_completion (& patch -> finish );
682673
683674 /* Put the module after the last access to struct klp_patch. */
684675 if (!patch -> forced )
@@ -700,8 +691,6 @@ static void klp_free_patch_work_fn(struct work_struct *work)
700691
701692static int klp_init_func (struct klp_object * obj , struct klp_func * func )
702693{
703- int ret ;
704-
705694 if (!func -> old_name )
706695 return - EINVAL ;
707696
@@ -724,13 +713,9 @@ static int klp_init_func(struct klp_object *obj, struct klp_func *func)
724713 * object. If the user selects 0 for old_sympos, then 1 will be used
725714 * since a unique symbol will be the first occurrence.
726715 */
727- ret = kobject_init_and_add (& func -> kobj , & klp_ktype_func ,
728- & obj -> kobj , "%s,%lu" , func -> old_name ,
729- func -> old_sympos ? func -> old_sympos : 1 );
730- if (!ret )
731- func -> kobj_added = true;
732-
733- return ret ;
716+ return kobject_add (& func -> kobj , & obj -> kobj , "%s,%lu" ,
717+ func -> old_name ,
718+ func -> old_sympos ? func -> old_sympos : 1 );
734719}
735720
736721/* Arches may override this to finish any remaining arch-specific tasks */
@@ -801,11 +786,9 @@ static int klp_init_object(struct klp_patch *patch, struct klp_object *obj)
801786 klp_find_object_module (obj );
802787
803788 name = klp_is_module (obj ) ? obj -> name : "vmlinux" ;
804- ret = kobject_init_and_add (& obj -> kobj , & klp_ktype_object ,
805- & patch -> kobj , "%s" , name );
789+ ret = kobject_add (& obj -> kobj , & patch -> kobj , "%s" , name );
806790 if (ret )
807791 return ret ;
808- obj -> kobj_added = true;
809792
810793 klp_for_each_func (obj , func ) {
811794 ret = klp_init_func (obj , func );
@@ -829,7 +812,7 @@ static int klp_init_patch_early(struct klp_patch *patch)
829812
830813 INIT_LIST_HEAD (& patch -> list );
831814 INIT_LIST_HEAD (& patch -> obj_list );
832- patch -> kobj_added = false ;
815+ kobject_init ( & patch -> kobj , & klp_ktype_patch ) ;
833816 patch -> enabled = false;
834817 patch -> forced = false;
835818 INIT_WORK (& patch -> free_work , klp_free_patch_work_fn );
@@ -840,11 +823,11 @@ static int klp_init_patch_early(struct klp_patch *patch)
840823 return - EINVAL ;
841824
842825 INIT_LIST_HEAD (& obj -> func_list );
843- obj -> kobj_added = false ;
826+ kobject_init ( & obj -> kobj , & klp_ktype_object ) ;
844827 list_add_tail (& obj -> node , & patch -> obj_list );
845828
846829 klp_for_each_func_static (obj , func ) {
847- func -> kobj_added = false ;
830+ kobject_init ( & func -> kobj , & klp_ktype_func ) ;
848831 list_add_tail (& func -> node , & obj -> func_list );
849832 }
850833 }
@@ -860,11 +843,9 @@ static int klp_init_patch(struct klp_patch *patch)
860843 struct klp_object * obj ;
861844 int ret ;
862845
863- ret = kobject_init_and_add (& patch -> kobj , & klp_ktype_patch ,
864- klp_root_kobj , "%s" , patch -> mod -> name );
846+ ret = kobject_add (& patch -> kobj , klp_root_kobj , "%s" , patch -> mod -> name );
865847 if (ret )
866848 return ret ;
867- patch -> kobj_added = true;
868849
869850 if (patch -> replace ) {
870851 ret = klp_add_nops (patch );
@@ -926,9 +907,6 @@ static int __klp_enable_patch(struct klp_patch *patch)
926907 if (WARN_ON (patch -> enabled ))
927908 return - EINVAL ;
928909
929- if (!patch -> kobj_added )
930- return - EINVAL ;
931-
932910 pr_notice ("enabling patch '%s'\n" , patch -> mod -> name );
933911
934912 klp_init_transition (patch , KLP_PATCHED );
0 commit comments