Skip to content

Commit 0d6e404

Browse files
eric-ocasio-nxpjhedberg
authored andcommitted
pmci: mctp: Fix MCTP USB packet buffer deallocation pointer issue
Explicitly set rx_pkt pointer to NULL after free'ing it. Fixes #98688 Signed-off-by: Eric Ocasio <eric.ocasio@nxp.com>
1 parent 3bdf103 commit 0d6e404

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

subsys/pmci/mctp/mctp_usb.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ static void mctp_usb_reset_rx_state(struct mctp_binding_usb *usb)
9595
{
9696
if (usb->rx_pkt != NULL) {
9797
mctp_pktbuf_free(usb->rx_pkt);
98+
usb->rx_pkt = NULL;
9899
}
99100

100101
usb->rx_data_idx = 0;
@@ -201,8 +202,8 @@ static void mctp_usb_class_out_work(struct k_work *work)
201202
/* Process the MCTP data */
202203
struct mctp_binding_usb *usb = (struct mctp_binding_usb *)ctx->inst->mctp_binding;
203204

204-
LOG_DBG("size=%d", ctx->out_net_buf->len);
205-
LOG_HEXDUMP_DBG(buf, ctx->out_net_buf->len, "buf = ");
205+
LOG_DBG("size=%d", buf_size);
206+
LOG_HEXDUMP_DBG(ctx->out_buf, buf_size, "buf = ");
206207

207208
for (int i = 0; i < buf_size; i++) {
208209
switch (usb->rx_state) {
@@ -262,6 +263,8 @@ static void mctp_usb_class_out_work(struct k_work *work)
262263
if (usb->rx_data_idx == usb->rx_pkt->end) {
263264
LOG_DBG("Packet complete");
264265
mctp_bus_rx(&usb->binding, usb->rx_pkt);
266+
/* Explicitly set rx_pkt to NULL since it is not guaranteed */
267+
usb->rx_pkt = NULL;
265268
mctp_usb_reset_rx_state(usb);
266269
}
267270

@@ -354,7 +357,7 @@ static int mctp_usb_class_init(struct usbd_class_data *const c_data)
354357
ctx->class_data = c_data;
355358
ctx->state = 0;
356359

357-
/* Share USB class data with the binding so that the binding */
360+
/* Share USB class data with the MCTP USB binding */
358361
ctx->inst->mctp_binding->usb_class_data = c_data;
359362

360363
k_work_init(&ctx->out_work, mctp_usb_class_out_work);

0 commit comments

Comments
 (0)