NFC: Added error handling in event_received hci ops
authorEric Lapuyade <eric.lapuyade@linux.intel.com>
Wed, 28 Nov 2012 14:48:44 +0000 (15:48 +0100)
committerSamuel Ortiz <sameo@linux.intel.com>
Wed, 9 Jan 2013 23:51:49 +0000 (00:51 +0100)
There is no use to return an error if the caller doesn't get it.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
drivers/nfc/pn544/pn544.c
include/net/nfc/hci.h
net/nfc/hci/core.c

index cc666de3b8e5a56b58ac984ff1f5ab890048c2e9..4af70f9c01aac1aeaa01bd6375c6b0023370ad60 100644 (file)
@@ -714,8 +714,8 @@ static int pn544_hci_check_presence(struct nfc_hci_dev *hdev,
        return 0;
 }
 
-static void pn544_hci_event_received(struct nfc_hci_dev *hdev, u8 gate,
-                                       u8 event, struct sk_buff *skb)
+static int pn544_hci_event_received(struct nfc_hci_dev *hdev, u8 gate, u8 event,
+                                   struct sk_buff *skb)
 {
        struct sk_buff *rgb_skb = NULL;
        int r = 0;
@@ -724,25 +724,23 @@ static void pn544_hci_event_received(struct nfc_hci_dev *hdev, u8 gate,
        switch (event) {
        case PN544_HCI_EVT_ACTIVATED:
                if (gate == PN544_RF_READER_NFCIP1_INITIATOR_GATE)
-                       nfc_hci_target_discovered(hdev, gate);
+                       r = nfc_hci_target_discovered(hdev, gate);
                else if (gate == PN544_RF_READER_NFCIP1_TARGET_GATE) {
                        r = nfc_hci_get_param(hdev, gate, PN544_DEP_ATR_REQ,
-                                               &rgb_skb);
-
+                                             &rgb_skb);
                        if (r < 0)
                                goto exit;
 
-                       nfc_tm_activated(hdev->ndev, NFC_PROTO_NFC_DEP_MASK,
-                                       NFC_COMM_PASSIVE, rgb_skb->data,
-                                       rgb_skb->len);
+                       r = nfc_tm_activated(hdev->ndev, NFC_PROTO_NFC_DEP_MASK,
+                                            NFC_COMM_PASSIVE, rgb_skb->data,
+                                            rgb_skb->len);
 
                        kfree_skb(rgb_skb);
                }
-
                break;
        case PN544_HCI_EVT_DEACTIVATED:
-               nfc_hci_send_event(hdev, gate,
-                       NFC_HCI_EVT_END_OPERATION, NULL, 0);
+               r = nfc_hci_send_event(hdev, gate, NFC_HCI_EVT_END_OPERATION,
+                                      NULL, 0);
                break;
        case PN544_HCI_EVT_RCV_DATA:
                if (skb->len < 2) {
@@ -757,15 +755,16 @@ static void pn544_hci_event_received(struct nfc_hci_dev *hdev, u8 gate,
                }
 
                skb_pull(skb, 2);
-               nfc_tm_data_received(hdev->ndev, skb);
-
-               return;
+               return nfc_tm_data_received(hdev->ndev, skb);
        default:
+               pr_err("Discarded unknown event %x to gate %x\n", event, gate);
                break;
        }
 
 exit:
        kfree_skb(skb);
+
+       return r;
 }
 
 static struct nfc_hci_ops pn544_hci_ops = {
index e6224571e5e69ca1e7bce2a45621e1b1f8b8e035..834e36481afff556a363f18fb895eff36459c9e4 100644 (file)
@@ -57,8 +57,8 @@ struct nfc_hci_ops {
        int (*tm_send)(struct nfc_hci_dev *hdev, struct sk_buff *skb);
        int (*check_presence)(struct nfc_hci_dev *hdev,
                              struct nfc_target *target);
-       void (*event_received)(struct nfc_hci_dev *hdev, u8 gate, u8 event,
-                               struct sk_buff *skb);
+       int (*event_received)(struct nfc_hci_dev *hdev, u8 gate, u8 event,
+                             struct sk_buff *skb);
 };
 
 /* Pipes */
index b4b84268653d6039dd6a8fc5d180d65c6bd584e6..f30f6fe815b4b56a009b1021af28a16ce5810f80 100644 (file)
@@ -323,16 +323,18 @@ void nfc_hci_event_received(struct nfc_hci_dev *hdev, u8 pipe, u8 event,
                break;
        default:
                if (hdev->ops->event_received) {
-                       hdev->ops->event_received(hdev, gate, event, skb);
-                       return;
+                       r = hdev->ops->event_received(hdev, gate, event, skb);
+                       goto exit_noskb;
+               } else {
+                       r = -EINVAL;
                }
-
                break;
        }
 
 exit:
        kfree_skb(skb);
 
+exit_noskb:
        if (r) {
                /* TODO: There was an error dispatching the event,
                 * how to propagate up to nfc core?