Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp220224pxx; Wed, 28 Oct 2020 03:12:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzj71KitcgSBcCD2G2sTYlhWrOmbLZUZsq+c5jqWMXozX7nQk+OEle+SIsUD4lRf7LgLgMU X-Received: by 2002:a05:6402:503:: with SMTP id m3mr7143914edv.368.1603879963334; Wed, 28 Oct 2020 03:12:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603879963; cv=none; d=google.com; s=arc-20160816; b=ZuxaKPFrl3aNFq0BlQjli4dUzmtw5QYRtSs2j0oiOL2MxMOn+Dlu5ezrPE3W5ogsTs u6D705xXB/2JBVWiy3w0pRtvCRqr/YHj8zQklq6p2EZJ003LNfsYeMUpYyJM/AnWjhT2 lq1McdOIuJWPi+FKgdNW7klYA76+F2XuzVaFwTJyXd3s1aQY7FY6jh1cQ4wJCCItZHXU RbUp8Dv8wKcT2VEHDa8rUnKqwLLVQKWP3Tj/QP5DSAaPXHyvuD83znVWiTeOVIcWHS6W BHXP15msh2AX5TYlIHB1H3jWfR1FNaZXjrm607B/a0YSrNYk9btZhtFDPB8Gjrn9xeGy qhaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MMI6nNIwTcUEFxZ79DreH/L/hTyUu/oWYKRZotiqslI=; b=I8lHLwoNXctm5KJO06s4Ex6Ke+G0bvtV2+Llw0Mm8RMjsThKW58vVuvNH3MWsRRfNq Dv4M4qMdGmZvZxEIUpccWr8TPtIf70GQU8bVKol6FrTedJKkFvCu2at3op2p9OvM55xw de+r4HW7/ZRSPHtgdN8eTH/KqiqBQSGfMVe66hstUMzFu0GHZ5TpkFDLy3qmrL264CDz a0pTZCU5gpDB4/uHSavq4Qxo/huemVrTPhrNVKqGpQ8E60RjRIVnSk6R4YLSMv2iQUe7 z08sAIRbAhZxxyXk9rKknv9qAFpvIiahX0pHRhGKYI/SkAHgr8W42fdw/MHRo+V72WO/ wNEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="du/h1/ix"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b29si2827715edn.354.2020.10.28.03.12.21; Wed, 28 Oct 2020 03:12:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="du/h1/ix"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760625AbgJ0Ofd (ORCPT + 99 others); Tue, 27 Oct 2020 10:35:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:33526 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760116AbgJ0Oem (ORCPT ); Tue, 27 Oct 2020 10:34:42 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 22B272225E; Tue, 27 Oct 2020 14:34:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809281; bh=FDE0hqvUMIcEX+UOoX7iVp3RYulH01N1fwI4rgtH+cE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=du/h1/ix2hPXYnKZzqtPH38QQwmUc9OZUJOoKzz6uha7BWTz6Nifx4cvvCaemTx2u WzBp3K7RPL8uYWGyp/NPZL/XJgu2R754+pgcrlBXVNDOnU9qvwMwGneagH+ml2I6/c 0D+sSGeqTv2sB7tzqWcNoRFlpX8rBj8w/Rjn1GOw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Abhinav Kumar , Jeykumar Sankaran , Jordan Crouse , Sean Paul , Stephen Boyd , Sai Prakash Ranjan , Rob Clark , Sasha Levin Subject: [PATCH 5.4 140/408] drm/msm: Avoid div-by-zero in dpu_crtc_atomic_check() Date: Tue, 27 Oct 2020 14:51:18 +0100 Message-Id: <20201027135501.591813165@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stephen Boyd [ Upstream commit 22f760941844dbcee6ee446e1896532f6dff01ef ] The cstate->num_mixers member is only set to a non-zero value once dpu_encoder_virt_mode_set() is called, but the atomic check function can be called by userspace before that. Let's avoid the div-by-zero here and inside _dpu_crtc_setup_lm_bounds() by skipping this part of the atomic check if dpu_encoder_virt_mode_set() hasn't been called yet. This fixes an UBSAN warning: UBSAN: Undefined behaviour in drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c:860:31 division by zero CPU: 7 PID: 409 Comm: frecon Tainted: G S 5.4.31 #128 Hardware name: Google Trogdor (rev0) (DT) Call trace: dump_backtrace+0x0/0x14c show_stack+0x20/0x2c dump_stack+0xa0/0xd8 __ubsan_handle_divrem_overflow+0xec/0x110 dpu_crtc_atomic_check+0x97c/0x9d4 drm_atomic_helper_check_planes+0x160/0x1c8 drm_atomic_helper_check+0x54/0xbc drm_atomic_check_only+0x6a8/0x880 drm_atomic_commit+0x20/0x5c drm_atomic_helper_set_config+0x98/0xa0 drm_mode_setcrtc+0x308/0x5dc drm_ioctl_kernel+0x9c/0x114 drm_ioctl+0x2ac/0x4b0 drm_compat_ioctl+0xe8/0x13c __arm64_compat_sys_ioctl+0x184/0x324 el0_svc_common+0xa4/0x154 el0_svc_compat_handler+0x Cc: Abhinav Kumar Cc: Jeykumar Sankaran Cc: Jordan Crouse Cc: Sean Paul Fixes: 25fdd5933e4c ("drm/msm: Add SDM845 DPU support") Signed-off-by: Stephen Boyd Reviewed-by: Abhinav Kumar Tested-by: Sai Prakash Ranjan Signed-off-by: Rob Clark Signed-off-by: Sasha Levin --- drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c index 36c85c05b7cf7..4aed5e9a84a45 100644 --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c @@ -819,7 +819,7 @@ static int dpu_crtc_atomic_check(struct drm_crtc *crtc, struct drm_plane *plane; struct drm_display_mode *mode; - int cnt = 0, rc = 0, mixer_width, i, z_pos; + int cnt = 0, rc = 0, mixer_width = 0, i, z_pos; struct dpu_multirect_plane_states multirect_plane[DPU_STAGE_MAX * 2]; int multirect_count = 0; @@ -852,9 +852,11 @@ static int dpu_crtc_atomic_check(struct drm_crtc *crtc, memset(pipe_staged, 0, sizeof(pipe_staged)); - mixer_width = mode->hdisplay / cstate->num_mixers; + if (cstate->num_mixers) { + mixer_width = mode->hdisplay / cstate->num_mixers; - _dpu_crtc_setup_lm_bounds(crtc, state); + _dpu_crtc_setup_lm_bounds(crtc, state); + } crtc_rect.x2 = mode->hdisplay; crtc_rect.y2 = mode->vdisplay; -- 2.25.1