From patchwork Thu Mar 14 14:19:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 10853005 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8C5456C2 for ; Thu, 14 Mar 2019 14:21:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77AA628BCE for ; Thu, 14 Mar 2019 14:21:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6BF362A381; Thu, 14 Mar 2019 14:21:40 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 8FF5C28BBA for ; Thu, 14 Mar 2019 14:21:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B99AF6E2E7; Thu, 14 Mar 2019 14:21:36 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from fireflyinternet.com (mail.fireflyinternet.com [109.228.58.192]) by gabe.freedesktop.org (Postfix) with ESMTPS id 819096E2B5; Thu, 14 Mar 2019 14:21:31 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from haswell.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 15889936-1500050 for multiple; Thu, 14 Mar 2019 14:19:43 +0000 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Thu, 14 Mar 2019 14:19:27 +0000 Message-Id: <20190314141939.26246-13-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190314141939.26246-1-chris@chris-wilson.co.uk> References: <20190314141939.26246-1-chris@chris-wilson.co.uk> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t 13/25] lib/i915: Improve gem_context error messages X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: igt-dev@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Avoid embedding the DRM_IOCTL() macro into the error message as it is unreadable, and instead always wrap the ioctl with a self-descriptive helper. Signed-off-by: Chris Wilson --- lib/i915/gem_context.c | 72 ++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 38 deletions(-) diff --git a/lib/i915/gem_context.c b/lib/i915/gem_context.c index 16004685e..8b4d5b704 100644 --- a/lib/i915/gem_context.c +++ b/lib/i915/gem_context.c @@ -113,16 +113,16 @@ uint32_t gem_context_create(int fd) int __gem_context_destroy(int fd, uint32_t ctx_id) { - struct drm_i915_gem_context_destroy destroy; - int ret; + struct drm_i915_gem_context_destroy destroy = { ctx_id }; + int err = 0; - memset(&destroy, 0, sizeof(destroy)); - destroy.ctx_id = ctx_id; + if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_DESTROY, &destroy)) { + err = -errno; + igt_assume(err); + } - ret = igt_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_DESTROY, &destroy); - if (ret) - return -errno; - return 0; + errno = 0; + return err; } /** @@ -134,21 +134,20 @@ int __gem_context_destroy(int fd, uint32_t ctx_id) */ void gem_context_destroy(int fd, uint32_t ctx_id) { - struct drm_i915_gem_context_destroy destroy; - - memset(&destroy, 0, sizeof(destroy)); - destroy.ctx_id = ctx_id; - - do_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_DESTROY, &destroy); + igt_assert_eq(__gem_context_destroy(fd, ctx_id), 0); } int __gem_context_get_param(int fd, struct drm_i915_gem_context_param *p) { - if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, p)) - return -errno; + int err = 0; + + if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, p)) { + err = -errno; + igt_assume(err); + } errno = 0; - return 0; + return err; } /** @@ -161,18 +160,22 @@ int __gem_context_get_param(int fd, struct drm_i915_gem_context_param *p) */ void gem_context_get_param(int fd, struct drm_i915_gem_context_param *p) { - igt_assert(__gem_context_get_param(fd, p) == 0); + igt_assert_eq(__gem_context_get_param(fd, p), 0); } - int __gem_context_set_param(int fd, struct drm_i915_gem_context_param *p) { - if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, p)) - return -errno; + int err = 0; + + if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, p)) { + err = -errno; + igt_assume(err); + } errno = 0; - return 0; + return err; } + /** * gem_context_set_param: * @fd: open i915 drm file descriptor @@ -183,7 +186,7 @@ int __gem_context_set_param(int fd, struct drm_i915_gem_context_param *p) */ void gem_context_set_param(int fd, struct drm_i915_gem_context_param *p) { - igt_assert(__gem_context_set_param(fd, p) == 0); + igt_assert_eq(__gem_context_set_param(fd, p), 0); } /** @@ -196,14 +199,9 @@ void gem_context_set_param(int fd, struct drm_i915_gem_context_param *p) */ void gem_context_require_param(int fd, uint64_t param) { - struct drm_i915_gem_context_param p; - - p.ctx_id = 0; - p.param = param; - p.value = 0; - p.size = 0; + struct drm_i915_gem_context_param p = { .param = param }; - igt_require(igt_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p) == 0); + igt_require(__gem_context_get_param(fd, &p) == 0); } void gem_context_require_bannable(int fd) @@ -252,13 +250,11 @@ void gem_context_require_bannable(int fd) */ int __gem_context_set_priority(int fd, uint32_t ctx_id, int prio) { - struct drm_i915_gem_context_param p; - - memset(&p, 0, sizeof(p)); - p.ctx_id = ctx_id; - p.size = 0; - p.param = DRM_I915_CONTEXT_PARAM_PRIORITY; - p.value = prio; + struct drm_i915_gem_context_param p = { + .ctx_id = ctx_id, + .param = DRM_I915_CONTEXT_PARAM_PRIORITY, + .value = prio, + }; return __gem_context_set_param(fd, &p); } @@ -273,5 +269,5 @@ int __gem_context_set_priority(int fd, uint32_t ctx_id, int prio) */ void gem_context_set_priority(int fd, uint32_t ctx_id, int prio) { - igt_assert(__gem_context_set_priority(fd, ctx_id, prio) == 0); + igt_assert_eq(__gem_context_set_priority(fd, ctx_id, prio), 0); }