Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3477128rwb; Tue, 16 Aug 2022 03:55:10 -0700 (PDT) X-Google-Smtp-Source: AA6agR7sc+oop/0FDDBWtOFwz9OvySjKldRpd8xFg0sZUuyLc0EUjzIzPU76d78d1egw2h9drHxL X-Received: by 2002:a05:6a00:2a05:b0:52e:6c05:9b84 with SMTP id ce5-20020a056a002a0500b0052e6c059b84mr19998188pfb.77.1660647310314; Tue, 16 Aug 2022 03:55:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660647310; cv=none; d=google.com; s=arc-20160816; b=BMPBz6I3PVvxKLkIZGNbwvATReuFACjXPNQoEUIJ79yK3UH/pqzzeIviiPUMWHICbq eIsLMkGDn3CBZBgar/Qq2B3T6hxO2ske4+NhB1niu8WRUSMzptFxIbR/8jT2o1cYfQFX +MIOtB1UOfc7BlEq4tU1gThP1lJwP0TU+PdGjRxC1/NW6C7+8SnD61jwuYLH2+rZj4Fc q8/wFf50HNIH20FzGM3StqzyLgDKy2Et7Zmi+IeBK+jmkr2nkU0fl+7rpHaT03sAjNpy e1hDq9s7j7T3HaqKWOre6yjJX+WHcFHL2regj82wCWlwGSgywb4JeKMgjEnuHnXts56/ azpw== 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=mrxRduehxIejFf1eA0Ts/9VK+co1SgILoxzGRTAe05Dx+ENXzcwH2IMHgi3mFpsLcn SoutPB4cBYoD9Is+aUKWpnW9PkSQiqR6Ec85rpBoCEG2qBeRVVtozP78Pmi6Twme+Or/ n5mZ3ZeCzvuEJW7eKDrZuLKHEme4xCMK69E0l0f9zG4u6iWNHCiGf8ChzOwXZxP5CXss w0waGSyLXMEVeQsaOe/YfNt99eq2r08unmSk8/O6ByPm1U+D/rTtD7qRRd9lR2B5zTNM WRVM0KNF9FA8kdRg9np+hgNGv4VklmX1ZMLEsfWGCCIDFrZRSBXmx5nKi1IWvs41ViFM qDBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GHH4tuyl; 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 cw1-20020a056a00450100b0051b904d9c7csi11680108pfb.251.2022.08.16.03.54.58; Tue, 16 Aug 2022 03:55:10 -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=GHH4tuyl; 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 S233841AbiHPKO7 (ORCPT + 99 others); Tue, 16 Aug 2022 06:14:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233420AbiHPKOO (ORCPT ); Tue, 16 Aug 2022 06:14:14 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92728C2FB5 for ; Tue, 16 Aug 2022 02:37:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660642664; x=1692178664; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uWNiR7M8bUT4JAhynBPIOlI6cvuOcXNpkpD1siwzhag=; b=GHH4tuylbYFEXlTJzhmOUai+ijQGV0iopxr2/T8WQ+in/ZNupGbx7jAQ XcEPx3deGUDqicIz+16CGM/qdieBwD61/7NLKjFUzBZFe9cp84Jjhu9Cu jRTdUAvkX6nOLIOYag/2COMMjsRa3MsaBSlB6HTZRFu3QNuraFwnZQBC4 45a0W/1Xkma69F1RgHY7wUgm//mibBujsI0Z+Rh1GB8kxIz4Ci1zQxSXe aRRtxoenF4uQUR6ldBK4zvIheczIWZJ3cLwraAAc06ZJoHSYJD9ihlDrA VizPjLRXQuw8lM5CURA8goVYm/LcXN4ET71EZY+cZswWgXPmo5tyiyaLJ w==; X-IronPort-AV: E=McAfee;i="6400,9594,10440"; a="293446805" X-IronPort-AV: E=Sophos;i="5.93,240,1654585200"; d="scan'208";a="293446805" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2022 02:35:49 -0700 X-IronPort-AV: E=Sophos;i="5.93,240,1654585200"; d="scan'208";a="733231037" Received: from clbarnes-mobl.amr.corp.intel.com (HELO paris.amr.corp.intel.com) ([10.254.7.166]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2022 02:35:46 -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 Subject: [PATCH v7 2/8] util_macros: Add exact_type macro to catch type mis-match while compiling Date: Tue, 16 Aug 2022 18:35:19 +0900 Message-Id: <20220816093525.184940-3-gwan-gyeong.mun@intel.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220816093525.184940-1-gwan-gyeong.mun@intel.com> References: <20220816093525.184940-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