@@ -444,9 +444,13 @@ static int nvme_subsystem_scan_ctrls(struct nvme_subsystem *s)
444444 return 0 ;
445445}
446446
447- static int nvme_init_subsystem (nvme_subsystem_t s , const char * name ,
448- const char * path )
447+ static int nvme_init_subsystem (nvme_subsystem_t s , const char * name )
449448{
449+ char * path ;
450+
451+ if (asprintf (& path , "%s/%s" , nvme_subsys_sysfs_dir , name ) < 0 )
452+ return -1 ;
453+
450454 s -> model = nvme_get_attr (path , "model" );
451455 if (!s -> model )
452456 s -> model = strdup ("undefined" );
@@ -509,7 +513,7 @@ static int nvme_scan_subsystem(struct nvme_root *r, char *name,
509513 goto free_path ;
510514 }
511515 if (!s -> name ) {
512- ret = nvme_init_subsystem (s , name , path );
516+ ret = nvme_init_subsystem (s , name );
513517 if (ret < 0 )
514518 goto free_path ;
515519 }
@@ -1177,17 +1181,10 @@ int nvme_init_ctrl(nvme_host_t h, nvme_ctrl_t c, int instance)
11771181 goto out_free_subsys ;
11781182 }
11791183 if (!s -> name ) {
1180- ret = asprintf (& path , "%s/%s" , nvme_subsys_sysfs_dir ,
1181- subsys_name );
1182- if (ret > 0 )
1183- ret = nvme_init_subsystem (s , subsys_name , path );
1184- else
1185- path = NULL ;
1184+ ret = nvme_init_subsystem (s , subsys_name );
11861185 if (ret < 0 ) {
1187- nvme_msg (LOG_ERR , "Failed to init subsystem %s/%s\n" ,
1188- nvme_subsys_sysfs_dir , subsys_name );
1189- if (path )
1190- free (path );
1186+ nvme_msg (LOG_ERR , "Failed to init subsystem %s\n" ,
1187+ subsys_name );
11911188 goto out_free_subsys ;
11921189 }
11931190 }
0 commit comments