drivers: udc: avoid NULL pointer dereferencing if endpoint is invalid

Immediately return NULL if endpoint configuration is not available.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This commit is contained in:
Johann Fischer 2022-12-29 01:27:18 +01:00 committed by Carles Cufí
commit c1860326d1

View file

@ -121,10 +121,11 @@ struct net_buf *udc_buf_peek(const struct device *dev, const uint8_t ep,
struct net_buf *buf = NULL;
ep_cfg = udc_get_ep_cfg(dev, ep);
if (ep_cfg != NULL) {
buf = k_fifo_peek_head(&ep_cfg->fifo);
if (ep_cfg == NULL) {
return NULL;
}
buf = k_fifo_peek_head(&ep_cfg->fifo);
if (buf == NULL && pending) {
ep_cfg->stat.pending = 1;
}