From patchwork Fri Oct 23 22:27:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Wunner X-Patchwork-Id: 7482631 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 463179F399 for ; Sun, 25 Oct 2015 14:01:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 54602206F1 for ; Sun, 25 Oct 2015 14:01:48 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 63E2220699 for ; Sun, 25 Oct 2015 14:01:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D10676E2A1; Sun, 25 Oct 2015 07:01:46 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mailout3.hostsharing.net (mailout3.hostsharing.net [176.9.242.54]) by gabe.freedesktop.org (Postfix) with ESMTPS id A77806E2A1 for ; Sun, 25 Oct 2015 07:01:44 -0700 (PDT) Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mailout3.hostsharing.net (Postfix) with ESMTPS id 1310C10342DC9; Sun, 25 Oct 2015 15:01:43 +0100 (CET) Received: from localhost (6-38-90-81.adsl.cmo.de [81.90.38.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by h08.hostsharing.net (Postfix) with ESMTPSA id 6E5B1605E00B; Sun, 25 Oct 2015 15:01:41 +0100 (CET) X-Mailbox-Line: From e08c113c04191ecd66904423da4f1908f48b5ef6 Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: References: <20151015173423.GK26517@intel.com> From: Lukas Wunner Date: Sat, 24 Oct 2015 00:27:57 +0200 To: intel-gfx@lists.freedesktop.org Subject: [Intel-gfx] [PATCH v6 4/4] drm/i915: Fix error handling in intelfb_create 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=-2.9 required=5.0 tests=BAYES_00, DATE_IN_PAST_24_48, RCVD_IN_DNSWL_MED, 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 intelfb_create() is called once on driver initialization. It either uses the fb inherited from BIOS or allocates a new one by calling intelfb_alloc(). Afterwards, it calls two functions which can fail: - drm_fb_helper_alloc_fbi() can fail with -ENOMEM. - ioremap_wc() can fail on alignment issues etc. In the case where we allocated the fb with intelfb_alloc(), if either of the two functions fail we currently unpin and unref the bo, but leak the fb. We need to unref the fb instead of the bo here. In the case where the fb was inherited from BIOS, the fb struct was allocated by dev_priv->display.get_initial_plane_config() and is in active use by a crtc, so it seems wrong to unpin and unref its bo. We could treat failure of the above two functions as a fatal error and call i915_driver_unload(), or try to limp on (fbcon won't work, but X11 might). Let's do the latter. However we should at least log an error message. Currently a failure of the above two functions is not reported at all: The negative return value is passed up the call stack to intel_fbdev_initial_config() which ignores it. To be fair, this is a corner case which few users probably ever experience, nevertheless we should try to get it right. Signed-off-by: Lukas Wunner --- drivers/gpu/drm/i915/intel_fbdev.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_fbdev.c b/drivers/gpu/drm/i915/intel_fbdev.c index 12597b5..b8c11a1 100644 --- a/drivers/gpu/drm/i915/intel_fbdev.c +++ b/drivers/gpu/drm/i915/intel_fbdev.c @@ -227,6 +227,7 @@ static int intelfb_create(struct drm_fb_helper *helper, info = drm_fb_helper_alloc_fbi(helper); if (IS_ERR(info)) { + DRM_ERROR("Failed to allocate fb_info\n"); ret = PTR_ERR(info); goto out_unpin; } @@ -253,6 +254,7 @@ static int intelfb_create(struct drm_fb_helper *helper, ioremap_wc(dev_priv->gtt.mappable_base + i915_gem_obj_ggtt_offset(obj), size); if (!info->screen_base) { + DRM_ERROR("Failed to remap framebuffer into virtual memory\n"); ret = -ENOSPC; goto out_destroy_fbi; } @@ -284,9 +286,14 @@ static int intelfb_create(struct drm_fb_helper *helper, out_destroy_fbi: drm_fb_helper_release_fbi(helper); out_unpin: - i915_gem_object_ggtt_unpin(obj); - drm_gem_object_unreference(&obj->base); - mutex_unlock(&dev->struct_mutex); + /* If fb was preallocated by BIOS, try to limp on. Else free it. */ + if (prealloc) + mutex_unlock(&dev->struct_mutex); + else { + i915_gem_object_ggtt_unpin(obj); + mutex_unlock(&dev->struct_mutex); + drm_framebuffer_unreference(&intel_fb->base); + } return ret; }