]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
NFC: protect nci_data_exchange transactions
authorIlan Elias <ilane@ti.com>
Thu, 22 Sep 2011 08:36:19 +0000 (11:36 +0300)
committerJohn W. Linville <linville@tuxdriver.com>
Tue, 27 Sep 2011 18:34:05 +0000 (14:34 -0400)
Protect 'cb' and 'cb_context' arguments in nci_data_exchange.
In fact, this implements a queue with max length of 1 data
exchange transactions in parallel.

Signed-off-by: Ilan Elias <ilane@ti.com>
Acked-by: Lauro Ramos Venancio <lauro.venancio@openbossa.org>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
include/net/nfc/nci_core.h
net/nfc/nci/core.c
net/nfc/nci/data.c
net/nfc/nci/ntf.c

index 2563f3a95e6712fed32a3392abf1ee91833db6d1..b8b4bbd7e0fc2d6abfa70ae5d2be24b11471bb76 100644 (file)
@@ -40,6 +40,7 @@ enum {
        NCI_UP,
        NCI_DISCOVERY,
        NCI_POLL_ACTIVE,
+       NCI_DATA_EXCHANGE,
 };
 
 /* NCI timeouts */
index 9f17e8ec0ab9e9dc0660b572bb6e5c500bbc09cf..1e6b20f2bc99335be8b5d3cbae3d7314ab7ca7dd 100644 (file)
@@ -453,6 +453,7 @@ static int nci_data_exchange(struct nfc_dev *nfc_dev, __u32 target_idx,
                                                void *cb_context)
 {
        struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
+       int rc;
 
        nfc_dbg("entry, target_idx %d, len %d", target_idx, skb->len);
 
@@ -461,11 +462,18 @@ static int nci_data_exchange(struct nfc_dev *nfc_dev, __u32 target_idx,
                return -EINVAL;
        }
 
+       if (test_and_set_bit(NCI_DATA_EXCHANGE, &ndev->flags))
+               return -EBUSY;
+
        /* store cb and context to be used on receiving data */
        ndev->data_exchange_cb = cb;
        ndev->data_exchange_cb_context = cb_context;
 
-       return nci_send_data(ndev, ndev->conn_id, skb);
+       rc = nci_send_data(ndev, ndev->conn_id, skb);
+       if (rc)
+               clear_bit(NCI_DATA_EXCHANGE, &ndev->flags);
+
+       return rc;
 }
 
 static struct nfc_ops nci_nfc_ops = {
index 141790ada4aa9e7f0269dc96c0f327998416fd1d..e5ed90fc1a9cf1bf6024e22bb2989644a48ed837 100644 (file)
@@ -54,6 +54,8 @@ void nci_data_exchange_complete(struct nci_dev *ndev,
                /* no waiting callback, free skb */
                kfree_skb(skb);
        }
+
+       clear_bit(NCI_DATA_EXCHANGE, &ndev->flags);
 }
 
 /* ----------------- NCI TX Data ----------------- */
index 8dd75352ab6cd851f8485f223908fc41e44c9671..96633f5cda4f790d3bae4ecdfa4f3a6435c5797c 100644 (file)
@@ -215,7 +215,7 @@ static void nci_rf_deactivate_ntf_packet(struct nci_dev *ndev,
        }
 
        /* complete the data exchange transaction, if exists */
-       if (ndev->data_exchange_cb)
+       if (test_bit(NCI_DATA_EXCHANGE, &ndev->flags))
                nci_data_exchange_complete(ndev, NULL, -EIO);
 }