From patchwork Thu May 12 15:28:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Imre Deak X-Patchwork-Id: 9083101 Return-Path: X-Original-To: patchwork-dri-devel@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 C8BB49F1C1 for ; Thu, 12 May 2016 15:28:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 680692024F for ; Thu, 12 May 2016 15:28:35 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 8728620222 for ; Thu, 12 May 2016 15:28:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 83B9B6E8EC; Thu, 12 May 2016 15:28:31 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTP id 904256E8EC for ; Thu, 12 May 2016 15:28:29 +0000 (UTC) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP; 12 May 2016 08:28:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,610,1455004800"; d="scan'208";a="978462613" Received: from wjryan-mobl1.ger.corp.intel.com (HELO ideak-mobl.ger.corp.intel.com) ([10.252.29.70]) by fmsmga002.fm.intel.com with ESMTP; 12 May 2016 08:28:17 -0700 From: Imre Deak To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 1/3] drm: Tune up error message for incorrect plane/format combinations Date: Thu, 12 May 2016 18:28:16 +0300 Message-Id: <1463066896-21104-1-git-send-email-imre.deak@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1463058040-31828-2-git-send-email-imre.deak@intel.com> References: <1463058040-31828-2-git-send-email-imre.deak@intel.com> MIME-Version: 1.0 Cc: Dave Airlie , Daniel Vetter X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00, 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 Returning 0 from these functions isn't ever valid. In many cases it can also lead to a div-by-zero possibly at some later point in time, so make sure we catch such errors as soon as possible via louder error reporting. v2: - Print the same WARN whenever we check for the same condition (Ville) - Don't change drm_fb_get_bpp_depth(), for non-RGB formats we return bpp=0, depth=0 normally. (Ville, Daniel) CC: Dave Airlie CC: Ville Syrjälä CC: Daniel Vetter Signed-off-by: Imre Deak --- drivers/gpu/drm/drm_crtc.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 70f9c68..990a9de 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -5544,6 +5544,13 @@ int drm_mode_destroy_dumb_ioctl(struct drm_device *dev, return dev->driver->dumb_destroy(file_priv, dev, args->handle); } +static bool check_format_plane_valid(uint32_t format, int plane) +{ + return !WARN(plane >= drm_format_num_planes(format), + "invalid plane %d for format %s\n", + plane, drm_get_format_name(format)); +} + /** * drm_fb_get_bpp_depth - get the bpp/depth values for format * @format: pixel format (DRM_FORMAT_*) @@ -5666,7 +5673,7 @@ int drm_format_plane_cpp(uint32_t format, int plane) unsigned int depth; int bpp; - if (plane >= drm_format_num_planes(format)) + if (!check_format_plane_valid(format, plane)) return 0; switch (format) { @@ -5771,7 +5778,7 @@ EXPORT_SYMBOL(drm_format_vert_chroma_subsampling); */ int drm_format_plane_width(int width, uint32_t format, int plane) { - if (plane >= drm_format_num_planes(format)) + if (!check_format_plane_valid(format, plane)) return 0; if (plane == 0) @@ -5792,7 +5799,7 @@ EXPORT_SYMBOL(drm_format_plane_width); */ int drm_format_plane_height(int height, uint32_t format, int plane) { - if (plane >= drm_format_num_planes(format)) + if (!check_format_plane_valid(format, plane)) return 0; if (plane == 0)