diff mbox series

USB: gadget: udc: tracing: Do not open code __string() with __dynamic_array()

Message ID 20220702200127.399d2358@gandalf.local.home (mailing list archive)
State Superseded
Headers show
Series USB: gadget: udc: tracing: Do not open code __string() with __dynamic_array() | expand

Commit Message

Steven Rostedt July 3, 2022, 12:01 a.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

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>
---
 drivers/usb/gadget/udc/trace.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

kernel test robot July 3, 2022, 1:42 a.m. UTC | #1
Hi Steven,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on usb/usb-testing]
[also build test ERROR on linus/master v5.19-rc4 next-20220701]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Steven-Rostedt/USB-gadget-udc-tracing-Do-not-open-code-__string-with-__dynamic_array/20220703-080329
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
config: riscv-buildonly-randconfig-r001-20220703 (https://download.01.org/0day-ci/archive/20220703/202207030931.QMgcEvNT-lkp@intel.com/config)
compiler: riscv64-linux-gcc (GCC) 11.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/63b33d8f7a24820f05bd2b8330b19c3d78e0c36f
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Steven-Rostedt/USB-gadget-udc-tracing-Do-not-open-code-__string-with-__dynamic_array/20220703-080329
        git checkout 63b33d8f7a24820f05bd2b8330b19c3d78e0c36f
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash drivers/usb/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   In file included from include/trace/define_trace.h:102,
                    from drivers/usb/gadget/udc/trace.h:289,
                    from drivers/usb/gadget/udc/trace.c:10:
>> drivers/usb/gadget/udc/./trace.h:217:41: error: expected expression before ';' token
     217 |                 __string(name, ep->name);
         |                                         ^
   include/trace/trace_events.h:244:9: note: in definition of macro 'DECLARE_EVENT_CLASS'
     244 |         tstruct                                                         \
         |         ^~~~~~~
   drivers/usb/gadget/udc/./trace.h:216:9: note: in expansion of macro 'TP_STRUCT__entry'
     216 |         TP_STRUCT__entry(
         |         ^~~~~~~~~~~~~~~~


vim +217 drivers/usb/gadget/udc/./trace.h

   212	
   213	DECLARE_EVENT_CLASS(udc_log_req,
   214		TP_PROTO(struct usb_ep *ep, struct usb_request *req, int ret),
   215		TP_ARGS(ep, req, ret),
   216		TP_STRUCT__entry(
 > 217			__string(name, ep->name);
   218			__field(unsigned, length)
   219			__field(unsigned, actual)
   220			__field(unsigned, num_sgs)
   221			__field(unsigned, num_mapped_sgs)
   222			__field(unsigned, stream_id)
   223			__field(unsigned, no_interrupt)
   224			__field(unsigned, zero)
   225			__field(unsigned, short_not_ok)
   226			__field(int, status)
   227			__field(int, ret)
   228			__field(struct usb_request *, req)
   229		),
   230		TP_fast_assign(
   231			__assign_str(name, ep->name);
   232			__entry->length = req->length;
   233			__entry->actual = req->actual;
   234			__entry->num_sgs = req->num_sgs;
   235			__entry->num_mapped_sgs = req->num_mapped_sgs;
   236			__entry->stream_id = req->stream_id;
   237			__entry->no_interrupt = req->no_interrupt;
   238			__entry->zero = req->zero;
   239			__entry->short_not_ok = req->short_not_ok;
   240			__entry->status = req->status;
   241			__entry->ret = ret;
   242			__entry->req = req;
   243		),
   244		TP_printk("%s: req %p length %d/%d sgs %d/%d stream %d %s%s%s status %d --> %d",
   245			__get_str(name),__entry->req,  __entry->actual, __entry->length,
   246			__entry->num_mapped_sgs, __entry->num_sgs, __entry->stream_id,
   247			__entry->zero ? "Z" : "z",
   248			__entry->short_not_ok ? "S" : "s",
   249			__entry->no_interrupt ? "i" : "I",
   250			__entry->status, __entry->ret
   251		)
   252	);
   253
diff mbox series

Patch

diff --git a/drivers/usb/gadget/udc/trace.h b/drivers/usb/gadget/udc/trace.h
index 98584f6b6c66..db6510454b28 100644
--- a/drivers/usb/gadget/udc/trace.h
+++ b/drivers/usb/gadget/udc/trace.h
@@ -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)
@@ -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;
@@ -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)
@@ -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;