[PATCH v3 05/14] greybus: cpc: switch RX path to socket buffers

Damien Riégel posted 14 patches 1 day, 8 hours ago
[PATCH v3 05/14] greybus: cpc: switch RX path to socket buffers
Posted by Damien Riégel 1 day, 8 hours ago
For symmetry, also convert the RX path to use socket buffers instead of
u8* buffers. Before this commit CPC host device drivers were responsible
for allocating and freeing the buffers.

Now they are only responsible for allocating the SKBs and pass it to the
upper layer, the CPC "core" module will take of converting the SKBs into
a buffer that can be consumed by Greybus' core and releasing the SKBs.

Signed-off-by: Damien Riégel <damien.riegel@silabs.com>
---
 drivers/greybus/cpc/host.c | 13 ++++++++-----
 drivers/greybus/cpc/host.h |  2 +-
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/greybus/cpc/host.c b/drivers/greybus/cpc/host.c
index 10b0529dc4e..66c4d7fd0b8 100644
--- a/drivers/greybus/cpc/host.c
+++ b/drivers/greybus/cpc/host.c
@@ -209,20 +209,23 @@ void cpc_hd_message_sent(struct sk_buff *skb, int status)
 }
 EXPORT_SYMBOL_GPL(cpc_hd_message_sent);
 
-void cpc_hd_rcvd(struct cpc_host_device *cpc_hd, u8 *data, size_t length)
+void cpc_hd_rcvd(struct cpc_host_device *cpc_hd, struct sk_buff *skb)
 {
 	struct gb_operation_msg_hdr *gb_hdr;
 	u16 cport_id;
 
 	/* Prevent an out-of-bound access if called with non-sensical parameters. */
-	if (!data || length < sizeof(*gb_hdr))
-		return;
+	if (skb->len < sizeof(*gb_hdr))
+		goto free_skb;
 
 	/* Retrieve cport ID that was packed in Greybus header */
-	gb_hdr = (struct gb_operation_msg_hdr *)data;
+	gb_hdr = (struct gb_operation_msg_hdr *)skb->data;
 	cport_id = cpc_cport_unpack(gb_hdr);
 
-	greybus_data_rcvd(cpc_hd->gb_hd, cport_id, data, length);
+	greybus_data_rcvd(cpc_hd->gb_hd, cport_id, skb->data, skb->len);
+
+free_skb:
+	kfree_skb(skb);
 }
 EXPORT_SYMBOL_GPL(cpc_hd_rcvd);
 
diff --git a/drivers/greybus/cpc/host.h b/drivers/greybus/cpc/host.h
index 2e568bac44e..cc835f5298b 100644
--- a/drivers/greybus/cpc/host.h
+++ b/drivers/greybus/cpc/host.h
@@ -45,7 +45,7 @@ struct cpc_host_device *cpc_hd_create(struct cpc_hd_driver *driver, struct devic
 int cpc_hd_add(struct cpc_host_device *cpc_hd);
 void cpc_hd_put(struct cpc_host_device *cpc_hd);
 void cpc_hd_del(struct cpc_host_device *cpc_hd);
-void cpc_hd_rcvd(struct cpc_host_device *cpc_hd, u8 *data, size_t length);
+void cpc_hd_rcvd(struct cpc_host_device *cpc_hd, struct sk_buff *skb);
 void cpc_hd_message_sent(struct sk_buff *skb, int status);
 
 int cpc_hd_send_skb(struct cpc_host_device *cpc_hd, struct sk_buff *skb);
-- 
2.52.0