File tree Expand file tree Collapse file tree 1 file changed +8
-14
lines changed
Expand file tree Collapse file tree 1 file changed +8
-14
lines changed Original file line number Diff line number Diff line change @@ -810,32 +810,26 @@ int device_set_subsystem(sd_device *device, const char *subsystem) {
810810
811811int device_set_drivers_subsystem (sd_device * device ) {
812812 _cleanup_free_ char * subsystem = NULL ;
813- const char * syspath , * drivers , * p ;
813+ const char * devpath , * drivers , * p ;
814814 int r ;
815815
816816 assert (device );
817817
818- r = sd_device_get_syspath (device , & syspath );
818+ r = sd_device_get_devpath (device , & devpath );
819819 if (r < 0 )
820820 return r ;
821821
822- drivers = strstr (syspath , "/drivers/" );
822+ drivers = strstr (devpath , "/drivers/" );
823823 if (!drivers )
824824 return - EINVAL ;
825825
826- for (p = drivers - 1 ; p >= syspath ; p -- )
827- if (* p == '/' )
828- break ;
829-
830- if (p <= syspath )
831- /* syspath does not start with /sys/ ?? */
832- return - EINVAL ;
833- p ++ ;
834- if (p >= drivers )
835- /* refuse duplicated slashes */
826+ r = path_find_last_component (devpath , false, & drivers , & p );
827+ if (r < 0 )
828+ return r ;
829+ if (r == 0 )
836830 return - EINVAL ;
837831
838- subsystem = strndup (p , drivers - p );
832+ subsystem = strndup (p , r );
839833 if (!subsystem )
840834 return - ENOMEM ;
841835
You can’t perform that action at this time.
0 commit comments