From patchwork Mon Mar 16 07:21:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ander Conselvan de Oliveira X-Patchwork-Id: 6015771 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 080BC9F314 for ; Mon, 16 Mar 2015 07:21:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 234AA202F8 for ; Mon, 16 Mar 2015 07:21:25 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 1A6B1201B4 for ; Mon, 16 Mar 2015 07:21:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AFBF56E13C; Mon, 16 Mar 2015 00:21:23 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTP id DE4816E13C for ; Mon, 16 Mar 2015 00:21:22 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP; 16 Mar 2015 00:21:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,407,1422950400"; d="scan'208";a="541396095" Received: from linux.intel.com ([10.23.219.25]) by orsmga003.jf.intel.com with ESMTP; 16 Mar 2015 00:20:23 -0700 Received: from localhost (unknown [10.237.72.55]) by linux.intel.com (Postfix) with ESMTP id CFC796A408F; Mon, 16 Mar 2015 00:21:04 -0700 (PDT) From: Ander Conselvan de Oliveira To: intel-gfx@lists.freedesktop.org Date: Mon, 16 Mar 2015 09:21:23 +0200 Message-Id: <1426490483-28312-1-git-send-email-ander.conselvan.de.oliveira@intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1426490381.3286.4.camel@gmail.com> References: <1426490381.3286.4.camel@gmail.com> Cc: Ander Conselvan de Oliveira , rodrigo.vivi@intel.com Subject: [Intel-gfx] [PATCH] drm/i915: Make for_each_intel_* macros typesafe X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP So that the compiler warns if we get something wrong. Signed-off-by: Ander Conselvan de Oliveira Tested-By: PRC QA PRTS (Patch Regression Test System Contact: shuang.he@intel.com) --- drivers/gpu/drm/i915/i915_drv.h | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index ae4ba6a..871d77a 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -232,30 +232,43 @@ enum hpd_pin { (__s) < INTEL_INFO(__dev_priv)->num_sprites[(__p)]; \ (__s)++) -#define for_each_crtc(dev, crtc) \ +#define type_check(variable, type) \ + { \ + typeof(variable) __dummy_ptr = NULL; \ + const type *__type_check = __dummy_ptr; \ + (void) __type_check; \ + } + +#define for_each_crtc(dev, crtc) \ + type_check(crtc, struct drm_crtc) \ list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) -#define for_each_intel_crtc(dev, intel_crtc) \ - list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list, base.head) +#define for_each_intel_crtc(dev, crtc) \ + type_check(crtc, struct intel_crtc) \ + list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) -#define for_each_intel_encoder(dev, intel_encoder) \ - list_for_each_entry(intel_encoder, \ +#define for_each_intel_encoder(dev, encoder) \ + type_check(encoder, struct intel_encoder) \ + list_for_each_entry(encoder, \ &(dev)->mode_config.encoder_list, \ base.head) -#define for_each_intel_connector(dev, intel_connector) \ - list_for_each_entry(intel_connector, \ +#define for_each_intel_connector(dev, connector) \ + type_check(connector, struct intel_connector); \ + list_for_each_entry(connector, \ &dev->mode_config.connector_list, \ base.head) -#define for_each_encoder_on_crtc(dev, __crtc, intel_encoder) \ - list_for_each_entry((intel_encoder), &(dev)->mode_config.encoder_list, base.head) \ - if ((intel_encoder)->base.crtc == (__crtc)) +#define for_each_encoder_on_crtc(dev, __crtc, encoder) \ + type_check(encoder, struct intel_encoder) \ + list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, base.head) \ + if ((encoder)->base.crtc == (__crtc)) -#define for_each_connector_on_encoder(dev, __encoder, intel_connector) \ - list_for_each_entry((intel_connector), &(dev)->mode_config.connector_list, base.head) \ - if ((intel_connector)->base.encoder == (__encoder)) +#define for_each_connector_on_encoder(dev, __encoder, connector) \ + type_check(connector, struct intel_connector) \ + list_for_each_entry((connector), &(dev)->mode_config.connector_list, base.head) \ + if ((connector)->base.encoder == (__encoder)) #define for_each_power_domain(domain, mask) \ for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \