NFC: st21nfca: Fix potential skb leaks in NFC-DEP code
authorChristophe Ricard <christophe.ricard@gmail.com>
Sat, 13 Sep 2014 08:28:44 +0000 (10:28 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Wed, 24 Sep 2014 00:02:23 +0000 (02:02 +0200)
After a unsuccessful call to nfc_hci_send_event the skb was not
freed and might lead to memory leak.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
drivers/nfc/st21nfca/st21nfca_dep.c

index 03dacc6550bc17af52402c2dda9850f4829456af..bf3132ba743c9c4de82ef292cf801c6368cb5d2c 100644 (file)
@@ -185,8 +185,10 @@ static int st21nfca_tm_send_atr_res(struct nfc_hci_dev *hdev,
 
        info->dep_info.curr_nfc_dep_pni = 0;
 
-       return nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE,
+       r = nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE,
                                ST21NFCA_EVT_SEND_DATA, skb->data, skb->len);
+       kfree_skb(skb);
+       return r;
 }
 
 static int st21nfca_tm_recv_atr_req(struct nfc_hci_dev *hdev,
@@ -254,6 +256,8 @@ static int st21nfca_tm_send_psl_res(struct nfc_hci_dev *hdev,
 
        r = nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE,
                                ST21NFCA_EVT_SEND_DATA, skb->data, skb->len);
+       if (r < 0)
+               goto error;
 
        /*
         * ST21NFCA only support P2P passive.
@@ -269,8 +273,11 @@ static int st21nfca_tm_send_psl_res(struct nfc_hci_dev *hdev,
        }
 
        /* Send an event to change bitrate change event to card f */
-       return nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE,
+       r = nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE,
                        ST21NFCA_EVT_CARD_F_BITRATE, bitrate, 2);
+error:
+       kfree_skb(skb);
+       return r;
 }
 
 static int st21nfca_tm_recv_psl_req(struct nfc_hci_dev *hdev,