@@ -224,7 +224,10 @@ void udc_mac::ctrl_stall(net_buf* buf, int err)
224224 addr = endpoint::address::control_out ();
225225 }
226226 [[maybe_unused]] auto ret = ep_set_stall (addr);
227- net_buf_unref (buf);
227+ if (buf)
228+ {
229+ net_buf_unref (buf);
230+ }
228231}
229232
230233net_buf* udc_mac::ctrl_buffer_allocate (net_buf* buf)
@@ -259,6 +262,10 @@ net_buf* udc_mac::ctrl_buffer_allocate(net_buf* buf)
259262 net_buf_frag_add (buf, status);
260263 }
261264 }
265+ else if (status != nullptr )
266+ {
267+ net_buf_unref (status);
268+ }
262269 return buf;
263270}
264271
@@ -319,8 +326,11 @@ void udc_mac::process_ctrl_ep_event(net_buf* buf, const udc_buf_info& info)
319326 stall_flags_.clear (endpoint::address::control_in ());
320327
321328 std::memcpy (&request (), buf->data , sizeof (request ()));
329+ #if CONFIG_C2USB_UDC_MAC_LOG_LEVEL >= LOG_LEVEL_DBG
330+ // logged when DBG level is selected, but without the extra details of LOG_DBG()
322331 LOG_INF (" CTRL EP setup: %02x %02x %04x %u" , request ().bmRequestType , request ().bRequest ,
323332 (uint16_t )request ().wValue , (uint16_t )request ().wLength );
333+ #endif
324334
325335 // pop the buf chain for the next stage(s), freeing the setup buf
326336 buf = net_buf_frag_del (nullptr , buf);
@@ -335,6 +345,8 @@ void udc_mac::process_ctrl_ep_event(net_buf* buf, const udc_buf_info& info)
335345 buf = ctrl_buffer_allocate (buf);
336346 if (buf == nullptr )
337347 {
348+ // TODO: instead try to consume all events from the queue, and only process the last
349+ // CTRL EP event
338350 LOG_ERR (" ctrl_buf alloc fail, stall" );
339351 return ctrl_stall (buf);
340352 }
0 commit comments