@@ -115,18 +115,18 @@ static int serio_match_port(const struct serio_device_id *ids, struct serio *ser
115115 * Basic serio -> driver core mappings
116116 */
117117
118- static void serio_bind_driver (struct serio * serio , struct serio_driver * drv )
118+ static int serio_bind_driver (struct serio * serio , struct serio_driver * drv )
119119{
120120 int error ;
121121
122- down_write (& serio_bus .subsys .rwsem );
123-
124122 if (serio_match_port (drv -> id_table , serio )) {
123+
125124 serio -> dev .driver = & drv -> driver ;
126125 if (serio_connect_driver (serio , drv )) {
127126 serio -> dev .driver = NULL ;
128- goto out ;
127+ return - ENODEV ;
129128 }
129+
130130 error = device_bind_driver (& serio -> dev );
131131 if (error ) {
132132 printk (KERN_WARNING
@@ -136,31 +136,21 @@ static void serio_bind_driver(struct serio *serio, struct serio_driver *drv)
136136 drv -> description , error );
137137 serio_disconnect_driver (serio );
138138 serio -> dev .driver = NULL ;
139- goto out ;
139+ return error ;
140140 }
141141 }
142- out :
143- up_write (& serio_bus .subsys .rwsem );
144- }
145-
146- static void serio_release_driver (struct serio * serio )
147- {
148- down_write (& serio_bus .subsys .rwsem );
149- device_release_driver (& serio -> dev );
150- up_write (& serio_bus .subsys .rwsem );
142+ return 0 ;
151143}
152144
153145static void serio_find_driver (struct serio * serio )
154146{
155147 int error ;
156148
157- down_write (& serio_bus .subsys .rwsem );
158149 error = device_attach (& serio -> dev );
159150 if (error < 0 )
160151 printk (KERN_WARNING
161152 "serio: device_attach() failed for %s (%s), error: %d\n" ,
162153 serio -> phys , serio -> name , error );
163- up_write (& serio_bus .subsys .rwsem );
164154}
165155
166156
@@ -470,13 +460,12 @@ static ssize_t serio_rebind_driver(struct device *dev, struct device_attribute *
470460{
471461 struct serio * serio = to_serio_port (dev );
472462 struct device_driver * drv ;
473- int retval ;
463+ int error ;
474464
475- retval = mutex_lock_interruptible (& serio_mutex );
476- if (retval )
477- return retval ;
465+ error = mutex_lock_interruptible (& serio_mutex );
466+ if (error )
467+ return error ;
478468
479- retval = count ;
480469 if (!strncmp (buf , "none" , count )) {
481470 serio_disconnect_port (serio );
482471 } else if (!strncmp (buf , "reconnect" , count )) {
@@ -486,15 +475,15 @@ static ssize_t serio_rebind_driver(struct device *dev, struct device_attribute *
486475 serio_find_driver (serio );
487476 } else if ((drv = driver_find (buf , & serio_bus )) != NULL ) {
488477 serio_disconnect_port (serio );
489- serio_bind_driver (serio , to_serio_driver (drv ));
478+ error = serio_bind_driver (serio , to_serio_driver (drv ));
490479 put_driver (drv );
491480 } else {
492- retval = - EINVAL ;
481+ error = - EINVAL ;
493482 }
494483
495484 mutex_unlock (& serio_mutex );
496485
497- return retval ;
486+ return error ? error : count ;
498487}
499488
500489static ssize_t serio_show_bind_mode (struct device * dev , struct device_attribute * attr , char * buf )
@@ -665,15 +654,15 @@ static void serio_disconnect_port(struct serio *serio)
665654 do {
666655 parent = s -> parent ;
667656
668- serio_release_driver ( s );
657+ device_release_driver ( & s -> dev );
669658 serio_destroy_port (s );
670659 } while ((s = parent ) != serio );
671660 }
672661
673662 /*
674663 * Ok, no children left, now disconnect this port
675664 */
676- serio_release_driver ( serio );
665+ device_release_driver ( & serio -> dev );
677666}
678667
679668void serio_rescan (struct serio * serio )
0 commit comments