From nobody Tue Dec 2 02:41:31 2025 Received: from mail-io1-f53.google.com (mail-io1-f53.google.com [209.85.166.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF50F2F83BB for ; Tue, 18 Nov 2025 20:19:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763497170; cv=none; b=C2oeEdY7xEHGbfL4Z/q/X+FWsOqWv2RN2t5KO1vJP7cAhK/ApetqzZupqK7bThcCo6OUZhbUiB0EzVUCsg0Ds7gqHkxYLb2HPJDbQ7ajrS1UBPRPfSoKn4t/AVfKm2xDhVKDuXgvCvP4ROBl1SASVpJT+8gBTBIE4UCtEOj5sXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763497170; c=relaxed/simple; bh=4gcGRgva0eLSrFJr6GtR+Nl4ilJG9ulEI9xGeh4rDlk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qnpTLSNrKLbShE7FstZtUAgthggh1R0sIXpux7VeBVKn+szVJx6C3vuPdBYvoN9FUnNF5u0NqnChcZtYMJJ8vj5q6GhN4rd8R7mu86Y/MyIpbB9L8pbyxzVVBrU/mF1fexE8nv3gdSJ+C5fGNowj7Fks+Ur0JE+enrO4Zf7IaeQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hTdACzOn; arc=none smtp.client-ip=209.85.166.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hTdACzOn" Received: by mail-io1-f53.google.com with SMTP id ca18e2360f4ac-949022f1c85so136898139f.0 for ; Tue, 18 Nov 2025 12:19:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763497166; x=1764101966; darn=vger.kernel.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=jMXBzIIRyoXzNJBSl4ah2NOKF+5LtDRbEmDzwpRMTZI=; b=hTdACzOniP43qUnmcxYcMxd4Vyu5t0pH9Jj9oc5VzhdZzcnP+tFkl0NO3l6I4ryiFb 2M4ePl3ry9D1Md7lbH9mj5bf7ByH8K+tAdLK35mOdiXH1zsFMNfZq9of6QxWBk28Ab8X MFeUMfhhLKal95Ph+eWZjKCcQEJhP4dX/qIZ67p7YMp1F9ynOO7mDnnDsqso1Pmc55Q/ IPzBkyo52xno60IBnIR1EH9c6YjrT8qGFXgKjK+xsi2GxkWL9a+Y5KNT2LuVt1BlyFZ4 R2ptW9DWlPC3k9GLpd0zbOfTLaopi94BzYba2XUEIxy2iiG0Ts/F0j5M+OKTAZdq/L5/ RH8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763497166; x=1764101966; 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=jMXBzIIRyoXzNJBSl4ah2NOKF+5LtDRbEmDzwpRMTZI=; b=XnC+XdPskE0Lptw2RJuDopao6hXWHRsCOf7m+FZyCoQzSaZKBB2M/BWTa8CP05nceV ft7nMyUBvgLeQ1+k6F7AEV9sfnTi34Mr6dSXGjAzx6/yNrX8TzpyCJ4QBGm7QEFwOVEz 51sbJPmBUf+JVhIXt7DNpfhpxYsUZ+izcbu38eYVe7M2aVo8xqZgNY49aj8Oa/ohXdcE fXS2cbYdhEgpMXjJ2L0zRSxk51b41aUENBQTPTzJkpBggMwOgSbPvjH+jXYR08RWZRWy 908xY+BySW13SojDmz7rSuzp/8NM4nNkWwJsHpXrGCePPMFz+B9TFEWK+6TyL5diLyGH fxSw== X-Gm-Message-State: AOJu0YxXBn2iAEKwTtS/m7H92PmLQngwPmesNrm/OFE/w5ih93JKmlg0 sVcFvILYCLkTkTfo8U442QBF7R7maqtw80r6O8JcauMEgeisAGugq+OOQKeIvemh X-Gm-Gg: ASbGncuGjvz/e/jQlJjEv6Y6xF+0wyVGW+uFXMILsKm1wJ0Mog3m5lrx1RVUwtrX1Ib wFtJqhBJ6hmOS/GRjYpuuS2lCaAYWB7ldeqhohoI8h2AbeUYSsp/HPSMpsRE/SKea6K17sp+/hH Fo1uM7W7OP3tt9l1FS3KE0z3Tyjz1vTK5YAP8DLRlc7q5IR06eiPRP2GeJofj2CIQc8foZ0sXpx B7pToYXvra7ByuRtBNn4EX6BVbkz79F07quWHrb6eazZZ4vAgo30JAy3EE0Bq74l/J/sTkmjcg0 rZfYojoJ2s5kwXeif/ZJgflOMUB+iF6hdFgJsg3p08beWnr8cjs4MeX40JM44EyvJV3WkgkaMMs BswM9TO0Q+INtLYyfVSLB8gD5h1jYGsQFtvrJa1UlkAZijnvO1ARhBbSCClmOIIeF7aAQ4DrDcd SB3MB5zV8FQGmBurMmd67GjVEVpms8rlZ9JSm/PD9Hac1zwQBvbPlL7J6psFW39e94DeY= X-Google-Smtp-Source: AGHT+IFOUykA39ngbL/gi4rSkDM2Dh8wgirVlMpJOQAuJ/4iYCBDDhEoAW+I/UmChihR1kpRWQW33g== X-Received: by 2002:a05:6602:2c06:b0:948:cbd2:3b84 with SMTP id ca18e2360f4ac-948e0d87a37mr1874742539f.11.1763497166224; Tue, 18 Nov 2025 12:19:26 -0800 (PST) Received: from godzilla.raven-morpho.ts.net (c-98-38-17-99.hsd1.co.comcast.net. [98.38.17.99]) by smtp.googlemail.com with ESMTPSA id ca18e2360f4ac-948fd4c273bsm419823939f.18.2025.11.18.12.19.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Nov 2025 12:19:25 -0800 (PST) From: Jim Cromie To: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, gregkh@linuxfoundation.org, jbaron@akamai.com Cc: ukaszb@chromium.org, louis.chauvet@bootlin.com, Jim Cromie Subject: [PATCH v6 23/31] dyndbg: check DYNAMIC_DEBUG_CLASSMAP_DEFINE args at compile-time Date: Tue, 18 Nov 2025 13:18:33 -0700 Message-ID: <20251118201842.1447666-24-jim.cromie@gmail.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251118201842.1447666-1-jim.cromie@gmail.com> References: <20251118201842.1447666-1-jim.cromie@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add __DYNAMIC_DEBUG_CLASSMAP_CHECK to implement the following arg-checks at compile-time: 0 <=3D _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 --- these checkpatch "reuse" issues are on lvalues, irrelevant. CHECK: Macro argument reuse '_clnames' - possible side-effects? CHECK: Macro argument reuse '_base' - possible side-effects? v4- deconflict after pulling macro-stubs forward v3- $macro_name =3D~ s/DYNDBG/DYNAMIC_DEBUG/ prev- - split static-asserts to __DYNDBG_CLASSMAP_CHECK - move __DYNDBG_CLASSMAP_CHECK above kdoc for DYNDBG_CLASSMAP_DEFINE silences kernel-doc warnings --- 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 905db0b49104..b19c9b1d53b6 100644 --- a/include/linux/dynamic_debug.h +++ b/include/linux/dynamic_debug.h @@ -180,6 +180,14 @@ struct _ddebug_class_param { * __pr_debug_cls(22, "no such class"); compiles but is not reachable */ =20 +#define __DYNAMIC_DEBUG_CLASSMAP_CHECK(_clnames, _base) \ + static_assert(((_base) >=3D 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 u= se. @@ -193,6 +201,7 @@ struct _ddebug_class_param { */ #define DYNAMIC_DEBUG_CLASSMAP_DEFINE(_var, _mapty, _base, ...) \ static const char *_var##_classnames[] =3D { __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 =3D { \ 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 =20 #else /* TEST_DYNAMIC_DEBUG_SUBMOD */ @@ -146,8 +146,19 @@ DYNDBG_CLASSMAP_DEFINE(classid_range_conflict, 0, D2_C= ORE + 1, "D3_CORE"); DYNAMIC_DEBUG_CLASSMAP_USE(map_disjoint_bits); DYNAMIC_DEBUG_CLASSMAP_USE(map_level_num); =20 +#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 =20 +#endif /* TEST_DYNAMIC_DEBUG_SUBMOD */ + /* stand-in for all pr_debug etc */ #define prdbg(SYM) __pr_debug_cls(SYM, #SYM " msg\n") =20 --=20 2.51.1