Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3697564rwa; Tue, 23 Aug 2022 08:40:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR4mK4lyxCk4SgrTSTuZnRfD++NIXxL1SWZVg3tUXzRPWI3mVsreWzC4/ovgCBgJt8AfMWDu X-Received: by 2002:a17:90a:4e07:b0:1fb:1253:475b with SMTP id n7-20020a17090a4e0700b001fb1253475bmr3874830pjh.0.1661269225799; Tue, 23 Aug 2022 08:40:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661269225; cv=none; d=google.com; s=arc-20160816; b=zSJIkrVVtixwyNLP9vrMKsXhTrLfnikdIYBu040xp+XhwpjpH5dXKlsYuBdFbZN+7c Af8TXMi5ThB/o7mugGGC9m2oUQY56NB9g7D/l0++O5ixEyeXQV3nl1rd7IvfS3xwh3VR AueUm0xsZ4FiyjRmf2chrDOND8jroyUkm8CO4HAd66g8EVwAgj3XQFQA4II1ZfRAmreU yF8sMQWvYnnBIeWlJBctmSNlZt2dAgLCr46wgFTvOj21RHGyBFJCGM0EBEUQ1TSfiHyy vaibP0F/qzm1oYJsBbYuLRpqkCw0zxbK0cDVa9IorM03DJxAnOVYRreCLaofu0CR8EeC 9WzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=abXwhZITsL9/cxl/WZ6hj4O+QHJl3Tns5O9rm+km7sY=; b=S9tUzdjDY9VXZs+/pBqdLxPf87l19PbP0FsE6Mf7hzvLqf4CYAoefCl23YGkm3/dSz JctKF4dWeKnE0NioAo/MqbV0s617fqEIP1SZnPm/pLYXe9vpKTJS4As8ojNhF5249vIl ktyBrTyw7YH3nfPb2AUkzSA/d7YHO0wfyhkV/qSgFAztT8HuE19pSVSF1zN4V1MQcBhg d5gDGUhQqLpTn/gKUyMBJNMJ2Anv+Gc3wODnhWY4bv8NkpCzkKAV5YrYLoHaMBV+J9RD dJk4c2BIxDCYQvNVDMYJD1OdFyOu5yQ1VGg63mDZfRYF/JP2soy3oqnnJPzUo2G78dJj 17BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UY8Rh9Bv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 189-20020a6302c6000000b0042a5e9b8da7si11701069pgc.626.2022.08.23.08.40.14; Tue, 23 Aug 2022 08:40:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UY8Rh9Bv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243565AbiHWPLU (ORCPT + 99 others); Tue, 23 Aug 2022 11:11:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244086AbiHWPKi (ORCPT ); Tue, 23 Aug 2022 11:10:38 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A975B144109 for ; Tue, 23 Aug 2022 03:20:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661250012; x=1692786012; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uWNiR7M8bUT4JAhynBPIOlI6cvuOcXNpkpD1siwzhag=; b=UY8Rh9BvNl41ByXZAg0XQE/sU62z+E+uS0L1aTp7x4S9KSbt6M2AAx3a rozBcz0eJdxu1q51Aa4wthmL3Nz7wxqLchCQQebm497fBEfQ2IiuNesMv RwI7FJJgcjdLg8xr+kETv4IvQdmGb57UexquiGt67HgJbaHOPo68zlFLE p+4kA+PJr89jG5AocGDUT0asQIZMu4qslI4rMfZMZHZjsbIiUFpVjXgH8 Oy4a2atNomHwCFXuYxSgSUTdCiENCd/37q+174udwdeyB1clslhe/fL1f uBdi379tE1B2SiZ1x39vOTJmwEUuIq6XP/a8r/CWXMZlEdFD5j0HZKYoK w==; X-IronPort-AV: E=McAfee;i="6500,9779,10447"; a="357627038" X-IronPort-AV: E=Sophos;i="5.93,257,1654585200"; d="scan'208";a="357627038" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2022 03:17:57 -0700 X-IronPort-AV: E=Sophos;i="5.93,257,1654585200"; d="scan'208";a="751639913" Received: from jabish-mobl2.amr.corp.intel.com (HELO paris.amr.corp.intel.com) ([10.254.9.209]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2022 03:17:52 -0700 From: Gwan-gyeong Mun To: intel-gfx@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, mchehab@kernel.org, chris@chris-wilson.co.uk, matthew.auld@intel.com, thomas.hellstrom@linux.intel.com, jani.nikula@intel.com, nirmoy.das@intel.com, airlied@linux.ie, daniel@ffwll.ch, andi.shyti@linux.intel.com, andrzej.hajda@intel.com, keescook@chromium.org, mauro.chehab@linux.intel.com, intel-gfx-trybot@lists.freedesktop.org Subject: [PATCH v8 2/8] util_macros: Add exact_type macro to catch type mis-match while compiling Date: Tue, 23 Aug 2022 19:17:23 +0900 Message-Id: <20220823101729.2098841-3-gwan-gyeong.mun@intel.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220823101729.2098841-1-gwan-gyeong.mun@intel.com> References: <20220823101729.2098841-1-gwan-gyeong.mun@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It adds exact_type and exactly_pgoff_t macro to catch type mis-match while compiling. The existing typecheck() macro outputs build warnings, but the newly added exact_type() macro uses the BUILD_BUG_ON() macro to generate a build break when the types are different and can be used to detect explicit build errors. v6: Move macro addition location so that it can be used by other than drm subsystem (Jani, Mauro, Andi) Signed-off-by: Gwan-gyeong Mun Cc: Thomas Hellström Cc: Matthew Auld Cc: Nirmoy Das Cc: Jani Nikula Cc: Andi Shyti Cc: Mauro Carvalho Chehab --- include/linux/util_macros.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/linux/util_macros.h b/include/linux/util_macros.h index 72299f261b25..b6624b275257 100644 --- a/include/linux/util_macros.h +++ b/include/linux/util_macros.h @@ -2,6 +2,9 @@ #ifndef _LINUX_HELPER_MACROS_H_ #define _LINUX_HELPER_MACROS_H_ +#include +#include + #define __find_closest(x, a, as, op) \ ({ \ typeof(as) __fc_i, __fc_as = (as) - 1; \ @@ -38,4 +41,26 @@ */ #define find_closest_descending(x, a, as) __find_closest(x, a, as, >=) +/** + * exact_type - break compile if source type and destination value's type are + * not the same + * @T: Source type + * @n: Destination value + * + * It is a helper macro for a poor man's -Wconversion: only allow variables of + * an exact type. It determines whether the source type and destination value's + * type are the same while compiling, and it breaks compile if two types are + * not the same + */ +#define exact_type(T, n) \ + BUILD_BUG_ON(!__builtin_constant_p(n) && !__builtin_types_compatible_p(T, typeof(n))) + +/** + * exactly_pgoff_t - helper to check if the type of a value is pgoff_t + * @n: value to compare pgoff_t type + * + * It breaks compile if the argument value's type is not pgoff_t type. + */ +#define exactly_pgoff_t(n) exact_type(pgoff_t, n) + #endif -- 2.37.1