Re: [PATCH 1/2] dyndbg: fix incorrect mod_ct value in dynamic_debug_init()

From: Yuntao Wang

Date: Sun Aug 30 2026 - 00:01:39 EST


On Sat, 29 Aug 2026 20:23:06 -0700, Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:

> On Tue, 11 Aug 2026 20:18:30 +0800 Yuntao Wang <yuntao.wang@xxxxxxxxx> wrote:
>
> > Suppose all `struct _ddebug` instances belong to the same module, mod_ct
> > should 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.
>
> > 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

> > --- a/lib/dynamic_debug.c
> > +++ b/lib/dynamic_debug.c
> > @@ -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
> >