Skip to contentSkip to conversation

tracing: devlink: Use dynamic size for string in devlink_trap_report event

PATCH New Steven Rostedt 1 participant 1 message Jul 3, 2022 Tracing

lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

PATCH 1/1 tracing: devlink: Use dynamic size for string in devlink_trap_report event

From: "Steven Rostedt (Google)" <[email protected]>

The trace event devlink_trap_report uses the __dynamic_array() macro to determine the size of the input_dev_name field. This is because it needs to test the dev field for NULL, and will use "NULL" if it is. But it also has the size of the dynamic array as a fixed IFNAMSIZ bytes. This defeats the purpose of the dynamic array, as this will reserve that amount of bytes on the ring buffer, and to make matters worse, it will even save that size in the event as the event expects it to be dynamic (for which it is not).

Instead, add the logic to calculate the size needed to save the input_dev_name field and only allocate that on the ring buffer.

Cc Jakub Kicinski <[email protected]>
Cc Leon Romanovsky <[email protected]>
---
 include/trace/events/devlink.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/trace/events/devlink.h +1 -1
index 2814f188d98c..93c2783609de 100644
@@ -186,7 +186,7 @@ TRACE_EVENT(devlink_trap_report,
 		__string(driver_name, devlink_to_dev(devlink)->driver->name)
 		__string(trap_name, metadata->trap_name)
 		__string(trap_group_name, metadata->trap_group_name)
-		__dynamic_array(char, input_dev_name, IFNAMSIZ)
+		__dynamic_array(char, input_dev_name, input_dev ? strlen(input_dev->name) + 1 : sizeof("NULL"))
 	),
 
 	TP_fast_assign(
Signature · 1 line
2.35.1