From: Matthew Wilcox Date: Tue, 8 Jan 2019 20:31:13 +0000 (-0500) Subject: soc: qcom: Convert txns to XArray X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=1a4f747832fd56cc9dae25109c0dc3ba9ab62a36;p=users%2Fwilly%2Fxarray.git soc: qcom: Convert txns to XArray Signed-off-by: Matthew Wilcox --- diff --git a/drivers/soc/qcom/qmi_interface.c b/drivers/soc/qcom/qmi_interface.c index f9e309f0acd3..929aee5fb5ef 100644 --- a/drivers/soc/qcom/qmi_interface.c +++ b/drivers/soc/qcom/qmi_interface.c @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -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 */ diff --git a/include/linux/soc/qcom/qmi.h b/include/linux/soc/qcom/qmi.h index 5efa2b67fa55..efe83bdad8f1 100644 --- a/include/linux/soc/qcom/qmi.h +++ b/include/linux/soc/qcom/qmi.h @@ -7,11 +7,11 @@ #define __QMI_HELPERS_H__ #include -#include #include #include #include #include +#include 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; };