From patchwork Mon Mar 16 12:51:00 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: 6018601 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E5405BF90F for ; Mon, 16 Mar 2015 12:51:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 208B120426 for ; Mon, 16 Mar 2015 12:51:03 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 35496203F7 for ; Mon, 16 Mar 2015 12:51:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A83456E551; Mon, 16 Mar 2015 05:51:01 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by gabe.freedesktop.org (Postfix) with ESMTP id 3BAAC6E54F for ; Mon, 16 Mar 2015 05:51:00 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP; 16 Mar 2015 05:47:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,409,1422950400"; d="scan'208";a="699321020" Received: from linux.intel.com ([10.23.219.25]) by orsmga002.jf.intel.com with ESMTP; 16 Mar 2015 05:50:59 -0700 Received: from localhost (aconselv-mobl3.fi.intel.com [10.237.72.55]) by linux.intel.com (Postfix) with ESMTP id AC9056A408F; Mon, 16 Mar 2015 05:50:41 -0700 (PDT) From: Ander Conselvan de Oliveira To: intel-gfx@lists.freedesktop.org Date: Mon, 16 Mar 2015 14:51:00 +0200 Message-Id: <1426510260-19251-1-git-send-email-ander.conselvan.de.oliveira@intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <20150316104218.GA27819@nuc-i3427.alporthouse.com> References: <20150316104218.GA27819@nuc-i3427.alporthouse.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. v2: Don't break 'if (foo) for_each_*' usage. (Jani & Chris) 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 | 63 ++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index ae4ba6a..55fc10d 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -232,30 +232,47 @@ enum hpd_pin { (__s) < INTEL_INFO(__dev_priv)->num_sprites[(__p)]; \ (__s)++) -#define for_each_crtc(dev, 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_encoder(dev, intel_encoder) \ - list_for_each_entry(intel_encoder, \ - &(dev)->mode_config.encoder_list, \ - base.head) - -#define for_each_intel_connector(dev, intel_connector) \ - list_for_each_entry(intel_connector, \ - &dev->mode_config.connector_list, \ - base.head) +#define __list_for_each_entry_type(pos, head, type, member) \ + for (pos = list_first_entry(head, type, member); \ + &pos->member != (head); \ + pos = list_next_entry(pos, member)) - -#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_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_crtc(dev, crtc) \ + __list_for_each_entry_type(crtc, \ + &dev->mode_config.crtc_list, \ + struct drm_crtc, \ + head) + +#define for_each_intel_crtc(dev, crtc) \ + __list_for_each_entry_type(crtc, \ + &dev->mode_config.crtc_list, \ + struct intel_crtc, base.head) + +#define for_each_intel_encoder(dev, encoder) \ + __list_for_each_entry_type(encoder, \ + &(dev)->mode_config.encoder_list, \ + struct intel_encoder, \ + base.head) + +#define for_each_intel_connector(dev, connector) \ + __list_for_each_entry_type(connector, \ + &dev->mode_config.connector_list, \ + struct intel_connector, \ + base.head) + + +#define for_each_encoder_on_crtc(dev, __crtc, encoder) \ + __list_for_each_entry_type((encoder), \ + &(dev)->mode_config.encoder_list,\ + struct intel_encoder, base.head) \ + if ((encoder)->base.crtc == (__crtc)) + +#define for_each_connector_on_encoder(dev, __encoder, connector) \ + __list_for_each_entry_type((connector), \ + &(dev)->mode_config.connector_list, \ + struct intel_connector, \ + base.head) \ + if ((connector)->base.encoder == (__encoder)) #define for_each_power_domain(domain, mask) \ for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \