Skip to content

Commit ed5d499

Browse files
andy-shevbroonie
authored andcommitted
regcache: maple: Split ->populate() from ->init()
Split ->populate() implementation from ->init() code. This decoupling will help for the further changes. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com> Link: https://patch.msgid.link/20251031080540.3970776-6-andriy.shevchenko@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 44c1a44 commit ed5d499

1 file changed

Lines changed: 21 additions & 26 deletions

File tree

drivers/base/regmap/regcache-maple.c

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,23 @@ static int regcache_maple_sync(struct regmap *map, unsigned int min,
289289
return ret;
290290
}
291291

292+
static int regcache_maple_init(struct regmap *map)
293+
{
294+
struct maple_tree *mt;
295+
296+
mt = kmalloc(sizeof(*mt), map->alloc_flags);
297+
if (!mt)
298+
return -ENOMEM;
299+
map->cache = mt;
300+
301+
mt_init(mt);
302+
303+
if (!mt_external_lock(mt) && map->lock_key)
304+
lockdep_set_class_and_subclass(&mt->ma_lock, map->lock_key, 1);
305+
306+
return 0;
307+
}
308+
292309
static int regcache_maple_exit(struct regmap *map)
293310
{
294311
struct maple_tree *mt = map->cache;
@@ -340,26 +357,12 @@ static int regcache_maple_insert_block(struct regmap *map, int first,
340357
return ret;
341358
}
342359

343-
static int regcache_maple_init(struct regmap *map)
360+
static int regcache_maple_populate(struct regmap *map)
344361
{
345-
struct maple_tree *mt;
346362
int i;
347363
int ret;
348364
int range_start;
349365

350-
mt = kmalloc(sizeof(*mt), map->alloc_flags);
351-
if (!mt)
352-
return -ENOMEM;
353-
map->cache = mt;
354-
355-
mt_init(mt);
356-
357-
if (!mt_external_lock(mt) && map->lock_key)
358-
lockdep_set_class_and_subclass(&mt->ma_lock, map->lock_key, 1);
359-
360-
if (!map->num_reg_defaults)
361-
return 0;
362-
363366
range_start = 0;
364367

365368
/* Scan for ranges of contiguous registers */
@@ -369,30 +372,22 @@ static int regcache_maple_init(struct regmap *map)
369372
ret = regcache_maple_insert_block(map, range_start,
370373
i - 1);
371374
if (ret != 0)
372-
goto err;
375+
return ret;
373376

374377
range_start = i;
375378
}
376379
}
377380

378381
/* Add the last block */
379-
ret = regcache_maple_insert_block(map, range_start,
380-
map->num_reg_defaults - 1);
381-
if (ret != 0)
382-
goto err;
383-
384-
return 0;
385-
386-
err:
387-
regcache_maple_exit(map);
388-
return ret;
382+
return regcache_maple_insert_block(map, range_start, map->num_reg_defaults - 1);
389383
}
390384

391385
struct regcache_ops regcache_maple_ops = {
392386
.type = REGCACHE_MAPLE,
393387
.name = "maple",
394388
.init = regcache_maple_init,
395389
.exit = regcache_maple_exit,
390+
.populate = regcache_maple_populate,
396391
.read = regcache_maple_read,
397392
.write = regcache_maple_write,
398393
.drop = regcache_maple_drop,

0 commit comments

Comments
 (0)