Skip to content

Commit 7dea1ff

Browse files
committed
Merge tag 'regmap-debugfs-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap
Pull regmap debugfs optimisation fixes from Mark Brown: "The debugfs optimisations merged in v3.8 weren't my finest hour, there were a number of cases that the more complex algorithm made worse especially around the error handling. This patch series should address those issues." * tag 'regmap-debugfs-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap: regmap: debugfs: Make sure we store the last entry in the offset cache regmap: debugfs: Ensure a correct return value for empty caches regmap: debugfs: Discard the cache if we fail to allocate an entry regmap: debugfs: Fix check for block start in cached seeks regmap: debugfs: Fix attempts to read nonexistant register blocks
2 parents 2ac1e66 + e8d6539 commit 7dea1ff

File tree

1 file changed

+40
-13
lines changed

1 file changed

+40
-13
lines changed

drivers/base/regmap/regmap-debugfs.c

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ static const struct file_operations regmap_name_fops = {
5656
.llseek = default_llseek,
5757
};
5858

59+
static void regmap_debugfs_free_dump_cache(struct regmap *map)
60+
{
61+
struct regmap_debugfs_off_cache *c;
62+
63+
while (!list_empty(&map->debugfs_off_cache)) {
64+
c = list_first_entry(&map->debugfs_off_cache,
65+
struct regmap_debugfs_off_cache,
66+
list);
67+
list_del(&c->list);
68+
kfree(c);
69+
}
70+
}
71+
5972
/*
6073
* Work out where the start offset maps into register numbers, bearing
6174
* in mind that we suppress hidden registers.
@@ -91,8 +104,10 @@ static unsigned int regmap_debugfs_get_dump_start(struct regmap *map,
91104
/* No cache entry? Start a new one */
92105
if (!c) {
93106
c = kzalloc(sizeof(*c), GFP_KERNEL);
94-
if (!c)
95-
break;
107+
if (!c) {
108+
regmap_debugfs_free_dump_cache(map);
109+
return base;
110+
}
96111
c->min = p;
97112
c->base_reg = i;
98113
}
@@ -101,14 +116,34 @@ static unsigned int regmap_debugfs_get_dump_start(struct regmap *map,
101116
}
102117
}
103118

119+
/* Close the last entry off if we didn't scan beyond it */
120+
if (c) {
121+
c->max = p - 1;
122+
list_add_tail(&c->list,
123+
&map->debugfs_off_cache);
124+
} else {
125+
return base;
126+
}
127+
128+
/*
129+
* This should never happen; we return above if we fail to
130+
* allocate and we should never be in this code if there are
131+
* no registers at all.
132+
*/
133+
if (list_empty(&map->debugfs_off_cache)) {
134+
WARN_ON(list_empty(&map->debugfs_off_cache));
135+
return base;
136+
}
137+
104138
/* Find the relevant block */
105139
list_for_each_entry(c, &map->debugfs_off_cache, list) {
106-
if (*pos >= c->min && *pos <= c->max) {
140+
if (from >= c->min && from <= c->max) {
107141
*pos = c->min;
108142
return c->base_reg;
109143
}
110144

111-
ret = c->max;
145+
*pos = c->min;
146+
ret = c->base_reg;
112147
}
113148

114149
return ret;
@@ -387,16 +422,8 @@ void regmap_debugfs_init(struct regmap *map, const char *name)
387422

388423
void regmap_debugfs_exit(struct regmap *map)
389424
{
390-
struct regmap_debugfs_off_cache *c;
391-
392425
debugfs_remove_recursive(map->debugfs);
393-
while (!list_empty(&map->debugfs_off_cache)) {
394-
c = list_first_entry(&map->debugfs_off_cache,
395-
struct regmap_debugfs_off_cache,
396-
list);
397-
list_del(&c->list);
398-
kfree(c);
399-
}
426+
regmap_debugfs_free_dump_cache(map);
400427
kfree(map->debugfs_name);
401428
}
402429

0 commit comments

Comments
 (0)