dyndbg: fix incorrect mod_ct value in dynamic_debug_init()
Subsystems (2)
cover dyndbg: fix incorrect mod_ct value in dynamic_debug_init()
Fix and clean up the dynamic_debug_init() function.
Yuntao Wang (2):
dyndbg: fix incorrect mod_ct value in dynamic_debug_init()
dyndbg: clean up dynamic_debug_init() to improve readability
lib/dynamic_debug.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
--
2.55.0
PATCH 1/2 dyndbg: fix incorrect mod_ct value in dynamic_debug_init()
Suppose all struct _ddebug instances belong to the same module, mod_ct should be 1, but it is currently 0.
Fix it.
--- lib/dynamic_debug.c | 2 ++ 1 file changed, 2 insertions(+)
lib/dynamic_debug.c +2 -0
@@ -1456,6 +1456,8 @@ static int __init dynamic_debug_init(void) iter_mod_start = iter; } } + + mod_ct++; di.num_descs = mod_sites; di.descs = iter_mod_start; ret =ddebug_add_module (&di, modname);
Signature · 1 line
2.55.0
Andrew Morton
maintainerQuoted 2 lines · On Tue, 11 Aug 2026 20:18:30 +0800 Yuntao Wang <[email protected]> wrote:
Suppose all
struct _ddebuginstances belong to the same module,mod_ctshould be 1, but it is currently 0.
Oh. Why. Does
if (strcmp(modname, iter->modname)) {not evaluate to true in this situation?
ie, more details please.
Quoted 1 line
Fix it.
What are the userspace-visible runtime effects of this bug?
Thanks.
Quoted 14 lines
lib/dynamic_debug.c +2
-0@@ -1456,6 +1456,8 @@ static int __init dynamic_debug_init(void) iter_mod_start = iter; } } + + mod_ct++; di.num_descs = mod_sites; di.descs = iter_mod_start; ret =ddebug_add_module (&di, modname);Signature · 1 line
2.55.0
Quoted 11 lines · Andrew Morton
Quoted 2 lines · On Tue, 11 Aug 2026 20:18:30 +0800 Yuntao Wang <[email protected]> wrote:
Suppose all
struct _ddebuginstances belong to the same module,mod_ctshould be 1, but it is currently 0.Oh. Why. Does
if (strcmp(modname, iter->modname)) {not evaluate to true in this situation?
Quoted 7 lines
ie, more details please.
Quoted 1 line
Fix it.
What are the userspace-visible runtime effects of this bug?
Thanks.
Hi Andrew,
mod_ct is incremented only when iter->modname changes, i.e. when the loop encounters the first _ddebug entry of a new module:
if (strcmp(modname, iter->modname)) {
mod_ct++;
...
}If all _ddebug entries belong to the same module, strcmp() never returns nonzero, so mod_ct remains 0.
However, the last (and in this case only) module is added after the loop:
di.num_descs = mod_sites;
di.descs = iter_mod_start;
ret = ddebug_add_module(&di, modname);
Thus, mod_ct should be incremented before adding this final module.
The bug only affects the diagnostic message printed by vpr_info():
"%d prdebugs in %d modules, ..."
It reports one fewer module than the actual number of modules. There is no userspace-visible runtime effect; the dynamic debug tables themselves are initialized correctly.
Thanks,
Yuntao
Quoted 14 lines
Quoted 14 lines
lib/dynamic_debug.c +2
-1@@ -1456,6 +1456,8 @@ static int __init dynamic_debug_init(void) iter_mod_start = iter; } } + + mod_ct++; di.num_descs = mod_sites; di.descs = iter_mod_start; ret =ddebug_add_module (&di, modname); --2.55.0
PATCH 2/2 dyndbg: clean up dynamic_debug_init() to improve readability
In reply to Yuntao WangKeep variable assignments in the same order throughout the function to make the code easier to follow.
No functional changes.
--- lib/dynamic_debug.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
lib/dynamic_debug.c +8 -7
@@ -1442,28 +1442,29 @@ static int __init dynamic_debug_init(void) i = mod_sites = mod_ct =0 ;for (; iter < __stop___dyndbg; iter++, i++, mod_sites++) { -if (strcmp (modname, iter->modname)) { - mod_ct++; - di.num_descs = mod_sites; di.descs = iter_mod_start; + di.num_descs = mod_sites; ret =ddebug_add_module (&di, modname);if (ret) goto out_err; - mod_sites =0 ; - modname = iter->modname; + mod_ct++; + iter_mod_start = iter; + modname = iter->modname; + mod_sites =0 ; } } - mod_ct++; - di.num_descs = mod_sites; di.descs = iter_mod_start; + di.num_descs = mod_sites; ret =ddebug_add_module (&di, modname);if (ret) goto out_err; + mod_ct++; + ddebug_init_success =1 ; vpr_info("%d prdebugs in %d modules, %d KiB in ddebug tables, %d kiB in __dyndbg section\n", i, mod_ct, (int)((mod_ct * sizeof(struct ddebug_table)) >> 10),
Signature · 1 line
2.55.0
Hi all,
Just a gentle ping on this patch series. Any chance someone could take a look and review it?
I'd really appreciate it.
Thanks,
Yuntao