[v7,5/6] telemetry: fix json output buffer size

Message ID 5a95b25b81e7ee57edfdcea73b9266bc8dae8d77.1631120194.git.gmuthukrishn@marvell.com (mailing list archive)
State Superseded, archived
Delegated to: Jerin Jacob
Headers
Series cnxk: enable telemetry endpoints |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Gowrishankar Muthukrishnan Sept. 8, 2021, 5:03 p.m. UTC
  Fix json output buffer size for a single largest value.

Fixes: 52af6ccb2b39 ("telemetry: add utility functions for creating JSON")

Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
Change-Id: Ida314114b654b5085244a659eb08b22969339856
---
 lib/telemetry/telemetry_json.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
  

Patch

diff --git a/lib/telemetry/telemetry_json.h b/lib/telemetry/telemetry_json.h
index ad270b9b30..ba2fde34cb 100644
--- a/lib/telemetry/telemetry_json.h
+++ b/lib/telemetry/telemetry_json.h
@@ -9,6 +9,7 @@ 
 #include <stdarg.h>
 #include <stdio.h>
 #include <rte_common.h>
+#include <rte_telemetry.h>
 
 /**
  * @file
@@ -23,13 +24,15 @@ 
  * @internal
  * Copies a value into a buffer if the buffer has enough available space.
  * Nothing written to buffer if an overflow ocurs.
- * This function is not for use for values larger than 1k.
+ * Size of buffer is (single largest value - 6), where at least 6 chars
+ * would have been used for creating json dict i.e '{"x": ... }'.
+ * This function is not for use for values larger than this buffer size.
  */
 __rte_format_printf(3, 4)
 static inline int
 __json_snprintf(char *buf, const int len, const char *format, ...)
 {
-	char tmp[1024];
+	char tmp[RTE_TEL_MAX_SINGLE_STRING_LEN - 6];
 	va_list ap;
 	int ret;