Skip to content

Commit 8155825

Browse files
committed
bugfixes after refactor
1 parent 9e33be2 commit 8155825

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

c2usb/c2usb.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ class result
7979
static inline constexpr std::errc BUSY = static_cast<std::errc>(EBUSY);
8080
static inline constexpr std::errc NO_CONNECTION = static_cast<std::errc>(ENOTCONN);
8181
static inline constexpr std::errc NO_MEMORY = static_cast<std::errc>(ENOMEM);
82-
bool operator==(std::errc err) const { return code_ == -static_cast<int>(err); }
83-
bool operator!=(std::errc err) const { return code_ != -static_cast<int>(err); }
82+
constexpr bool operator==(const result& other) const = default;
8483
};
8584

8685
/// @brief The interface base class is used by interface subclasses,

c2usb/port/zephyr/udc_mac.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

230233
net_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

Comments
 (0)