regmap: debugfs: Simplify calculation of `c->max_reg'
Subsystems (2)
PATCH v2 1/1 regmap: debugfs: Simplify calculation of `c->max_reg'
We don't need to use any of the file position information to calculate the base and max register of each block. Just use the counter directly.
Ensure that in the limiting case where there is a single register in the register file we handle that properly in the if (c) { ... } code after the loop without causing an integer wrap-around.
--- drivers/base/regmap/regmap-debugfs.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/base/regmap/regmap-debugfs.c +6 -7
@@ -80,7 +80,7 @@ static unsigned int regmap_debugfs_get_dump_start(struct regmap *map, {struct regmap_debugfs_off_cache *c =NULL ;loff_t p =0 ; -unsigned int i, ret; +unsigned int i =0 , ret;unsigned int fpos_offset;unsigned int reg_offset;
@@ -95,9 +95,7 @@ static unsigned int regmap_debugfs_get_dump_start(struct regmap *map, regmap_precious(map, i)) {if (c) { c->max = p -1 ; - fpos_offset = c->max - c->min; - reg_offset = fpos_offset / map->debugfs_tot_len; - c->max_reg = c->base_reg + reg_offset; + c->max_reg = i -1 ;list_add_tail (&c->list, &map->debugfs_off_cache); c =NULL ;
@@ -124,9 +122,10 @@ static unsigned int regmap_debugfs_get_dump_start(struct regmap *map,/* Close the last entry off if we didn't scan beyond it */ if (c) { c->max = p -1 ; - fpos_offset = c->max - c->min; - reg_offset = fpos_offset / map->debugfs_tot_len; - c->max_reg = c->base_reg + reg_offset; +if (!i) + c->max_reg =0 ; +else + c->max_reg = i -1 ;list_add_tail (&c->list, &map->debugfs_off_cache); }
Signature · 1 line
1.8.1.3
drivers/base/regmap/regmap-debugfs.c static unsigned int regmap_debugfs_get_dump_start(struct regmap *map, · line 83
Quoted 2 lines · Dimitris Papastamos
drivers/base/regmap/regmap-debugfs.c +1
-1-unsigned int i, ret; +unsigned int i =0 , ret;
Coding style and are you sure this is a good default.
Quoted 6 lines · Mark Brown
drivers/base/regmap/regmap-debugfs.c static unsigned int regmap_debugfs_get_dump_start(struct regmap *map, · line 83
Quoted 2 lines · Dimitris Papastamos
drivers/base/regmap/regmap-debugfs.c +1
-1-unsigned int i, ret; +unsigned int i =0 , ret;Coding style and are you sure this is a good default.
Hm, it doesn't really matter. I guess the proper fix would be to set i = base at the start, but that would not change anything in terms of the actual code flow, it would only silence the gcc flow analysis bug.
Thanks,
Dimitris