mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-24 09:50:04 +00:00
regmap: regcache-rbtree: Clean new present bits on present bitmap resize
When inserting a new register into a block, the present bit map size is
increased using krealloc. krealloc does not clear the additionally
allocated memory, leaving it filled with random values. Result is that
some registers are considered cached even though this is not the case.
Fix the problem by clearing the additionally allocated memory. Also, if
the bitmap size does not increase, do not reallocate the bitmap at all
to reduce overhead.
Fixes: 3f4ff561bc
("regmap: rbtree: Make cache_present bitmap per node")
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Mark Brown <broonie@kernel.org>
Cc: stable@vger.kernel.org
This commit is contained in:
parent
d770e558e2
commit
8ef9724bf9
1 changed files with 14 additions and 5 deletions
|
@ -296,11 +296,20 @@ static int regcache_rbtree_insert_to_block(struct regmap *map,
|
|||
if (!blk)
|
||||
return -ENOMEM;
|
||||
|
||||
present = krealloc(rbnode->cache_present,
|
||||
BITS_TO_LONGS(blklen) * sizeof(*present), GFP_KERNEL);
|
||||
if (!present) {
|
||||
kfree(blk);
|
||||
return -ENOMEM;
|
||||
if (BITS_TO_LONGS(blklen) > BITS_TO_LONGS(rbnode->blklen)) {
|
||||
present = krealloc(rbnode->cache_present,
|
||||
BITS_TO_LONGS(blklen) * sizeof(*present),
|
||||
GFP_KERNEL);
|
||||
if (!present) {
|
||||
kfree(blk);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memset(present + BITS_TO_LONGS(rbnode->blklen), 0,
|
||||
(BITS_TO_LONGS(blklen) - BITS_TO_LONGS(rbnode->blklen))
|
||||
* sizeof(*present));
|
||||
} else {
|
||||
present = rbnode->cache_present;
|
||||
}
|
||||
|
||||
/* insert the register value in the correct place in the rbnode block */
|
||||
|
|
Loading…
Reference in a new issue