Skip to content

Commit

Permalink
regmap: use rb_entry()
Browse files Browse the repository at this point in the history
To make the code clearer, use rb_entry() instead of container_of() to
deal with rbtree.

Signed-off-by: Geliang Tang <geliangtang@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Geliang Tang authored and Mark Brown committed Dec 19, 2016
1 parent daaadbf commit 671a911
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions drivers/base/regmap/regcache-rbtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static struct regcache_rbtree_node *regcache_rbtree_lookup(struct regmap *map,

node = rbtree_ctx->root.rb_node;
while (node) {
rbnode = container_of(node, struct regcache_rbtree_node, node);
rbnode = rb_entry(node, struct regcache_rbtree_node, node);
regcache_rbtree_get_base_top_reg(map, rbnode, &base_reg,
&top_reg);
if (reg >= base_reg && reg <= top_reg) {
Expand All @@ -108,8 +108,7 @@ static int regcache_rbtree_insert(struct regmap *map, struct rb_root *root,
parent = NULL;
new = &root->rb_node;
while (*new) {
rbnode_tmp = container_of(*new, struct regcache_rbtree_node,
node);
rbnode_tmp = rb_entry(*new, struct regcache_rbtree_node, node);
/* base and top registers of the current rbnode */
regcache_rbtree_get_base_top_reg(map, rbnode_tmp, &base_reg_tmp,
&top_reg_tmp);
Expand Down Expand Up @@ -152,7 +151,7 @@ static int rbtree_show(struct seq_file *s, void *ignored)

for (node = rb_first(&rbtree_ctx->root); node != NULL;
node = rb_next(node)) {
n = container_of(node, struct regcache_rbtree_node, node);
n = rb_entry(node, struct regcache_rbtree_node, node);
mem_size += sizeof(*n);
mem_size += (n->blklen * map->cache_word_size);
mem_size += BITS_TO_LONGS(n->blklen) * sizeof(long);
Expand Down
4 changes: 2 additions & 2 deletions drivers/base/regmap/regmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ static bool _regmap_range_add(struct regmap *map,

while (*new) {
struct regmap_range_node *this =
container_of(*new, struct regmap_range_node, node);
rb_entry(*new, struct regmap_range_node, node);

parent = *new;
if (data->range_max < this->range_min)
Expand All @@ -483,7 +483,7 @@ static struct regmap_range_node *_regmap_range_lookup(struct regmap *map,

while (node) {
struct regmap_range_node *this =
container_of(node, struct regmap_range_node, node);
rb_entry(node, struct regmap_range_node, node);

if (reg < this->range_min)
node = node->rb_left;
Expand Down

0 comments on commit 671a911

Please sign in to comment.