diff mbox series

[for-next,03/23] tracing: devlink: Use static array for string in devlink_trap_report even

Message ID 20220714164328.461963902@goodmis.org (mailing list archive)
State Not Applicable
Headers show
Series None | expand

Commit Message

Steven Rostedt July 14, 2022, 4:42 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

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).

Since IFNAMSIZ is just 16 bytes, just make it a static array and this will
remove the meta data from the event that records the size.

Link: https://lkml.kernel.org/r/20220712185820.002d9fb5@gandalf.local.home

Cc: Leon Romanovsky <leon@kernel.org>
Cc: Jiri Pirko <jiri@nvidia.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org
Acked-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 include/trace/events/devlink.h | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Ido Schimmel July 14, 2022, 6:40 p.m. UTC | #1
On Thu, Jul 14, 2022 at 12:42:59PM -0400, Steven Rostedt wrote:
> From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
> 
> 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).
> 
> Since IFNAMSIZ is just 16 bytes, just make it a static array and this will
> remove the meta data from the event that records the size.
> 
> Link: https://lkml.kernel.org/r/20220712185820.002d9fb5@gandalf.local.home
> 
> Cc: Leon Romanovsky <leon@kernel.org>
> Cc: Jiri Pirko <jiri@nvidia.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: netdev@vger.kernel.org
> Acked-by: Jakub Kicinski <kuba@kernel.org>
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

On the off chance that my tags weren't omitted on purpose:

Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Tested-by: Ido Schimmel <idosch@nvidia.com>

s/even/event/ in subject
Steven Rostedt July 14, 2022, 7:05 p.m. UTC | #2
On Thu, 14 Jul 2022 21:40:40 +0300
Ido Schimmel <idosch@idosch.org> wrote:

> On the off chance that my tags weren't omitted on purpose:

Ah, I probably pulled it in from my patchwork before you sent the tags. I
usually let my internal patchwork add them for me. So, it was not on
purpose.

It's also a reason I post to the mailing list before I push to linux-next.
In case I missed anything.

> 
> Reviewed-by: Ido Schimmel <idosch@nvidia.com>
> Tested-by: Ido Schimmel <idosch@nvidia.com>

Will add. Thanks!

> 
> s/even/event/ in subject

I'll fix that too.

-- Steve
diff mbox series

Patch

diff --git a/include/trace/events/devlink.h b/include/trace/events/devlink.h
index 2814f188d98c..24969184c534 100644
--- a/include/trace/events/devlink.h
+++ b/include/trace/events/devlink.h
@@ -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)
+		__array(char, input_dev_name, IFNAMSIZ)
 	),
 
 	TP_fast_assign(
@@ -197,15 +197,14 @@  TRACE_EVENT(devlink_trap_report,
 		__assign_str(driver_name, devlink_to_dev(devlink)->driver->name);
 		__assign_str(trap_name, metadata->trap_name);
 		__assign_str(trap_group_name, metadata->trap_group_name);
-		__assign_str(input_dev_name,
-			     (input_dev ? input_dev->name : "NULL"));
+		strscpy(__entry->input_dev_name, input_dev ? input_dev->name : "NULL", IFNAMSIZ);
 	),
 
 	TP_printk("bus_name=%s dev_name=%s driver_name=%s trap_name=%s "
 		  "trap_group_name=%s input_dev_name=%s", __get_str(bus_name),
 		  __get_str(dev_name), __get_str(driver_name),
 		  __get_str(trap_name), __get_str(trap_group_name),
-		  __get_str(input_dev_name))
+		  __entry->input_dev_name)
 );
 
 #endif /* _TRACE_DEVLINK_H */