From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E673AECD6F9 for ; Thu, 12 Feb 2026 00:14:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D6CFD10E68F; Thu, 12 Feb 2026 00:14:54 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="R6wzY2bs"; dkim-atps=neutral Received: from mail-oa1-f65.google.com (mail-oa1-f65.google.com [209.85.160.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id A084A10E695 for ; Thu, 12 Feb 2026 00:14:39 +0000 (UTC) Received: by mail-oa1-f65.google.com with SMTP id 586e51a60fabf-409521ba360so1581700fac.2 for ; Wed, 11 Feb 2026 16:14:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770855278; x=1771460078; darn=lists.freedesktop.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=j2MYJzJHADFhmDlQmMQlbImDYfLHhfEQ7IriPsfmok0=; b=R6wzY2bsYThndyYj5gOsSk5YdsAoKe/pJQ5IP7CGcVz9X7XuUetJH9Knno/6bCK7jc UtsbZfzxfWOjuD0TU6N66RWVrRsHI4K/t9qh7Q3q7zRP1lDisN+YizFEeCou/FUNGLT4 eE4j1gUjmJll5SeH3mCzdfzPWRW7WMpSJB2HVxudZZYCVNWprB2D/QyI0n3epT2/vCcL Qx+siUtUclcp21sArry8qb2DM9xbGvySzddOtvMNJGxvTK6tkWa0ObG9unGKBOa4hW1I pI56QrHj5ncaBLCntU68lKASCxbEX0lQNCHCTkriVGFXr+2DfTX9FLZ7EQKyQFqxuA2R DsvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770855278; x=1771460078; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=j2MYJzJHADFhmDlQmMQlbImDYfLHhfEQ7IriPsfmok0=; b=gIzbH5A6yJU12YPZonMiVy89AcIYSYoDubrl//2/s/VtXNd+ZjXGPA6mc96cfSnkpg qiQKDMczZb6q4cGrd3OW9krFd230ey1gGMAriRuR/xGEdIAt5igxggLPHY46E0xT5+94 J+wRvLG4L0sRkD1wxg5oeARyRemtQGKSnUCMA4nSyblWpu/7ExarnuDfCxTThR4DsCAe XDCwdSD7Ud7dEnsKANL0juOXmGE5CYkN3FtUqsreSWiMpvw1ZoDhXbZXJ3cNlAyMDyNj +/0keaoRZu66pD52gbCHZN00rbDT9XaU8H9BxgbQUARv2f5h0drGXw0B5vEivx7RuVHb 04Wg== X-Gm-Message-State: AOJu0Yy1CH4SADkFJ/DL6DEAfa0GXK9QWdFUB+Mvz47axq8K8piz89I4 XwQfdEsujuudBxxRYB67BOE4Po1yFnJu0Xj3A0pgqjDbLg3VGtwYIqpIytVrzAAt X-Gm-Gg: AZuq6aJfqi4gZsnkx72yMmla4w2kKZWKIxofits5ufxJvCwDVyHoTXoJ0LNa8REsycj MtC3b5lH5z32GTGSfizn0cRNr18FlRecR641mErwvkUL5XF367TWDouE3nl+3FAsjqcz7mTd4ew jMec7+TdCyYwGFwkf9iv1oOg/11VWJ6YFk/JaXfdAb6Io0ZbQQiP65i29VoYllUqJxyVb9orFQP xVd3lnaB1QHRXH6fgzN3ZmQm6azYTBJKhC8SgE6FQM7jHeAcYjEX7ylG9g1ylgZKscUNvOeWNTs CgevMhatdTL38Aw5SFQSlMil+mhw9TM/ZQXSqyrA2sJfTRRD+rK8sNMoY2Lk+8WXoov8oOVZAhD akB6JXAgUCWyReW4CH372aeDInVwKiDbd6CBHkfpBjIYZBXcFtC2pLZ2NXP1CfeTyWZW4p8v84R WBMNSLT8e2lUxZSpEgUQLJYD09xX+uy232kAlLiTzlq3DwlE/dmkiT X-Received: by 2002:a05:6870:a18e:b0:409:794e:fdb with SMTP id 586e51a60fabf-40eca1fddcbmr358256fac.36.1770855278456; Wed, 11 Feb 2026 16:14:38 -0800 (PST) Received: from godzilla (c-98-38-17-99.hsd1.co.comcast.net. [98.38.17.99]) by smtp.googlemail.com with ESMTPSA id 586e51a60fabf-40eaf1062ffsm2331939fac.13.2026.02.11.16.14.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Feb 2026 16:14:38 -0800 (PST) From: Jim Cromie To: dri-devel@lists.freedesktop.org, intel-gfx-trybot@lists.freedesktop.org Cc: Jim Cromie Subject: [PATCH 24/61] dyndbg: check DYNAMIC_DEBUG_CLASSMAP_DEFINE args at compile-time Date: Wed, 11 Feb 2026 17:13:19 -0700 Message-ID: <20260212001359.97296-25-jim.cromie@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260212001359.97296-24-jim.cromie@gmail.com> References: <20260212001359.97296-1-jim.cromie@gmail.com> <20260212001359.97296-2-jim.cromie@gmail.com> <20260212001359.97296-3-jim.cromie@gmail.com> <20260212001359.97296-4-jim.cromie@gmail.com> <20260212001359.97296-5-jim.cromie@gmail.com> <20260212001359.97296-6-jim.cromie@gmail.com> <20260212001359.97296-7-jim.cromie@gmail.com> <20260212001359.97296-8-jim.cromie@gmail.com> <20260212001359.97296-9-jim.cromie@gmail.com> <20260212001359.97296-10-jim.cromie@gmail.com> <20260212001359.97296-11-jim.cromie@gmail.com> <20260212001359.97296-12-jim.cromie@gmail.com> <20260212001359.97296-13-jim.cromie@gmail.com> <20260212001359.97296-14-jim.cromie@gmail.com> <20260212001359.97296-15-jim.cromie@gmail.com> <20260212001359.97296-16-jim.cromie@gmail.com> <20260212001359.97296-17-jim.cromie@gmail.com> <20260212001359.97296-18-jim.cromie@gmail.com> <20260212001359.97296-19-jim.cromie@gmail.com> <20260212001359.97296-20-jim.cromie@gmail.com> <20260212001359.97296-21-jim.cromie@gmail.com> <20260212001359.97296-22-jim.cromie@gmail.com> <20260212001359.97296-23-jim.cromie@gmail.com> <20260212001359.97296-24-jim.cromie@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 + _base) < 63 These compile-time checks will prevent several simple misuses, and will issue obvious errors if violated. 4 such examples are added to test_dynamic_debug_submod.ko, and will fail compilation if -DDD_MACRO_ARGCHECK is added to cflags. This wouldn't be a useful CONFIG_ item, since it breaks the build. Signed-off-by: Jim Cromie --- include/linux/dynamic_debug.h | 9 +++++++++ lib/test_dynamic_debug.c | 13 ++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h index 74ed18a038bd..d3889173abf3 100644 --- a/include/linux/dynamic_debug.h +++ b/include/linux/dynamic_debug.h @@ -181,6 +181,14 @@ struct _ddebug_class_param { * __pr_debug_cls(22, "no such class"); compiles but is not reachable */ +#define __DYNAMIC_DEBUG_CLASSMAP_CHECK(_clnames, _base) \ + static_assert(((_base) >= 0 && (_base) < _DPRINTK_CLASS_DFLT), \ + "_base must be in 0..62"); \ + static_assert(ARRAY_SIZE(_clnames) > 0, \ + "classnames array size must be > 0"); \ + static_assert((ARRAY_SIZE(_clnames) + (_base)) < _DPRINTK_CLASS_DFLT, \ + "_base + classnames.length exceeds range") + /** * DYNAMIC_DEBUG_CLASSMAP_DEFINE - define debug classes used by a module. * @_var: name of the classmap, exported for other modules coordinated use. @@ -194,6 +202,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)); \ extern struct _ddebug_class_map _var; \ struct _ddebug_class_map __aligned(8) __used \ __section("__dyndbg_class_maps") _var = { \ diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c index 1ba4be9a403a..b2bdfdfb6ba1 100644 --- a/lib/test_dynamic_debug.c +++ b/lib/test_dynamic_debug.c @@ -133,7 +133,7 @@ DYNAMIC_DEBUG_CLASSMAP_PARAM(level_num, p); * Enable with -Dflag on compile to test overlapping class-id range * detection. This should warn on modprobes. */ -DYNDBG_CLASSMAP_DEFINE(classid_range_conflict, 0, D2_CORE + 1, "D3_CORE"); +DYNAMIC_DEBUG_CLASSMAP_DEFINE(classid_range_conflict, 0, D2_CORE + 1, "D3_CORE"); #endif #else /* TEST_DYNAMIC_DEBUG_SUBMOD */ @@ -146,8 +146,19 @@ DYNDBG_CLASSMAP_DEFINE(classid_range_conflict, 0, D2_CORE + 1, "D3_CORE"); DYNAMIC_DEBUG_CLASSMAP_USE(map_disjoint_bits); DYNAMIC_DEBUG_CLASSMAP_USE(map_level_num); +#if defined(DD_MACRO_ARGCHECK) +/* + * 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 */); #endif +#endif /* TEST_DYNAMIC_DEBUG_SUBMOD */ + /* stand-in for all pr_debug etc */ #define prdbg(SYM) __pr_debug_cls(SYM, #SYM " msg\n") -- 2.53.0