Remove extra strlen call

While the ternary is nice to read, strlen in general is an expensive
call, so call it once and check if the value is greater than our maximum
allowable string length and adjust accordingly

Signed-off-by: Kent Russell <kent.russell@amd.com>
Change-Id: Id744f2ba0eb81bb2b3c52eb69f38a615398a655d


[ROCm/ROCR-Runtime commit: 025036a662]
这个提交包含在:
Kent Russell 于 2020-10-30 06:44:48 -04:00 提交
1 父节点 acdda4811b
当前提交 85b0b04903
1 个文件已更改
+3 -2
+3 -2
查看文件
@@ -881,8 +881,9 @@ static HSAKMT_STATUS topology_parse_cpuinfo(struct proc_cpuinfo *cpuinfo,
if (!strncmp("model name", read_buf, sizeof("model name") - 1)) {
p = strchr(read_buf, ':');
p += 2; /* remove ": " */
p_len = (strlen(p) > HSA_PUBLIC_NAME_SIZE ?
HSA_PUBLIC_NAME_SIZE : strlen(p));
p_len = strlen(p);
if (p_len > HSA_PUBLIC_NAME_SIZE)
p_len = HSA_PUBLIC_NAME_SIZE;
memcpy(cpuinfo[proc].model_name, p, p_len);
cpuinfo[proc].model_name[p_len - 1] = '\0';
continue;