Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/mlx4/mlx4_core/mlx4_resource_tracker.c
Show First 20 Lines • Show All 233 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
struct rb_node *node = root->rb_node; | struct rb_node *node = root->rb_node; | ||||
while (node) { | while (node) { | ||||
struct res_common *res = container_of(node, struct res_common, | struct res_common *res = container_of(node, struct res_common, | ||||
node); | node); | ||||
if (res_id < res->res_id) | if (res_id < res->res_id) | ||||
node = node->rb_left; | node = rb_ptr(node->rb_left); | ||||
else if (res_id > res->res_id) | else if (res_id > res->res_id) | ||||
node = node->rb_right; | node = rb_ptr(node->rb_right); | ||||
else | else | ||||
return res; | return res; | ||||
} | } | ||||
return NULL; | return NULL; | ||||
} | } | ||||
static int res_tracker_insert(struct rb_root *root, struct res_common *res) | static int res_tracker_insert(struct rb_root *root, struct res_common *res) | ||||
{ | { | ||||
struct rb_node **new = &(root->rb_node), *parent = NULL; | struct rb_node **new = &(root->rb_node), *parent = NULL; | ||||
/* Figure out where to put new node */ | /* Figure out where to put new node */ | ||||
while (*new) { | while (rb_ptr(*new)) { | ||||
struct res_common *this = container_of(*new, struct res_common, | struct res_common *this = container_of(rb_ptr(*new), struct res_common, | ||||
node); | node); | ||||
parent = *new; | parent = rb_ptr(*new); | ||||
if (res->res_id < this->res_id) | if (res->res_id < this->res_id) | ||||
new = &((*new)->rb_left); | new = &((*new)->rb_left); | ||||
else if (res->res_id > this->res_id) | else if (res->res_id > this->res_id) | ||||
new = &((*new)->rb_right); | new = &((*new)->rb_right); | ||||
else | else | ||||
return -EEXIST; | return -EEXIST; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 5,115 Lines • Show Last 20 Lines |