@@ -998,36 +998,56 @@ static int names_usb(sd_device *dev, const char *prefix, NetNames *names, bool t
998
998
return 0 ;
999
999
}
1000
1000
1001
- static int names_bcma (sd_device * dev , NetNames * names ) {
1002
- sd_device * bcmadev ;
1003
- unsigned core ;
1001
+ static int get_bcma_specifier (sd_device * dev , char * * ret ) {
1004
1002
const char * sysname ;
1003
+ char * buf = NULL ;
1004
+ unsigned core ;
1005
1005
int r ;
1006
1006
1007
1007
assert (dev );
1008
- assert (names );
1009
-
1010
- r = sd_device_get_parent_with_subsystem_devtype (dev , "bcma" , NULL , & bcmadev );
1011
- if (r < 0 )
1012
- return log_device_debug_errno (dev , r , "sd_device_get_parent_with_subsystem_devtype() failed: %m" );
1008
+ assert (ret );
1013
1009
1014
- r = sd_device_get_sysname (bcmadev , & sysname );
1010
+ r = sd_device_get_sysname (dev , & sysname );
1015
1011
if (r < 0 )
1016
- return log_device_debug_errno (dev , r , "sd_device_get_sysname() failed : %m" );
1012
+ return log_device_debug_errno (dev , r , "Failed to get sysname : %m" );
1017
1013
1018
1014
/* bus num:core num */
1019
1015
r = sscanf (sysname , "bcma%*u:%u" , & core );
1020
- log_device_debug (dev , "Parsing bcma device information from sysname \"%s\": %s" ,
1021
- sysname , r == 1 ? "success" : "failure" );
1022
1016
if (r != 1 )
1023
- return - EINVAL ;
1017
+ return log_device_debug_errno (dev , SYNTHETIC_ERRNO (EINVAL ),
1018
+ "Failed to parse bcma device information." );
1019
+
1024
1020
/* suppress the common core == 0 */
1025
- if (core > 0 )
1026
- xsprintf ( names -> bcma_core , "b%u" , core );
1021
+ if (core > 0 && asprintf ( & buf , "b%u" , core ) < 0 )
1022
+ return log_oom_debug ( );
1027
1023
1028
- names -> type = NET_BCMA ;
1029
1024
log_device_debug (dev , "BCMA core identifier: core=%u %s \"%s\"" ,
1030
- core , special_glyph (SPECIAL_GLYPH_ARROW_RIGHT ), names -> bcma_core );
1025
+ core , special_glyph (SPECIAL_GLYPH_ARROW_RIGHT ), strna (buf ));
1026
+
1027
+ * ret = buf ;
1028
+ return 0 ;
1029
+ }
1030
+
1031
+ static int names_bcma (sd_device * dev , NetNames * names ) {
1032
+ _cleanup_free_ char * suffix = NULL ;
1033
+ sd_device * bcmadev ;
1034
+ int r ;
1035
+
1036
+ assert (dev );
1037
+ assert (names );
1038
+
1039
+ r = sd_device_get_parent_with_subsystem_devtype (dev , "bcma" , NULL , & bcmadev );
1040
+ if (r < 0 )
1041
+ return log_device_debug_errno (dev , r , "Could not get bcma parent device: %m" );
1042
+
1043
+ r = get_bcma_specifier (bcmadev , & suffix );
1044
+ if (r < 0 )
1045
+ return r ;
1046
+
1047
+ size_t l = strscpy (names -> bcma_core , sizeof (names -> bcma_core ), strempty (suffix ));
1048
+ if (l != 0 )
1049
+ names -> type = NET_BCMA ;
1050
+
1031
1051
return 0 ;
1032
1052
}
1033
1053
0 commit comments