core: Free packet in mctp_bus_rx

Change mctp_bus_rx to take ownership of a received packet, freeing it
after use.

This prevents potential leaks in binding implementations.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Change-Id: I76c427df7ffa5172e77eccad682325c1376c424f
diff --git a/core.c b/core.c
index baf60a8..2a9784e 100644
--- a/core.c
+++ b/core.c
@@ -262,7 +262,7 @@
 
 	if (hdr->dest != bus->eid)
 		/* @todo: non-local packet routing */
-		return;
+		goto out;
 
 	flags = hdr->flags_seq_tag & (MCTP_HDR_FLAG_SOM | MCTP_HDR_FLAG_EOM);
 	tag = (hdr->flags_seq_tag >> MCTP_HDR_TAG_SHIFT) & MCTP_HDR_TAG_MASK;
@@ -300,7 +300,7 @@
 	case MCTP_HDR_FLAG_EOM:
 		ctx = mctp_msg_ctx_lookup(mctp, hdr->src, tag);
 		if (!ctx)
-			return;
+			goto out;
 
 		exp_seq = (ctx->last_seq + 1) % 4;
 
@@ -309,7 +309,7 @@
 				"Sequence number %d does not match expected %d",
 				seq, exp_seq);
 			mctp_msg_ctx_drop(ctx);
-			return;
+			goto out;
 		}
 
 		rc = mctp_msg_ctx_add_pkt(ctx, pkt);
@@ -325,7 +325,7 @@
 		/* Neither SOM nor EOM */
 		ctx = mctp_msg_ctx_lookup(mctp, hdr->src, tag);
 		if (!ctx)
-			return;
+			goto out;
 
 		exp_seq = (ctx->last_seq + 1) % 4;
 		if (exp_seq != seq) {
@@ -333,18 +333,20 @@
 				"Sequence number %d does not match expected %d",
 				seq, exp_seq);
 			mctp_msg_ctx_drop(ctx);
-			return;
+			goto out;
 		}
 
 		rc = mctp_msg_ctx_add_pkt(ctx, pkt);
 		if (rc) {
 			mctp_msg_ctx_drop(ctx);
-			return;
+			goto out;
 		}
 		ctx->last_seq = seq;
 
 		break;
 	}
+out:
+	mctp_pktbuf_free(pkt);
 }
 
 static int mctp_packet_tx(struct mctp_bus *bus,