[v2,2/9] telemetry: make array initialization more robust

Message ID 20230112105903.46341-3-bruce.richardson@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series Standardize telemetry int types |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Bruce Richardson Jan. 12, 2023, 10:58 a.m. UTC
  Rather than relying on a specific ordering of elements in the array
matching that of elements in the enum definition, we can explicitly mark
each array entry using the equivalent enum value as an index.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 lib/telemetry/telemetry_data.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
  

Patch

diff --git a/lib/telemetry/telemetry_data.c b/lib/telemetry/telemetry_data.c
index 76fae720e3..3f5ef3979b 100644
--- a/lib/telemetry/telemetry_data.c
+++ b/lib/telemetry/telemetry_data.c
@@ -16,10 +16,10 @@  int
 rte_tel_data_start_array(struct rte_tel_data *d, enum rte_tel_value_type type)
 {
 	enum tel_container_types array_types[] = {
-			TEL_ARRAY_STRING, /* RTE_TEL_STRING_VAL = 0 */
-			TEL_ARRAY_INT,    /* RTE_TEL_INT_VAL = 1 */
-			TEL_ARRAY_U64,    /* RTE_TEL_U64_VAL = 2 */
-			TEL_ARRAY_CONTAINER, /* RTE_TEL_CONTAINER = 3 */
+			[RTE_TEL_STRING_VAL] = TEL_ARRAY_STRING,
+			[RTE_TEL_INT_VAL] = TEL_ARRAY_INT,
+			[RTE_TEL_U64_VAL] = TEL_ARRAY_U64,
+			[RTE_TEL_CONTAINER] = TEL_ARRAY_CONTAINER,
 	};
 	d->type = array_types[type];
 	d->data_len = 0;