// SPDX-License-Identifier: GPL-2.0-only /* * 2002-10-18 written by Jim Houston jim.houston@ccur.com * Copyright (C) 2002 by Concurrent Computer Corporation * Distributed under the GNU GPL license version 2. * * Modified by George Anzinger to reuse immediately and to use * find bit instructions. Also removed _irq on spinlocks. * * Modified by Nadia Derbey to make it RCU safe. * * Small id to pointer translation service. * * It uses a radix tree like structure as a sparse array indexed * by the id to obtain the pointer. The bitmap makes allocating * a new id quick. * * You call it to allocate an id (an int) an associate with that id a * pointer or what ever, we treat it as a (void *). You can pass this * id to a user for him to pass back at a later time. You then pass * that id to this code and it returns your pointer. */ #include "linux_export.h" #include #include void *idr_find_slowpath(struct idr *idp, int id) { #ifdef MAC80211_TODO int n; struct idr_layer *p; if (id < 0) return NULL; p = rcu_dereference_raw(idp->top); if (!p) return NULL; n = (p->layer+1) * IDR_BITS; if (id > idr_max(p->layer + 1)) return NULL; BUG_ON(n == 0); while (n > 0 && p) { n -= IDR_BITS; BUG_ON(n != p->layer*IDR_BITS); p = rcu_dereference_raw(p->ary[(id >> n) & IDR_MASK]); } return((void *)p); #else (void)idp; (void)id; return NULL; #endif /* MAC80211_TODO */ } EXPORT_SYMBOL(idr_find_slowpath);