1818#include <linux/stat.h>
1919#include <linux/slab.h>
2020
21- /**
22- * populate_dir - populate directory with attributes.
23- * @kobj: object we're working on.
24- *
25- * Most subsystems have a set of default attributes that
26- * are associated with an object that registers with them.
27- * This is a helper called during object registration that
28- * loops through the default attributes of the subsystem
29- * and creates attributes files for them in sysfs.
21+ /*
22+ * populate_dir - populate directory with attributes.
23+ * @kobj: object we're working on.
3024 *
25+ * Most subsystems have a set of default attributes that are associated
26+ * with an object that registers with them. This is a helper called during
27+ * object registration that loops through the default attributes of the
28+ * subsystem and creates attributes files for them in sysfs.
3129 */
32-
33- static int populate_dir (struct kobject * kobj )
30+ static int populate_dir (struct kobject * kobj )
3431{
35- struct kobj_type * t = get_ktype (kobj );
36- struct attribute * attr ;
32+ struct kobj_type * t = get_ktype (kobj );
33+ struct attribute * attr ;
3734 int error = 0 ;
3835 int i ;
39-
36+
4037 if (t && t -> default_attrs ) {
4138 for (i = 0 ; (attr = t -> default_attrs [i ]) != NULL ; i ++ ) {
42- if ((error = sysfs_create_file (kobj ,attr )))
39+ error = sysfs_create_file (kobj , attr );
40+ if (error )
4341 break ;
4442 }
4543 }
4644 return error ;
4745}
4846
49- static int create_dir (struct kobject * kobj )
47+ static int create_dir (struct kobject * kobj )
5048{
5149 int error = 0 ;
5250 if (kobject_name (kobj )) {
5351 error = sysfs_create_dir (kobj );
5452 if (!error ) {
55- if ((error = populate_dir (kobj )))
53+ error = populate_dir (kobj );
54+ if (error )
5655 sysfs_remove_dir (kobj );
5756 }
5857 }
5958 return error ;
6059}
6160
62- static inline struct kobject * to_kobj (struct list_head * entry )
61+ static inline struct kobject * to_kobj (struct list_head * entry )
6362{
64- return container_of (entry ,struct kobject ,entry );
63+ return container_of (entry , struct kobject , entry );
6564}
6665
6766static int get_kobj_path_length (struct kobject * kobj )
6867{
6968 int length = 1 ;
70- struct kobject * parent = kobj ;
69+ struct kobject * parent = kobj ;
7170
72- /* walk up the ancestors until we hit the one pointing to the
71+ /* walk up the ancestors until we hit the one pointing to the
7372 * root.
7473 * Add 1 to strlen for leading '/' of each level.
7574 */
@@ -84,19 +83,19 @@ static int get_kobj_path_length(struct kobject *kobj)
8483
8584static void fill_kobj_path (struct kobject * kobj , char * path , int length )
8685{
87- struct kobject * parent ;
86+ struct kobject * parent ;
8887
8988 -- length ;
9089 for (parent = kobj ; parent ; parent = parent -> parent ) {
9190 int cur = strlen (kobject_name (parent ));
9291 /* back up enough to print this name with '/' */
9392 length -= cur ;
94- strncpy (path + length , kobject_name (parent ), cur );
93+ strncpy (path + length , kobject_name (parent ), cur );
9594 * (path + -- length ) = '/' ;
9695 }
9796
9897 pr_debug ("kobject: '%s' (%p): %s: path = '%s'\n" , kobject_name (kobj ),
99- kobj , __FUNCTION__ ,path );
98+ kobj , __FUNCTION__ , path );
10099}
101100
102101/**
@@ -148,7 +147,7 @@ static void kobj_kset_leave(struct kobject *kobj)
148147 kset_put (kobj -> kset );
149148}
150149
151- static void kobject_init_internal (struct kobject * kobj )
150+ static void kobject_init_internal (struct kobject * kobj )
152151{
153152 if (!kobj )
154153 return ;
@@ -160,7 +159,7 @@ static void kobject_init_internal(struct kobject * kobj)
160159static int kobject_add_internal (struct kobject * kobj )
161160{
162161 int error = 0 ;
163- struct kobject * parent ;
162+ struct kobject * parent ;
164163
165164 if (!kobj )
166165 return - ENOENT ;
@@ -185,7 +184,7 @@ static int kobject_add_internal(struct kobject *kobj)
185184 pr_debug ("kobject: '%s' (%p): %s: parent: '%s', set: '%s'\n" ,
186185 kobject_name (kobj ), kobj , __FUNCTION__ ,
187186 parent ? kobject_name (parent ) : "<NULL>" ,
188- kobj -> kset ? kobject_name (& kobj -> kset -> kobj ) : "<NULL>" );
187+ kobj -> kset ? kobject_name (& kobj -> kset -> kobj ) : "<NULL>" );
189188
190189 error = create_dir (kobj );
191190 if (error ) {
@@ -399,12 +398,11 @@ int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,
399398EXPORT_SYMBOL_GPL (kobject_init_and_add );
400399
401400/**
402- * kobject_rename - change the name of an object
403- * @kobj: object in question.
404- * @new_name: object's new name
401+ * kobject_rename - change the name of an object
402+ * @kobj: object in question.
403+ * @new_name: object's new name
405404 */
406-
407- int kobject_rename (struct kobject * kobj , const char * new_name )
405+ int kobject_rename (struct kobject * kobj , const char * new_name )
408406{
409407 int error = 0 ;
410408 const char * devpath = NULL ;
@@ -461,11 +459,10 @@ int kobject_rename(struct kobject * kobj, const char *new_name)
461459}
462460
463461/**
464- * kobject_move - move object to another parent
465- * @kobj: object in question.
466- * @new_parent: object's new parent (can be NULL)
462+ * kobject_move - move object to another parent
463+ * @kobj: object in question.
464+ * @new_parent: object's new parent (can be NULL)
467465 */
468-
469466int kobject_move (struct kobject * kobj , struct kobject * new_parent )
470467{
471468 int error ;
@@ -513,11 +510,10 @@ int kobject_move(struct kobject *kobj, struct kobject *new_parent)
513510}
514511
515512/**
516- * kobject_del - unlink kobject from hierarchy.
517- * @kobj: object.
513+ * kobject_del - unlink kobject from hierarchy.
514+ * @kobj: object.
518515 */
519-
520- void kobject_del (struct kobject * kobj )
516+ void kobject_del (struct kobject * kobj )
521517{
522518 if (!kobj )
523519 return ;
@@ -530,11 +526,10 @@ void kobject_del(struct kobject * kobj)
530526}
531527
532528/**
533- * kobject_get - increment refcount for object.
534- * @kobj: object.
529+ * kobject_get - increment refcount for object.
530+ * @kobj: object.
535531 */
536-
537- struct kobject * kobject_get (struct kobject * kobj )
532+ struct kobject * kobject_get (struct kobject * kobj )
538533{
539534 if (kobj )
540535 kref_get (& kobj -> kref );
@@ -591,12 +586,12 @@ static void kobject_release(struct kref *kref)
591586}
592587
593588/**
594- * kobject_put - decrement refcount for object.
595- * @kobj: object.
589+ * kobject_put - decrement refcount for object.
590+ * @kobj: object.
596591 *
597- * Decrement the refcount, and if 0, call kobject_cleanup().
592+ * Decrement the refcount, and if 0, call kobject_cleanup().
598593 */
599- void kobject_put (struct kobject * kobj )
594+ void kobject_put (struct kobject * kobj )
600595{
601596 if (kobj )
602597 kref_put (& kobj -> kref , kobject_release );
@@ -670,11 +665,10 @@ struct kobject *kobject_create_and_add(const char *name, struct kobject *parent)
670665EXPORT_SYMBOL_GPL (kobject_create_and_add );
671666
672667/**
673- * kset_init - initialize a kset for use
674- * @k: kset
668+ * kset_init - initialize a kset for use
669+ * @k: kset
675670 */
676-
677- void kset_init (struct kset * k )
671+ void kset_init (struct kset * k )
678672{
679673 kobject_init_internal (& k -> kobj );
680674 INIT_LIST_HEAD (& k -> list );
@@ -712,11 +706,10 @@ struct sysfs_ops kobj_sysfs_ops = {
712706};
713707
714708/**
715- * kset_register - initialize and add a kset.
716- * @k: kset.
709+ * kset_register - initialize and add a kset.
710+ * @k: kset.
717711 */
718-
719- int kset_register (struct kset * k )
712+ int kset_register (struct kset * k )
720713{
721714 int err ;
722715
@@ -731,39 +724,35 @@ int kset_register(struct kset * k)
731724 return 0 ;
732725}
733726
734-
735727/**
736- * kset_unregister - remove a kset.
737- * @k: kset.
728+ * kset_unregister - remove a kset.
729+ * @k: kset.
738730 */
739-
740- void kset_unregister (struct kset * k )
731+ void kset_unregister (struct kset * k )
741732{
742733 if (!k )
743734 return ;
744735 kobject_put (& k -> kobj );
745736}
746737
747-
748738/**
749- * kset_find_obj - search for object in kset.
750- * @kset: kset we're looking in.
751- * @name: object's name.
739+ * kset_find_obj - search for object in kset.
740+ * @kset: kset we're looking in.
741+ * @name: object's name.
752742 *
753- * Lock kset via @kset->subsys, and iterate over @kset->list,
754- * looking for a matching kobject. If matching object is found
755- * take a reference and return the object.
743+ * Lock kset via @kset->subsys, and iterate over @kset->list,
744+ * looking for a matching kobject. If matching object is found
745+ * take a reference and return the object.
756746 */
757-
758- struct kobject * kset_find_obj (struct kset * kset , const char * name )
747+ struct kobject * kset_find_obj (struct kset * kset , const char * name )
759748{
760- struct list_head * entry ;
761- struct kobject * ret = NULL ;
749+ struct list_head * entry ;
750+ struct kobject * ret = NULL ;
762751
763752 spin_lock (& kset -> list_lock );
764- list_for_each (entry ,& kset -> list ) {
765- struct kobject * k = to_kobj (entry );
766- if (kobject_name (k ) && !strcmp (kobject_name (k ),name )) {
753+ list_for_each (entry , & kset -> list ) {
754+ struct kobject * k = to_kobj (entry );
755+ if (kobject_name (k ) && !strcmp (kobject_name (k ), name )) {
767756 ret = kobject_get (k );
768757 break ;
769758 }
0 commit comments