NFC: nfcmrvl: update nci recv frame API
authorVincent Cuissard <cuissard@marvell.com>
Thu, 11 Jun 2015 09:25:44 +0000 (11:25 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Thu, 11 Jun 2015 21:24:31 +0000 (23:24 +0200)
Update internal nci recv frame API to use skbuff phy management
to generic part of the driver.

Signed-off-by: Vincent Cuissard <cuissard@marvell.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
drivers/nfc/nfcmrvl/main.c
drivers/nfc/nfcmrvl/nfcmrvl.h
drivers/nfc/nfcmrvl/usb.c

index 48d8b00744df542eaa9dcf100ce4d188164e5caa..e7f579b2d987b441a004f0b9cbd94b0b2b9d5f0d 100644 (file)
@@ -153,16 +153,8 @@ void nfcmrvl_nci_unregister_dev(struct nfcmrvl_private *priv)
 }
 EXPORT_SYMBOL_GPL(nfcmrvl_nci_unregister_dev);
 
-int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, void *data, int count)
+int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, struct sk_buff *skb)
 {
-       struct sk_buff *skb;
-
-       skb = nci_skb_alloc(priv->ndev, count, GFP_ATOMIC);
-       if (!skb)
-               return -ENOMEM;
-
-       memcpy(skb_put(skb, count), data, count);
-
        if (priv->hci_muxed) {
                if (skb->data[0] == NFCMRVL_HCI_EVENT_CODE &&
                    skb->data[1] == NFCMRVL_HCI_NFC_EVENT_CODE) {
@@ -175,9 +167,15 @@ int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, void *data, int count)
                }
        }
 
-       nci_recv_frame(priv->ndev, skb);
+       if (test_bit(NFCMRVL_NCI_RUNNING, &priv->flags))
+               nci_recv_frame(priv->ndev, skb);
+       else {
+               /* Drop this packet since nobody wants it */
+               kfree_skb(skb);
+               return 0;
+       }
 
-       return count;
+       return 0;
 }
 EXPORT_SYMBOL_GPL(nfcmrvl_nci_recv_frame);
 
index b04cddd57388af0919cabd4fd31e0b0d1721e94d..7a10dabaf1b280dc6dfd2aad6e49089658ea0266 100644 (file)
@@ -58,7 +58,7 @@ struct nfcmrvl_if_ops {
 };
 
 void nfcmrvl_nci_unregister_dev(struct nfcmrvl_private *priv);
-int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, void *data, int count);
+int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, struct sk_buff *skb);
 struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,
                                                 struct nfcmrvl_if_ops *ops,
                                                 struct device *dev,
index df534b90468bcfaa750ba720f87d80fed812025c..f81861af5b257cda6eb8fbf0e7777d7549df3cdc 100644 (file)
@@ -69,18 +69,27 @@ static int nfcmrvl_inc_tx(struct nfcmrvl_usb_drv_data *drv_data)
 static void nfcmrvl_bulk_complete(struct urb *urb)
 {
        struct nfcmrvl_usb_drv_data *drv_data = urb->context;
+       struct sk_buff *skb;
        int err;
 
-       dev_dbg(&drv_data->udev->dev, "urb %p status %d count %d",
+       dev_dbg(&drv_data->udev->dev, "urb %p status %d count %d\n",
                urb, urb->status, urb->actual_length);
 
        if (!test_bit(NFCMRVL_NCI_RUNNING, &drv_data->flags))
                return;
 
        if (!urb->status) {
-               if (nfcmrvl_nci_recv_frame(drv_data->priv, urb->transfer_buffer,
-                                          urb->actual_length) < 0)
-                       nfc_err(&drv_data->udev->dev, "corrupted Rx packet\n");
+               skb = nci_skb_alloc(drv_data->priv->ndev, urb->actual_length,
+                                   GFP_ATOMIC);
+               if (!skb) {
+                       nfc_err(&drv_data->udev->dev, "failed to alloc mem\n");
+               } else {
+                       memcpy(skb_put(skb, urb->actual_length),
+                              urb->transfer_buffer, urb->actual_length);
+                       if (nfcmrvl_nci_recv_frame(drv_data->priv, skb) < 0)
+                               nfc_err(&drv_data->udev->dev,
+                                       "corrupted Rx packet\n");
+               }
        }
 
        if (!test_bit(NFCMRVL_USB_BULK_RUNNING, &drv_data->flags))