Skip to content

Commit 3bec0c2

Browse files
committed
Merge remote-tracking branch 'regmap/for-next' into sound/upstream-20241203
2 parents a1b2cae + 3ad4bd9 commit 3bec0c2

4 files changed

Lines changed: 26 additions & 18 deletions

File tree

drivers/base/regmap/regcache-maple.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ static int regcache_maple_write(struct regmap *map, unsigned int reg,
7373

7474
rcu_read_unlock();
7575

76-
entry = kmalloc((last - index + 1) * sizeof(unsigned long),
77-
map->alloc_flags);
76+
entry = kmalloc_array(last - index + 1, sizeof(*entry), map->alloc_flags);
7877
if (!entry)
7978
return -ENOMEM;
8079

@@ -204,7 +203,7 @@ static int regcache_maple_sync_block(struct regmap *map, unsigned long *entry,
204203
* overheads.
205204
*/
206205
if (max - min > 1 && regmap_can_raw_write(map)) {
207-
buf = kmalloc(val_bytes * (max - min), map->alloc_flags);
206+
buf = kmalloc_array(max - min, val_bytes, map->alloc_flags);
208207
if (!buf) {
209208
ret = -ENOMEM;
210209
goto out;
@@ -320,7 +319,7 @@ static int regcache_maple_insert_block(struct regmap *map, int first,
320319
unsigned long *entry;
321320
int i, ret;
322321

323-
entry = kcalloc(last - first + 1, sizeof(unsigned long), map->alloc_flags);
322+
entry = kmalloc_array(last - first + 1, sizeof(*entry), map->alloc_flags);
324323
if (!entry)
325324
return -ENOMEM;
326325

drivers/base/regmap/regcache-rbtree.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,18 +275,16 @@ static int regcache_rbtree_insert_to_block(struct regmap *map,
275275
pos = (reg - base_reg) / map->reg_stride;
276276
offset = (rbnode->base_reg - base_reg) / map->reg_stride;
277277

278-
blk = krealloc(rbnode->block,
279-
blklen * map->cache_word_size,
280-
map->alloc_flags);
278+
blk = krealloc_array(rbnode->block, blklen, map->cache_word_size, map->alloc_flags);
281279
if (!blk)
282280
return -ENOMEM;
283281

284282
rbnode->block = blk;
285283

286284
if (BITS_TO_LONGS(blklen) > BITS_TO_LONGS(rbnode->blklen)) {
287-
present = krealloc(rbnode->cache_present,
288-
BITS_TO_LONGS(blklen) * sizeof(*present),
289-
map->alloc_flags);
285+
present = krealloc_array(rbnode->cache_present,
286+
BITS_TO_LONGS(blklen), sizeof(*present),
287+
map->alloc_flags);
290288
if (!present)
291289
return -ENOMEM;
292290

drivers/base/regmap/regcache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ int regcache_init(struct regmap *map, const struct regmap_config *config)
154154
map->num_reg_defaults = config->num_reg_defaults;
155155
map->num_reg_defaults_raw = config->num_reg_defaults_raw;
156156
map->reg_defaults_raw = config->reg_defaults_raw;
157-
map->cache_word_size = DIV_ROUND_UP(config->val_bits, 8);
157+
map->cache_word_size = BITS_TO_BYTES(config->val_bits);
158158
map->cache_size_raw = map->cache_word_size * config->num_reg_defaults_raw;
159159

160160
map->cache = NULL;

drivers/base/regmap/regmap.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,17 @@ int regmap_attach_dev(struct device *dev, struct regmap *map,
598598
}
599599
EXPORT_SYMBOL_GPL(regmap_attach_dev);
600600

601+
static int dev_get_regmap_match(struct device *dev, void *res, void *data);
602+
603+
static int regmap_detach_dev(struct device *dev, struct regmap *map)
604+
{
605+
if (!dev)
606+
return 0;
607+
608+
return devres_release(dev, dev_get_regmap_release,
609+
dev_get_regmap_match, (void *)map->name);
610+
}
611+
601612
static enum regmap_endian regmap_get_reg_endian(const struct regmap_bus *bus,
602613
const struct regmap_config *config)
603614
{
@@ -758,14 +769,13 @@ struct regmap *__regmap_init(struct device *dev,
758769
map->alloc_flags = GFP_KERNEL;
759770

760771
map->reg_base = config->reg_base;
772+
map->reg_shift = config->pad_bits % 8;
761773

762-
map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8);
763774
map->format.pad_bytes = config->pad_bits / 8;
764775
map->format.reg_shift = config->reg_shift;
765-
map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8);
766-
map->format.buf_size = DIV_ROUND_UP(config->reg_bits +
767-
config->val_bits + config->pad_bits, 8);
768-
map->reg_shift = config->pad_bits % 8;
776+
map->format.reg_bytes = BITS_TO_BYTES(config->reg_bits);
777+
map->format.val_bytes = BITS_TO_BYTES(config->val_bits);
778+
map->format.buf_size = BITS_TO_BYTES(config->reg_bits + config->val_bits + config->pad_bits);
769779
if (config->reg_stride)
770780
map->reg_stride = config->reg_stride;
771781
else
@@ -1052,13 +1062,13 @@ struct regmap *__regmap_init(struct device *dev,
10521062

10531063
/* Sanity check */
10541064
if (range_cfg->range_max < range_cfg->range_min) {
1055-
dev_err(map->dev, "Invalid range %d: %d < %d\n", i,
1065+
dev_err(map->dev, "Invalid range %d: %u < %u\n", i,
10561066
range_cfg->range_max, range_cfg->range_min);
10571067
goto err_range;
10581068
}
10591069

10601070
if (range_cfg->range_max > map->max_register) {
1061-
dev_err(map->dev, "Invalid range %d: %d > %d\n", i,
1071+
dev_err(map->dev, "Invalid range %d: %u > %u\n", i,
10621072
range_cfg->range_max, map->max_register);
10631073
goto err_range;
10641074
}
@@ -1445,6 +1455,7 @@ void regmap_exit(struct regmap *map)
14451455
{
14461456
struct regmap_async *async;
14471457

1458+
regmap_detach_dev(map->dev, map);
14481459
regcache_exit(map);
14491460

14501461
regmap_debugfs_exit(map);

0 commit comments

Comments
 (0)