From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2701647B438; Tue, 13 Oct 2026 02:36:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791859000; cv=none; b=tQE0jthzvMgPhyC+F8nF4GXSNenUK0DBAVca3vzj2+86fKHuSpAEujB3GuAWAqS3YOOnVKy8MF2ri10fmg8Ar9vyb72C+sgoHZkwTl7eHyfzm5/4cWCIMVzytGxV70Cl+njVCXxNRGOunNIX6tmkFEWAnG2unz48lDfH6QVAcFM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791859000; c=relaxed/simple; bh=9XhHQFE+V9VhxRQQhSc0QWAiHmeTAlCsUztAh1ENOCw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uPA0Y/vtkDcWynpPnfLmn/CU/HBH34uS5PI4DlKtdZ2KIX5Dc0kE4F75JKoyveiivtrzZMX2NQQKsiEEvuX+pUZoLYIF5ZooNdVRQEeHR8yAd8X1T485pPK+Cm36t+JRHQlWWU/G94SeSgVbPhWmbE3C1C2BVunJXs2FB3E8q00= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FOSNts7l; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FOSNts7l" Received: by smtp.kernel.org (Postfix) with ESMTPS id EA063C2BCFD; Tue, 13 Oct 2026 02:36:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1791859000; bh=9XhHQFE+V9VhxRQQhSc0QWAiHmeTAlCsUztAh1ENOCw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=FOSNts7lMBs9NtTAM+SoyiQuaIK2b21e5Vnmw8cRDzFJxkZ4dQ7om+HVustCHQQnY 4nUMAgpghnjeSWFHSJPoeoUkgtgfQqbuYUMpnYtOuLJKVLr/fPKfeBsrSZtfdWntos ETfHMFTIX2UcjcMY0r3lk3Wgl8yiTVfY02uDM/MVJZMADdsqxv0vhZ6LC/ukI0U9M8 D9Ln/9qvem1SSe34huznYtOGjpnJ1DTtVzKU9c4rtS4speqSn/Z1rtodoD/T6YVQB1 qdKM/A6EPxvL/wQSJ8g+Tb4BPNpGWnj8rnOlD1ipn26nzeDtMTQgm+jEiOQeibpaDD CLkoWD9maHI4w== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D810BCC6B08; Tue, 13 Oct 2026 02:36:39 +0000 (UTC) From: Jim Cromie via B4 Relay Date: Mon, 12 Oct 2026 20:36:56 -0600 Subject: [PATCH v12 25/40] dyndbg: check DYNAMIC_DEBUG_CLASSMAP_{DEFINE,USE_} args at compile-time Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261012-dd-cmap-part2-clean-v12-25-3c8cc5725def@gmail.com> References: <20261012-dd-cmap-part2-clean-v12-0-3c8cc5725def@gmail.com> In-Reply-To: <20261012-dd-cmap-part2-clean-v12-0-3c8cc5725def@gmail.com> To: Jason Baron , Shuah Khan , Andrew Morton , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Arnd Bergmann , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Jonathan Corbet , Greg Kroah-Hartman , Nathan Chancellor , Nicolas Schier , Shuah Khan , Randy Dunlap , "Rafael J. Wysocki" , Pavel Machek , Len Brown , Jonathan Corbet , Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arch@vger.kernel.org, linux-modules@vger.kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-pm@vger.kernel.org, Jim Cromie X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1791858995; l=3976; i=jim.cromie@gmail.com; s=20260203; h=from:subject:message-id; bh=BttU43V6r82KX09zxe0E4gNnGNPebpFVDPYu6yqeeqw=; b=6ezP0EYM8Hkkm3CHcq60U+JQ1xdQLcO8e0ridiYIc+G+Q78i0ZdmPIEpG26RsGqUWMxoP6q+K 8Sz07InJVBYDIcgfrpdsxT7PDCicwzCO7dmcudRbtEQIAm5fcqZmJ7Q X-Developer-Key: i=jim.cromie@gmail.com; a=ed25519; pk=C6E5ODlPQo7ZBynATXH9wg7K6HxP0pIXyf4s38Qw0XE= X-Endpoint-Received: by B4 Relay for jim.cromie@gmail.com/20260203 with auth_id=958 X-Original-From: Jim Cromie Reply-To: jim.cromie@gmail.com From: Jim Cromie Add __DYNAMIC_DEBUG_CLASSMAP_CHECK to implement the following arg-checks at compile-time: 0 <= _base < 63 class_names is not empty class_names[0] is a string class_names.length <= 32 (class_names.length + _base) < 63 dd-map-type is known value These compile-time checks will prevent several simple misuses, issuing obvious errors if violated. Several bad examples are ifdef DD_MACRO_ARGCHECK qualified in test_dynamic_debug_submod.c and will fail compilation if enabled. Signed-off-by: Jim Cromie --- include/linux/dynamic_debug.h | 16 +++++++++++++++- lib/test_dynamic_debug.c | 20 +++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h index 3c2ab0ec23c1..cd733f256b90 100644 --- a/include/linux/dynamic_debug.h +++ b/include/linux/dynamic_debug.h @@ -184,6 +184,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 <= 63"); \ + static_assert(((_mapty) >= DD_CLASS_TYPE_DISJOINT_BITS) && \ + ((_mapty) <= DD_CLASS_TYPE_LEVEL_NUM), \ + "unknown class_map_type") + /** * DYNAMIC_DEBUG_CLASSMAP_DEFINE - define debug classes used by a module. * @_var: name of the classmap, exported for other modules coordinated use. @@ -197,6 +210,7 @@ struct ddebug_class_param { */ #define DYNAMIC_DEBUG_CLASSMAP_DEFINE(_var, _mapty, _base, ...) \ static const char *_var##_classnames[] = { __VA_ARGS__ }; \ + __DYNAMIC_DEBUG_CLASSMAP_CHECK(_var##_classnames, (_base), (_mapty)); \ extern struct ddebug_class_map _var; \ struct ddebug_class_map __aligned(8) __used \ __section("__dyndbg_class_maps") _var = { \ @@ -204,7 +218,7 @@ struct ddebug_class_param { .mod_name = KBUILD_MODNAME, \ .base = (_base), \ .map_type = (_mapty), \ - .length = ARRAY_SIZE(_var##_classnames), \ + .length = __DDEBUG_ARRAY_SIZE(_var##_classnames), \ .class_names = _var##_classnames, \ }; \ EXPORT_SYMBOL(_var) diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c index 3a69cc3cae6d..01ce07001d4c 100644 --- a/lib/test_dynamic_debug.c +++ b/lib/test_dynamic_debug.c @@ -148,12 +148,26 @@ DYNAMIC_DEBUG_CLASSMAP_USE_(map_level_num, 7); enum cat_level_offset { Vu1 = V1 + 7, Vu2, Vu3, Vu4, Vu5, Vu6, Vu7 }; -#endif - +#if defined(DD_MACRO_ARGCHECK) /* - * now add the sysfs-params + * Exersize compile-time arg-checks in DYNAMIC_DEBUG_CLASSMAP_DEFINE. + * These will break compilation. */ +DYNAMIC_DEBUG_CLASSMAP_DEFINE(fail_base_neg, 0, -1, "NEGATIVE_BASE_ARG"); +DYNAMIC_DEBUG_CLASSMAP_DEFINE(fail_base_big, 0, 100, "TOOBIG_BASE_ARG"); +DYNAMIC_DEBUG_CLASSMAP_DEFINE(fail_str_type, 0, 0, 1 /* not a string */); +DYNAMIC_DEBUG_CLASSMAP_DEFINE(fail_emptyclass, 0, 0 /* ,empty */); +DYNAMIC_DEBUG_CLASSMAP_DEFINE(fail_maptype, 3, 10, "no such type"); +DYNAMIC_DEBUG_CLASSMAP_DEFINE(fail_base_len, 0, 60, + "base", "plus", "classes", "length", "too-big"); +DYNAMIC_DEBUG_CLASSMAP_USE_(fail_offset_big, 100); +#endif /* DD_MACRO_ARGCHECK */ + +#endif /* TEST_DYNAMIC_DEBUG_SUBMOD */ +/* + * now add the sysfs-params to both sub/super-mods + */ DYNAMIC_DEBUG_CLASSMAP_PARAM(disjoint_bits, p); DYNAMIC_DEBUG_CLASSMAP_PARAM(level_num, p); -- 2.56.0