From patchwork Thu Aug 23 00:51:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Vivi X-Patchwork-Id: 10573315 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 CC3F0920 for ; Thu, 23 Aug 2018 00:51:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B52D52C017 for ; Thu, 23 Aug 2018 00:51:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A95232BF74; Thu, 23 Aug 2018 00:51:21 +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 2693F2BFF2 for ; Thu, 23 Aug 2018 00:51:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DBBFB6E123; Thu, 23 Aug 2018 00:51:19 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTPS id A66E46E0FD for ; Thu, 23 Aug 2018 00:51:18 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Aug 2018 17:51:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,276,1531810800"; d="scan'208";a="85636914" Received: from vanajaka-mobl2.amr.corp.intel.com (HELO rdvivi-vienna.intel.com) ([10.252.140.166]) by orsmga002.jf.intel.com with ESMTP; 22 Aug 2018 17:51:17 -0700 From: Rodrigo Vivi To: intel-gfx@lists.freedesktop.org Date: Wed, 22 Aug 2018 17:51:16 -0700 Message-Id: <20180823005116.4336-1-rodrigo.vivi@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [Intel-gfx] [PATCH] drm/i915: protect against division by zero. 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: Rodrigo Vivi MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Static analyzer tools thinks it is possible to have a division by zero here. I don't believe we would really reach this path without any crtc enabled, but may be good to protect against some unexpected path or behavior. Fixes: cf1f697acb04 ("drm/i915/skl: distribute DDB based on panel resolution") Cc: Chris Wilson Cc: Mahesh Kumar Cc: Maarten Lankhorst Signed-off-by: Rodrigo Vivi --- drivers/gpu/drm/i915/intel_pm.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c index d99e5fabe93c..fac6e159a640 100644 --- a/drivers/gpu/drm/i915/intel_pm.c +++ b/drivers/gpu/drm/i915/intel_pm.c @@ -3878,6 +3878,12 @@ skl_ddb_get_pipe_allocation_limits(struct drm_device *dev, pipe_width = hdisplay; } + if (WARN_ON(total_width == 0)) { + alloc->start = 0; + alloc->end = 0; + return; + } + alloc->start = ddb_size * width_before_pipe / total_width; alloc->end = ddb_size * (width_before_pipe + pipe_width) / total_width; }