From 025036a662c3e133f09de314ff000fcd842fa443 Mon Sep 17 00:00:00 2001 From: Kent Russell Date: Tue, 13 Oct 2020 11:00:48 -0400 Subject: [PATCH] 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 Change-Id: Id744f2ba0eb81bb2b3c52eb69f38a615398a655d --- src/topology.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/topology.c b/src/topology.c index 36ef98742d..da1d7479de 100644 --- a/src/topology.c +++ b/src/topology.c @@ -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;