From e00d15abf59110811900645dd8319dee24c81247 Mon Sep 17 00:00:00 2001 From: Chris Lew Date: Mon, 3 Oct 2022 09:58:06 -0700 Subject: [PATCH] net: qrtr: Improve qrtr_node_assign First check if the node is already assigned the requested nid, this allows an early exit for the common case. Do not allow later nodes to overwrite a node id. The first to claim a node id should get priority. Change-Id: Ie3da0c3b709de8c68f9918cd485492f9eaa41247 Signed-off-by: Chris Lew --- net/qrtr/af_qrtr.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c index af77ee732753..28b6fc6d5ccb 100644 --- a/net/qrtr/af_qrtr.c +++ b/net/qrtr/af_qrtr.c @@ -457,11 +457,13 @@ static void qrtr_node_assign(struct qrtr_node *node, unsigned int nid) { unsigned long flags; - if (nid == QRTR_EP_NID_AUTO) + if (nid == node->nid || nid == QRTR_EP_NID_AUTO) return; spin_lock_irqsave(&qrtr_nodes_lock, flags); - radix_tree_insert(&qrtr_nodes, nid, node); + if (!radix_tree_lookup(&qrtr_nodes, nid)) + radix_tree_insert(&qrtr_nodes, nid, node); + if (node->nid == QRTR_EP_NID_AUTO) node->nid = nid; spin_unlock_irqrestore(&qrtr_nodes_lock, flags);