Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Compile-time check incorrectly rejects valid class ID 62 due to an off-by-one error in the upper bound assertion. --
commit eff2fbed05187c69eca3bc170f67e07db2c41b8d Author: Jim Cromie <[email protected]> dyndbg: check DYNAMIC_DEBUG_CLASSMAP_{DEFINE,USE_} args at compile-time This commit adds the __DYNAMIC_DEBUG_CLASSMAP_CHECK macro to implement compile-time argument checks for dynamic debug classmaps. These assertions validate bounds for the base offset, class names length, and map types to prevent simple misuses. > diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h > index 17fc3a29d97b8..471b9891bd83b 100644 > --- a/include/linux/dynamic_debug.h > +++ b/include/linux/dynamic_debug.h > @@ -197,6 +197,19 @@ struct ddebug_class_param { > * __pr_debug_cls(22, "no such class"); compiles but is not reachable > */ > > +#define __DYNAMIC_DEBUG_CLASSMAP_CHECK(_clnames, _base, _mapty) > \ > + static_assert(((_base) >= 0 && (_base) < _DPRINTK_CLASS_DFLT), \ > + "_base must be in 0..62"); \ > + static_assert(__DDEBUG_ARRAY_SIZE(_clnames) > 0, > \ > + "classnames array size must be > 0"); \ > + static_assert(__DDEBUG_ARRAY_SIZE(_clnames) <= 32, > \ > + "classnames array size must be <= 32"); \ > + static_assert((__DDEBUG_ARRAY_SIZE(_clnames) + (_base)) < > _DPRINTK_CLASS_DFLT, \ > + "_base + classnames.length must be <= 62"); \ [Severity: Low] Does this logic introduce an off-by-one error that inadvertently rejects valid class maps? The first static assertion correctly allows a base up to 62 by verifying it is less than _DPRINTK_CLASS_DFLT. However, if a class map is defined with a single class at a base of 62, the sum of the base and array size evaluates to 63. Since this check strictly enforces that the sum must be less than _DPRINTK_CLASS_DFLT (meaning <= 62), it would fail compilation. Should this assertion allow the sum to be equal to _DPRINTK_CLASS_DFLT to permit a single class definition at the highest allowed base? > + static_assert(((_mapty) >= DD_CLASS_TYPE_DISJOINT_BITS) && \ > + ((_mapty) <= DD_CLASS_TYPE_LEVEL_NUM), \ > + "unknown class_map_type") > + -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=30
