Compare

2f93bcb3f9aaf6ceee1aec0a97d4fe386d48e781..834035934cef9e60169de682f4dc9feafd49e51a

regmap: Remove debugfs before cache teardown

regmap_exit() and regmap_reinit_cache() destroy the register cache before
removing debugfs. A concurrent debugfs cache operation can therefore
access cache state after the backend exit callback starts freeing it.

Remove debugfs before cache teardown, and clear the debugfs pointer after
removal. During cache reinitialization, recreate debugfs only after the
new cache initializes successfully.

Signed-off-by: Michael Reeves <michael.reeves077@gmail.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Link: https://patch.msgid.link/20261006-regcache-lifecycle-submit-v3-1-37bdd82fd47c@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>

Michael Reeves <michael.reeves077@gmail.com> · 2026-10-06 07:03 UTC · committed by Mark Brown

Browse files
4 files changed, +24 −27
modified drivers/base/regmap/regmap-debugfs.c
@@ -664,6 +664,7 @@ void regmap_debugfs_exit(struct regmap *map)
664 664 {
665 665 if (map->debugfs) {
666 666 debugfs_remove_recursive(map->debugfs);
667 + map->debugfs = NULL;
667 668 mutex_lock(&map->cache_lock);
668 669 regmap_debugfs_free_dump_cache(map);
669 670 mutex_unlock(&map->cache_lock);
modified drivers/base/regmap/regmap.c
@@ -1422,8 +1422,8 @@ int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config)
1422 1422 {
1423 1423 int ret;
1424 1424
1425 - regcache_exit(map);
1426 1425 regmap_debugfs_exit(map);
1426 + regcache_exit(map);
1427 1427
1428 1428 map->max_register = config->max_register;
1429 1429 map->max_register_is_set = map->max_register ?: config->max_register_is_0;
@@ -1440,12 +1440,16 @@ int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config)
1440 1440 if (ret)
1441 1441 return ret;
1442 1442
1443 - regmap_debugfs_init(map);
1444 -
1445 1443 map->cache_bypass = false;
1446 1444 map->cache_only = false;
1447 1445
1448 - return regcache_init(map, config);
1446 + ret = regcache_init(map, config);
1447 + if (ret)
1448 + return ret;
1449 +
1450 + regmap_debugfs_init(map);
1451 +
1452 + return 0;
1449 1453 }
1450 1454 EXPORT_SYMBOL_GPL(regmap_reinit_cache);
1451 1455
@@ -1459,9 +1463,8 @@ void regmap_exit(struct regmap *map)
1459 1463 struct regmap_async *async;
1460 1464
1461 1465 regmap_detach_dev(map->dev, map);
1462 - regcache_exit(map);
1463 -
1464 1466 regmap_debugfs_exit(map);
1467 + regcache_exit(map);
1465 1468 regmap_range_exit(map);
1466 1469 if (map->bus && map->bus->free_context)
1467 1470 map->bus->free_context(map->bus_context);
modified kernel/sched/core.c
@@ -11327,16 +11327,17 @@ void sched_change_end(struct sched_change_ctx *ctx)
11327 11327 if (p->sched_class->switched_to)
11328 11328 p->sched_class->switched_to(rq, p);
11329 11329
11330 - /*
11331 - * Check if the task can preempt the current in case the class
11332 - * was upgraded. Note that none of the switch*_from() methods
11333 - * know the new class and none of the switch*_to() methods know
11334 - * the old class so we must resched here.
11335 - */
11336 - if (ctx->queued)
11337 - wakeup_preempt(rq, p, 0);
11338 -
11339 11330 if (ctx->running) {
11331 + /*
11332 + * If this was a class promotion; let the old class
11333 + * know it got preempted. Note that none of the
11334 + * switch*_from() methods know the new class and none
11335 + * of the switch*_to() methods know the old class.
11336 + */
11337 + if (sched_class_above(p->sched_class, ctx->class)) {
11338 + rq->next_class->wakeup_preempt(rq, p, 0);
11339 + rq->next_class = p->sched_class;
11340 + }
11340 11341 /*
11341 11342 * If this was a degradation in class; make sure to
11342 11343 * reschedule.
modified kernel/sched/fair.c
@@ -6463,20 +6463,12 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
6463 6463 load = cfs_rq->sum_weight;
6464 6464 if (curr && curr->on_rq)
6465 6465 load += avg_vruntime_weight(cfs_rq, curr->h_load.weight);
6466 - if (WARN_ON_ONCE(!load))
6467 - load = 1;
6468 6466
6469 6467 weight = avg_vruntime_weight(cfs_rq, se->h_load.weight);
6470 -
6471 - /*
6472 - * Rewrite, because the product (W + w_i)*vl'_i might
6473 - * overflow s64:
6474 - *
6475 - * vl_i = (W + w_i)*vl'_i / W
6476 - * = (W*vl'_i + w_i*vl'_i) / W
6477 - * = vl'_i + w_i*vl'_i/W
6478 - */
6479 - lag += div64_long(lag * weight, load);
6468 + lag *= load + weight;
6469 + if (WARN_ON_ONCE(!load))
6470 + load = 1;
6471 + lag = div64_long(lag, load);
6480 6472
6481 6473 /*
6482 6474 * A heavy entity (relative to the tree) will pull the