Skip to content

Commit

Permalink
Merge amd-staging into amd-master 20230331
Browse files Browse the repository at this point in the history
Signed-off-by: Hao Zhou <[email protected]>
Change-Id: I4d59f2bfb9a4f3cf64662d76437ddb808f6b510b
  • Loading branch information
Hao Zhou authored and Hao Zhou committed Mar 31, 2023
2 parents 230b5bc + 58c83eb commit f454d46
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
12 changes: 10 additions & 2 deletions src/rocm_smi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1811,6 +1811,8 @@ static rsmi_status_t get_dev_name_from_id(uint32_t dv_ind, char *name,
uint16_t subsys_vend_id;
uint16_t subsys_id;
bool found_device_vendor = false;
// to match subsystem, it must match the device id at previous line
bool found_device_id_for_subsys = false;
std::string val_str;

assert(name != nullptr);
Expand Down Expand Up @@ -1857,8 +1859,8 @@ static rsmi_status_t get_dev_name_from_id(uint32_t dv_ind, char *name,
if (ln[0] == '\t') {
if (found_device_vendor) {
if (ln[1] == '\t') {
// This is a subsystem line
if (typ == NAME_STR_SUBSYS) {
// The subsystem line, ignore a line if the device id not match
if (typ == NAME_STR_SUBSYS && found_device_id_for_subsys) {
val_str = get_id_name_str_from_line(subsys_vend_id, ln, &ln_str);

if (val_str.size() > 0) {
Expand All @@ -1880,6 +1882,12 @@ static rsmi_status_t get_dev_name_from_id(uint32_t dv_ind, char *name,
if (val_str.size() > 0) {
break;
}
} else if (typ == NAME_STR_SUBSYS) {
// match the device id line
val_str = get_id_name_str_from_line(device_id, ln, &ln_str);
if (val_str.size() > 0) {
found_device_id_for_subsys = true;
}
}
}
} else { // ln[0] != '\t'; Vendor line
Expand Down
11 changes: 6 additions & 5 deletions src/rocm_smi_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,17 @@ static bool bdfid_from_path(const std::string in_name, uint64_t *bdfid) {
// 1 = not a good bdfid found
static uint32_t ConstructBDFID(std::string path, uint64_t *bdfid) {
assert(bdfid != nullptr);
char tpath[256] = {'\0'};
const unsigned int MAX_BDF_LENGTH = 512;
char tpath[MAX_BDF_LENGTH] = {'\0'};
ssize_t ret;
memset(tpath,0,256);
memset(tpath,0,MAX_BDF_LENGTH);

ret = readlink(path.c_str(), tpath, 256);
ret = readlink(path.c_str(), tpath, MAX_BDF_LENGTH);

assert(ret > 0);
assert(ret < 256);
assert(ret < MAX_BDF_LENGTH);

if (ret <= 0 || ret >= 256) {
if (ret <= 0 || ret >= MAX_BDF_LENGTH) {
return 1;
}

Expand Down

0 comments on commit f454d46

Please sign in to comment.