From: Luke Yeager Date: Mon, 27 Jul 2020 16:15:56 +0000 (-0700) Subject: infiniband: replace hard-coded constant with variable X-Git-Tag: collectd-5.12.0~23^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b5c86c03ebdbf70d92957e6f54a8bbe2a33ad04e;p=thirdparty%2Fcollectd.git infiniband: replace hard-coded constant with variable --- diff --git a/src/infiniband.c b/src/infiniband.c index 5467a6251..c70c824d6 100644 --- a/src/infiniband.c +++ b/src/infiniband.c @@ -55,6 +55,8 @@ static int ib_glob_ports(glob_t *g) { return glob("/sys/class/infiniband/*/ports/*/state", GLOB_NOSORT, NULL, g); } +static const int device_tok_idx = 3, port_tok_idx = 5; + static int ib_parse_glob_port(char *path, char **device, char **port) { char *tok, *saveptr = NULL; int j = 0; @@ -62,9 +64,9 @@ static int ib_parse_glob_port(char *path, char **device, char **port) { *port = NULL; tok = strtok_r(path, "/", &saveptr); while (tok != NULL) { - if (j == 3) + if (j == device_tok_idx) *device = tok; - else if (j == 5) { + else if (j == port_tok_idx) { *port = tok; break; }