[PATCH v6 14/15] net: qrtr: use nid modulo 65536 in 32-bit lookups

From: Juha-Matti Tilli

Date: Tue Sep 01 2026 - 09:53:02 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: please don't merge yet. This commit will have to be either
squashed or removed.

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 f1601c0701fdb..960e6e816be41 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