Skip to content

Commit

Permalink
USB: gadget: udc: tracing: Do not open code __string() with __dynamic…
Browse files Browse the repository at this point in the history
…_array()

The event classes udc_log_ep and udc_log_req both declare:

    __dynamic_array(char, name, UDC_TRACE_STR_MAX)

Which will reserve UDC_TRACE_STR_MAX bytes on the ring buffer for the
event to write in name. It then uses snprintf() to write into that space.

Assuming that the string being copied is nul terminated, it is better to
just use the __string() helper. That way only the size of the string is
saved into the ring buffer and not the max size (yes, the entire
UDC_TRACE_STR_MAX is used in the trace event, and anything not used is
just junk in the ring buffer). Worse, there's also meta data saved into
the event that denotes where the string is stored in the event and also
saves its size, which is always going to be UDC_TRACE_STR_MAX.

Convert both to use the __string() and __assign_str() helpers that are for
this kind of use case.

Cc: Felipe Balbi <balbi@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Link: https://lore.kernel.org/r/20220703091449.317f94b1@rorschach.local.home
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Steven Rostedt (Google) authored and Greg Kroah-Hartman committed Jul 8, 2022
1 parent 90557fa commit 14a6043
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions drivers/usb/gadget/udc/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ DECLARE_EVENT_CLASS(udc_log_ep,
TP_PROTO(struct usb_ep *ep, int ret),
TP_ARGS(ep, ret),
TP_STRUCT__entry(
__dynamic_array(char, name, UDC_TRACE_STR_MAX)
__string(name, ep->name)
__field(unsigned, maxpacket)
__field(unsigned, maxpacket_limit)
__field(unsigned, max_streams)
Expand All @@ -152,7 +152,7 @@ DECLARE_EVENT_CLASS(udc_log_ep,
__field(int, ret)
),
TP_fast_assign(
snprintf(__get_str(name), UDC_TRACE_STR_MAX, "%s", ep->name);
__assign_str(name, ep->name);
__entry->maxpacket = ep->maxpacket;
__entry->maxpacket_limit = ep->maxpacket_limit;
__entry->max_streams = ep->max_streams;
Expand Down Expand Up @@ -214,7 +214,7 @@ DECLARE_EVENT_CLASS(udc_log_req,
TP_PROTO(struct usb_ep *ep, struct usb_request *req, int ret),
TP_ARGS(ep, req, ret),
TP_STRUCT__entry(
__dynamic_array(char, name, UDC_TRACE_STR_MAX)
__string(name, ep->name)
__field(unsigned, length)
__field(unsigned, actual)
__field(unsigned, num_sgs)
Expand All @@ -228,7 +228,7 @@ DECLARE_EVENT_CLASS(udc_log_req,
__field(struct usb_request *, req)
),
TP_fast_assign(
snprintf(__get_str(name), UDC_TRACE_STR_MAX, "%s", ep->name);
__assign_str(name, ep->name);
__entry->length = req->length;
__entry->actual = req->actual;
__entry->num_sgs = req->num_sgs;
Expand Down

0 comments on commit 14a6043

Please sign in to comment.