Changeset View
Changeset View
Standalone View
Standalone View
sys/compat/linuxkpi/common/src/linux_idr.c
Show First 20 Lines • Show All 212 Lines • ▼ Show 20 Lines | idr_remove_all(struct idr *idr) | ||||
mtx_lock(&idr->lock); | mtx_lock(&idr->lock); | ||||
idr_remove_layer(idr->top, idr->layers - 1); | idr_remove_layer(idr->top, idr->layers - 1); | ||||
idr->top = NULL; | idr->top = NULL; | ||||
idr->layers = 0; | idr->layers = 0; | ||||
mtx_unlock(&idr->lock); | mtx_unlock(&idr->lock); | ||||
} | } | ||||
static void | static void * | ||||
idr_remove_locked(struct idr *idr, int id) | idr_remove_locked(struct idr *idr, int id) | ||||
{ | { | ||||
struct idr_layer *il; | struct idr_layer *il; | ||||
void *res; | |||||
int layer; | int layer; | ||||
int idx; | int idx; | ||||
id &= MAX_ID_MASK; | id &= MAX_ID_MASK; | ||||
il = idr->top; | il = idr->top; | ||||
layer = idr->layers - 1; | layer = idr->layers - 1; | ||||
if (il == NULL || id > idr_max(idr)) | if (il == NULL || id > idr_max(idr)) | ||||
return; | return NULL; | ||||
/* | /* | ||||
* Walk down the tree to this item setting bitmaps along the way | * Walk down the tree to this item setting bitmaps along the way | ||||
* as we know at least one item will be free along this path. | * as we know at least one item will be free along this path. | ||||
*/ | */ | ||||
while (layer && il) { | while (layer && il) { | ||||
idx = idr_pos(id, layer); | idx = idr_pos(id, layer); | ||||
il->bitmap |= 1 << idx; | il->bitmap |= 1 << idx; | ||||
il = il->ary[idx]; | il = il->ary[idx]; | ||||
layer--; | layer--; | ||||
} | } | ||||
res = il->ary[idx]; | |||||
hselasky: I think this "res = " should be after the "idx = " ? | |||||
Not Done Inline ActionsGood catch! Fixed in my local branch. johalun0_gmail.com: Good catch! Fixed in my local branch. | |||||
idx = id & IDR_MASK; | idx = id & IDR_MASK; | ||||
/* | /* | ||||
* At this point we've set free space bitmaps up the whole tree. | * At this point we've set free space bitmaps up the whole tree. | ||||
* We could make this non-fatal and unwind but linux dumps a stack | * We could make this non-fatal and unwind but linux dumps a stack | ||||
* and a warning so I don't think it's necessary. | * and a warning so I don't think it's necessary. | ||||
*/ | */ | ||||
if (il == NULL || (il->bitmap & (1 << idx)) != 0) | if (il == NULL || (il->bitmap & (1 << idx)) != 0) | ||||
panic("idr_remove: Item %d not allocated (%p, %p)\n", | panic("idr_remove: Item %d not allocated (%p, %p)\n", | ||||
id, idr, il); | id, idr, il); | ||||
il->ary[idx] = NULL; | il->ary[idx] = NULL; | ||||
Done Inline ActionsYou might want to put after the if-checks, just before the NULL assignment. hselasky: You might want to put after the if-checks, just before the NULL assignment. | |||||
il->bitmap |= 1 << idx; | il->bitmap |= 1 << idx; | ||||
return (res); | |||||
} | } | ||||
void | void * | ||||
idr_remove(struct idr *idr, int id) | idr_remove(struct idr *idr, int id) | ||||
{ | { | ||||
void *res; | |||||
mtx_lock(&idr->lock); | mtx_lock(&idr->lock); | ||||
idr_remove_locked(idr, id); | res = idr_remove_locked(idr, id); | ||||
mtx_unlock(&idr->lock); | mtx_unlock(&idr->lock); | ||||
return (res); | |||||
} | } | ||||
static inline struct idr_layer * | static inline struct idr_layer * | ||||
idr_find_layer_locked(struct idr *idr, int id) | idr_find_layer_locked(struct idr *idr, int id) | ||||
{ | { | ||||
struct idr_layer *il; | struct idr_layer *il; | ||||
int layer; | int layer; | ||||
▲ Show 20 Lines • Show All 437 Lines • ▼ Show 20 Lines | idr_for_each_layer(struct idr_layer *il, int offset, int layer, | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
/* NOTE: It is not allowed to modify the IDR tree while it is being iterated */ | /* NOTE: It is not allowed to modify the IDR tree while it is being iterated */ | ||||
int | int | ||||
idr_for_each(struct idr *idp, int (*f)(int id, void *p, void *data), void *data) | idr_for_each(struct idr *idp, int (*f)(int id, void *p, void *data), void *data) | ||||
{ | { | ||||
return (idr_for_each_layer(idp->top, 0, idp->layers - 1, f, data)); | return (idr_for_each_layer(idp->top, 0, idp->layers - 1, f, data)); | ||||
} | |||||
static int | |||||
idr_has_entry(int id, void *p, void *data) | |||||
{ | |||||
Not Done Inline ActionsIs this one only used for debugging? hselasky: Is this one only used for debugging? | |||||
Not Done Inline ActionsIs is only used directly by the function below, idr_is_empty. drm_lease is actually not used currently because we lack something it needs but probably will be in the future johalun0_gmail.com: Is is only used directly by the function below, idr_is_empty.
idr_is_empty is used here
https… | |||||
return 1; | |||||
} | |||||
bool | |||||
idr_is_empty(struct idr *idp) | |||||
{ | |||||
return !idr_for_each(idp, idr_has_entry, NULL); | |||||
} | } | ||||
int | int | ||||
ida_pre_get(struct ida *ida, gfp_t flags) | ida_pre_get(struct ida *ida, gfp_t flags) | ||||
{ | { | ||||
if (idr_pre_get(&ida->idr, flags) == 0) | if (idr_pre_get(&ida->idr, flags) == 0) | ||||
return (0); | return (0); | ||||
▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines |
I think this "res = " should be after the "idx = " ?