[PATCH v7 14/15] net: qrtr: use nid modulo 65536 in 32-bit lookups
From: Juha-Matti Tilli
Date: Tue Sep 15 2026 - 01:48:53 EST
The node id is chosen by the device firmware, and is generally a small
single number. However, there's nothing to prevent the device from
choosing a large node id. Use node id modulo 65536 in 32-bit systems to
allow it to work in cases where the node id is large.
NOTE: this commit is a candidate for squashing with the previous and
next commit, if we want to have the "radix tree of trees" approach. This
note should probably be removed before committing. If we don't want
"radix tree of trees", this commit needs careful decision of whether we
may want to drop it.
Signed-off-by: Juha-Matti Tilli <juha-matti.tilli@xxxxxx>
---
net/qrtr/af_qrtr.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index 3c84da3059a80..87eb7363c4a9f 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -497,8 +497,11 @@ static struct qrtr_node *qrtr_node_lookup(unsigned int endpoint_id,
unsigned long flags;
unsigned long key = 0;
- if (endpoint_id > QRTR_INDEX_HALF_UNSIGNED_MAX ||
- nid > QRTR_INDEX_HALF_UNSIGNED_MAX)
+ /* nid is chosen by device firmware and is generally a single
+ * and small number. If firmware chooses otherwise, use it
+ * modulo 65536 in 32-bit systems.
+ */
+ if (endpoint_id > QRTR_INDEX_HALF_UNSIGNED_MAX)
return node;
key = ((unsigned long)(endpoint_id) << QRTR_INDEX_HALF_BITS) |
@@ -529,8 +532,11 @@ static int qrtr_node_assign(struct qrtr_node *node, unsigned int nid)
if (nid == QRTR_EP_NID_AUTO)
return 0;
- if (node->ep->id > QRTR_INDEX_HALF_UNSIGNED_MAX ||
- nid > QRTR_INDEX_HALF_UNSIGNED_MAX)
+ /* nid is chosen by device firmware and is generally a single
+ * and small number. If firmware chooses otherwise, use it
+ * modulo 65536 in 32-bit systems.
+ */
+ if (node->ep->id > QRTR_INDEX_HALF_UNSIGNED_MAX)
return -EINVAL;
spin_lock_irqsave(&qrtr_nodes_lock, flags);
--
2.34.1