]> www.infradead.org Git - users/willy/xarray.git/commitdiff
soc: qcom: Convert txns to XArray
authorMatthew Wilcox <willy@infradead.org>
Tue, 8 Jan 2019 20:31:13 +0000 (15:31 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 9 Aug 2019 01:38:14 +0000 (21:38 -0400)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
drivers/soc/qcom/qmi_interface.c
include/linux/soc/qcom/qmi.h

index f9e309f0acd32debbb44cb116386ed8bc9fc3093..929aee5fb5efd8b98f4e2d7ed9c7dea939c9a1fd 100644 (file)
@@ -8,7 +8,6 @@
 #include <linux/qrtr.h>
 #include <linux/net.h>
 #include <linux/completion.h>
-#include <linux/idr.h>
 #include <linux/string.h>
 #include <net/sock.h>
 #include <linux/workqueue.h>
@@ -317,15 +316,14 @@ int qmi_txn_init(struct qmi_handle *qmi, struct qmi_txn *txn,
        txn->ei = ei;
        txn->dest = c_struct;
 
-       mutex_lock(&qmi->txn_lock);
-       ret = idr_alloc_cyclic(&qmi->txns, txn, 0, U16_MAX, GFP_KERNEL);
-       if (ret < 0)
+       ret = xa_alloc_cyclic(&qmi->txns, &txn->id, txn, XA_LIMIT(0, U16_MAX),
+                       &qmi->txn_next, GFP_KERNEL);
+       if (ret < 0) {
                pr_err("failed to allocate transaction id\n");
+               return ret;
+       }
 
-       txn->id = ret;
-       mutex_unlock(&qmi->txn_lock);
-
-       return ret;
+       return txn->id;
 }
 EXPORT_SYMBOL(qmi_txn_init);
 
@@ -347,11 +345,9 @@ int qmi_txn_wait(struct qmi_txn *txn, unsigned long timeout)
 
        ret = wait_for_completion_timeout(&txn->completion, timeout);
 
-       mutex_lock(&qmi->txn_lock);
        mutex_lock(&txn->lock);
-       idr_remove(&qmi->txns, txn->id);
+       xa_erase(&qmi->txns, txn->id);
        mutex_unlock(&txn->lock);
-       mutex_unlock(&qmi->txn_lock);
 
        if (ret == 0)
                return -ETIMEDOUT;
@@ -368,11 +364,9 @@ void qmi_txn_cancel(struct qmi_txn *txn)
 {
        struct qmi_handle *qmi = txn->qmi;
 
-       mutex_lock(&qmi->txn_lock);
        mutex_lock(&txn->lock);
-       idr_remove(&qmi->txns, txn->id);
+       xa_erase(&qmi->txns, txn->id);
        mutex_unlock(&txn->lock);
-       mutex_unlock(&qmi->txn_lock);
 }
 EXPORT_SYMBOL(qmi_txn_cancel);
 
@@ -486,17 +480,13 @@ static void qmi_handle_message(struct qmi_handle *qmi,
 
        /* If this is a response, find the matching transaction handle */
        if (hdr->type == QMI_RESPONSE) {
-               mutex_lock(&qmi->txn_lock);
-               txn = idr_find(&qmi->txns, hdr->txn_id);
+               txn = xa_load(&qmi->txns, hdr->txn_id);
 
                /* Ignore unexpected responses */
-               if (!txn) {
-                       mutex_unlock(&qmi->txn_lock);
+               if (!txn)
                        return;
-               }
 
                mutex_lock(&txn->lock);
-               mutex_unlock(&qmi->txn_lock);
 
                if (txn->dest && txn->ei) {
                        ret = qmi_decode_message(buf, len, txn->ei, txn->dest);
@@ -621,10 +611,10 @@ int qmi_handle_init(struct qmi_handle *qmi, size_t recv_buf_size,
 {
        int ret;
 
-       mutex_init(&qmi->txn_lock);
        mutex_init(&qmi->sock_lock);
 
-       idr_init(&qmi->txns);
+       xa_init_flags(&qmi->txns, XA_FLAGS_ALLOC);
+       qmi->txn_next = 0;
 
        INIT_LIST_HEAD(&qmi->lookups);
        INIT_LIST_HEAD(&qmi->lookup_results);
@@ -694,8 +684,6 @@ void qmi_handle_release(struct qmi_handle *qmi)
 
        destroy_workqueue(qmi->wq);
 
-       idr_destroy(&qmi->txns);
-
        kfree(qmi->recv_buf);
 
        /* Free registered lookup requests */
index 5efa2b67fa55792d37ecfe67b14ea9b0fca663fd..efe83bdad8f1cfdba36a2fcb6d6a05a3c8e140af 100644 (file)
@@ -7,11 +7,11 @@
 #define __QMI_HELPERS_H__
 
 #include <linux/completion.h>
-#include <linux/idr.h>
 #include <linux/list.h>
 #include <linux/qrtr.h>
 #include <linux/types.h>
 #include <linux/workqueue.h>
+#include <linux/xarray.h>
 
 struct socket;
 
@@ -166,11 +166,11 @@ struct qmi_ops {
 struct qmi_txn {
        struct qmi_handle *qmi;
 
-       u16 id;
+       u32 id;
+       int result;
 
        struct mutex lock;
        struct completion completion;
-       int result;
 
        struct qmi_elem_info *ei;
        void *dest;
@@ -209,7 +209,7 @@ struct qmi_msg_handler {
  * @services:          list of registered services (by this client)
  * @ops:       reference to callbacks
  * @txns:      outstanding transactions
- * @txn_lock:  lock for modifications of @txns
+ * @txn_next:  next transaction number
  * @handlers:  list of handlers for incoming messages
  */
 struct qmi_handle {
@@ -230,8 +230,8 @@ struct qmi_handle {
 
        struct qmi_ops ops;
 
-       struct idr txns;
-       struct mutex txn_lock;
+       struct xarray txns;
+       u32 txn_next;
 
        const struct qmi_msg_handler *handlers;
 };