mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2025-01-24 16:29:55 +07:00
regmap: rbtree: Factor out node allocation
In preparation for being slightly smarter about how we allocate memory factor out the node allocation. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
This commit is contained in:
parent
154881e59b
commit
0186645d25
@ -304,6 +304,27 @@ static int regcache_rbtree_insert_to_block(struct regmap *map,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct regcache_rbtree_node *
|
||||||
|
regcache_rbtree_node_alloc(struct regmap *map, unsigned int reg)
|
||||||
|
{
|
||||||
|
struct regcache_rbtree_node *rbnode;
|
||||||
|
|
||||||
|
rbnode = kzalloc(sizeof(*rbnode), GFP_KERNEL);
|
||||||
|
if (!rbnode)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
rbnode->blklen = sizeof(*rbnode);
|
||||||
|
rbnode->base_reg = reg;
|
||||||
|
rbnode->block = kmalloc(rbnode->blklen * map->cache_word_size,
|
||||||
|
GFP_KERNEL);
|
||||||
|
if (!rbnode->block) {
|
||||||
|
kfree(rbnode);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rbnode;
|
||||||
|
}
|
||||||
|
|
||||||
static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
|
static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
|
||||||
unsigned int value)
|
unsigned int value)
|
||||||
{
|
{
|
||||||
@ -354,23 +375,15 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* we did not manage to find a place to insert it in an existing
|
|
||||||
* block so create a new rbnode with a single register in its block.
|
/* We did not manage to find a place to insert it in
|
||||||
* This block will get populated further if any other adjacent
|
* an existing block so create a new rbnode.
|
||||||
* registers get modified in the future.
|
|
||||||
*/
|
*/
|
||||||
rbnode = kzalloc(sizeof *rbnode, GFP_KERNEL);
|
rbnode = regcache_rbtree_node_alloc(map, reg);
|
||||||
if (!rbnode)
|
if (!rbnode)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
rbnode->blklen = sizeof(*rbnode);
|
regcache_rbtree_set_register(map, rbnode,
|
||||||
rbnode->base_reg = reg;
|
reg - rbnode->base_reg, value);
|
||||||
rbnode->block = kmalloc(rbnode->blklen * map->cache_word_size,
|
|
||||||
GFP_KERNEL);
|
|
||||||
if (!rbnode->block) {
|
|
||||||
kfree(rbnode);
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
regcache_rbtree_set_register(map, rbnode, 0, value);
|
|
||||||
regcache_rbtree_insert(map, &rbtree_ctx->root, rbnode);
|
regcache_rbtree_insert(map, &rbtree_ctx->root, rbnode);
|
||||||
rbtree_ctx->cached_rbnode = rbnode;
|
rbtree_ctx->cached_rbnode = rbnode;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user