Skip to content

Commit 3981514

Browse files
Jim Wylderbroonie
authored andcommitted
regmap: Account for register length when chunking
Currently, when regmap_raw_write() splits the data, it uses the max_raw_write value defined for the bus. For any bus that includes the target register address in the max_raw_write value, the chunked transmission will always exceed the maximum transmission length. To avoid this problem, subtract the length of the register and the padding from the maximum transmission. Signed-off-by: Jim Wylder <jwylder@google.com Link: https://lore.kernel.org/r/20230517152444.3690870-2-jwylder@google.com Signed-off-by: Mark Brown <broonie@kernel.org
1 parent 70a640c commit 3981514

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/base/regmap/regmap.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,15 +2082,17 @@ int _regmap_raw_write(struct regmap *map, unsigned int reg,
20822082
size_t val_count = val_len / val_bytes;
20832083
size_t chunk_count, chunk_bytes;
20842084
size_t chunk_regs = val_count;
2085+
size_t max_data = map->max_raw_write - map->format.reg_bytes -
2086+
map->format.pad_bytes;
20852087
int ret, i;
20862088

20872089
if (!val_count)
20882090
return -EINVAL;
20892091

20902092
if (map->use_single_write)
20912093
chunk_regs = 1;
2092-
else if (map->max_raw_write && val_len > map->max_raw_write)
2093-
chunk_regs = map->max_raw_write / val_bytes;
2094+
else if (map->max_raw_write && val_len > max_data)
2095+
chunk_regs = max_data / val_bytes;
20942096

20952097
chunk_count = val_count / chunk_regs;
20962098
chunk_bytes = chunk_regs * val_bytes;

0 commit comments

Comments
 (0)