From patchwork Tue Dec 13 20:32:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Auld X-Patchwork-Id: 9473185 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1C750607EE for ; Tue, 13 Dec 2016 20:32:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F008C28579 for ; Tue, 13 Dec 2016 20:32:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E4E5F28585; Tue, 13 Dec 2016 20:32:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 62CA728579 for ; Tue, 13 Dec 2016 20:32:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 18BA66E666; Tue, 13 Dec 2016 20:32:39 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 97C3A6E664 for ; Tue, 13 Dec 2016 20:32:27 +0000 (UTC) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP; 13 Dec 2016 12:32:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.33,342,1477983600"; d="scan'208"; a="1081405893" Received: from idodin-mobl.ger.corp.intel.com (HELO mwahaha.ger.corp.intel.com) ([10.252.20.12]) by fmsmga001.fm.intel.com with ESMTP; 13 Dec 2016 12:32:26 -0800 From: Matthew Auld To: intel-gfx@lists.freedesktop.org Date: Tue, 13 Dec 2016 20:32:21 +0000 Message-Id: <20161213203222.32564-3-matthew.auld@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161213203222.32564-1-matthew.auld@intel.com> References: <20161213203222.32564-1-matthew.auld@intel.com> Subject: [Intel-gfx] [PATCH 3/4] drm/i915: introduce range_overflows utility macros 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-Virus-Scanned: ClamAV using ClamSMTP In a number places we hand-roll the overflow sanity check for ranges, so roll that into single macro, conceived by Chris, along with its typed variant. Cc: Joonas Lahtinen Cc: Chris Wilson Suggested-by: Chris Wilson Signed-off-by: Matthew Auld --- drivers/gpu/drm/i915/i915_drv.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 20bc04d5e617..47b5a9f1c9ed 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -218,6 +218,18 @@ static inline const char *enableddisabled(bool v) return v ? "enabled" : "disabled"; } +#define range_overflows(start, size, max) ({ \ + typeof(start) start__ = (start); \ + typeof(size) size__ = (size); \ + typeof(max) max__ = (max); \ + (void)(&start__ == &size__); \ + (void)(&start__ == &max__); \ + start > max || size > max - start; \ +}) + +#define range_overflows_t(type, start, size, max) \ + range_overflows(((type)start), ((type)size), ((type)max)) + enum pipe { INVALID_PIPE = -1, PIPE_A = 0,