]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
gpu_sysman: Improve metric variant handling code readability
authorEero Tamminen <eero.t.tamminen@intel.com>
Mon, 3 Oct 2022 09:36:40 +0000 (12:36 +0300)
committerMatthias Runge <mrunge@matthias-runge.de>
Tue, 8 Nov 2022 12:24:36 +0000 (13:24 +0100)
Based on review comments by Tuomas

Signed-off-by: Eero Tamminen <eero.t.tamminen@intel.com>
src/gpu_sysman.c

index 68666c53b50b0b99b8965b74fa47ee4d87c11e41..5f9cd1c77f5f101e232d575b36476bf6e5e7e1df 100644 (file)
@@ -120,10 +120,10 @@ typedef struct {
 } gpu_device_t;
 
 typedef enum {
-  OUTPUT_COUNTER = 1,
-  OUTPUT_RATE = 2,
-  OUTPUT_RATIO = 4,
-  OUTPUT_ALL = 7
+  OUTPUT_COUNTER = (1 << 0),
+  OUTPUT_RATE = (1 << 1),
+  OUTPUT_RATIO = (1 << 2),
+  OUTPUT_ALL = (OUTPUT_COUNTER | OUTPUT_RATE | OUTPUT_RATIO)
 } output_t;
 
 static const struct {
@@ -2026,15 +2026,17 @@ static int gpu_config_parse(const char *key, const char *value) {
     char *save, *flag, *flags = sstrdup(value);
     for (flag = strtok_r(flags, delim, &save); flag;
          flag = strtok_r(NULL, delim, &save)) {
-      unsigned i;
-      for (i = 0; i < STATIC_ARRAY_SIZE(metrics_output); i++) {
+      bool found = false;
+      for (unsigned i = 0; i < STATIC_ARRAY_SIZE(metrics_output); i++) {
         if (strcasecmp(flag, metrics_output[i].name) == 0) {
           config.output |= metrics_output[i].value;
+          found = true;
           break;
         }
       }
-      if (i >= STATIC_ARRAY_SIZE(metrics_output)) {
+      if (!found) {
         free(flags);
+        ERROR(PLUGIN_NAME ": Invalid '%s' config key value '%s'", key, value);
         return RET_INVALID_CONFIG;
       }
     }