Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25AD41F4180; Wed, 14 Jan 2026 00:00:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768348844; cv=none; b=fZJb8U/sqkq1n/w1c6YUkURmgro/Ah8wVTr8P+KYtrZYk75OiaLU+lBZ/p67OP54gXddpNUMnmGkzHiiTJCCWxEAcprVzDXUFBS0kCL6s6f7uNoxxuXQ7la738hAwX8TXTPzCdsvFctJ/4zsx6A2Y4ZXklJjT7nvZlwkRgqOGMI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768348844; c=relaxed/simple; bh=bXLpO8c9ZBsExdS2sHYGwKNmU+WKPGSgvNzVCoVhZYw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=H8VTr2nsjIMTmHaG/65np7VdoYbJyWe33xDJLosG8aKRhyuOT0VsPOpi0V3se3yOlo1IbbvMBdGozmUn8IvNuDyhV/NyeagO571fv8/cgR/iEiu5c3QlMBDvUOSinhNnK/dl2B8J4CtyNJ6AbV51rT/3n8CHl+UrhC+8RVCP7qM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uc+7oYGl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uc+7oYGl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49891C116C6; Wed, 14 Jan 2026 00:00:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768348843; bh=bXLpO8c9ZBsExdS2sHYGwKNmU+WKPGSgvNzVCoVhZYw=; h=From:Date:Subject:To:Cc:From; b=uc+7oYGl75Lz8ht0DyVesshS8Yxx8aV8Q5h8oU6t3D0pXEnrrYsOoDnIfNxYZWEAK sKLjVwY+F26AjkDiYsPs48ilC/mpxdZyeu771qPN7rWgSJcQ1bVuFnzq3XgNarTihr ZFZJQQqvrJqqVsZHSZxnWhVRAbMdOS3qo9R5/+gdHfVIoZxWnLLJ5HlPe1TaK4o2D/ JCzZyekCygyNVTctCkGUqRkXalu1iLiV5xRi/6MwoOMJd+36uBH5LQv21/gOHG2efc vfyzx0VI86PRsewPyNn8IvmFshLL1Z2boB4YULGLO/DkLa46lkYZN0OpXq2dtODf0z zqjvzP5w9bIRA== From: Nathan Chancellor Date: Tue, 13 Jan 2026 17:00:31 -0700 Subject: [PATCH v2] drm/msm/dp: Avoid division by zero in msm_dp_ctrl_config_msa() Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260113-drm-msm-dp_ctrl-avoid-zero-div-v2-1-f1aa67bf6e8e@kernel.org> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/42OQQ6CMBBFr0Jm7ZgWlBBX3sMQQ9sRRoGSKTYq4 e4CXsDlS17++xMEEqYAp2QCociBfb9AukvANlVfE7JbGFKV5kqrAp102IUO3XC1o7RYRc8OPyQ eHUc0dHT2oKyxuoBlZBC68WsLXMofh6e5kx3X1dVoOIxe3tuDqFfv71jUqDGvCkfGmkxl2flB0 lO791JDOc/zF71BhHzfAAAA X-Change-ID: 20260108-drm-msm-dp_ctrl-avoid-zero-div-be5dc40cbc18 To: Rob Clark , Dmitry Baryshkov , Abhinav Kumar , Jessica Zhang , Sean Paul , Marijn Suijten Cc: linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, llvm@lists.linux.dev, patches@lists.linux.dev, kernel test robot , Konrad Dybcio , Nathan Chancellor X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3616; i=nathan@kernel.org; h=from:subject:message-id; bh=bXLpO8c9ZBsExdS2sHYGwKNmU+WKPGSgvNzVCoVhZYw=; b=owGbwMvMwCUmm602sfCA1DTG02pJDJlpd1aoxTJt9GOdJFio/Oh2+SfpdJ6yrfuVjVbubGvh0 dnYotjfUcrCIMbFICumyFL9WPW4oeGcs4w3Tk2CmcPKBDKEgYtTACZi2cvIcKvp5KZbV//qR/CL Hz0W67YnpkImbJ//Xhklhe+K32MF5jMyzCy40il6SIfjYPjSRomXN1ISjsyPvPzoYOPOdStPzrq vxQsA X-Developer-Key: i=nathan@kernel.org; a=openpgp; fpr=2437CB76E544CB6AB3D9DFD399739260CB6CB716 An (admittedly problematic) optimization change in LLVM 20 [1] turns known division by zero into the equivalent of __builtin_unreachable(), which invokes undefined behavior if it is encountered in a control flow graph, destroying code generation. When compile testing for x86_64, objtool flags an instance of this optimization triggering in msm_dp_ctrl_config_msa(), inlined into msm_dp_ctrl_on_stream(): drivers/gpu/drm/msm/msm.o: warning: objtool: msm_dp_ctrl_on_stream(): unexpected end of section .text.msm_dp_ctrl_on_stream The zero division happens if the else branch in the first if statement in msm_dp_ctrl_config_msa() is taken because pixel_div is initialized to zero and it is not possible for LLVM to eliminate the else branch since rate is still not known after inlining into msm_dp_ctrl_on_stream(). Transform the if statements into a switch statement with a default case with the existing error print and an early return to avoid the invalid division. Add a comment to note this helps the compiler, even though the case is known to be unreachable. With this, pixel_dev's default zero initialization can be dropped, as it is dead with this change. Fixes: c943b4948b58 ("drm/msm/dp: add displayPort driver support") Link: https://github.com/llvm/llvm-project/commit/37932643abab699e8bb1def08b7eb4eae7ff1448 [1] Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202601081959.9UVJEOfP-lkp@intel.com/ Suggested-by: Konrad Dybcio Signed-off-by: Nathan Chancellor --- Changes in v2: - Transform existing if statement structure into a switch case with a default case that early returns, avoiding the invalid division (Konrad, Dmitry). Add a commment about the reachability of the default case. - Drop the default zero initialization of pixel_div, as it is no longer used due to the new switch statement. - Link to v1: https://patch.msgid.link/20260108-drm-msm-dp_ctrl-avoid-zero-div-v1-1-6a8debcb3033@kernel.org --- drivers/gpu/drm/msm/dp/dp_ctrl.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/msm/dp/dp_ctrl.c b/drivers/gpu/drm/msm/dp/dp_ctrl.c index cbcc7c2f0ffc..94411870a5e0 100644 --- a/drivers/gpu/drm/msm/dp/dp_ctrl.c +++ b/drivers/gpu/drm/msm/dp/dp_ctrl.c @@ -2395,20 +2395,32 @@ static void msm_dp_ctrl_config_msa(struct msm_dp_ctrl_private *ctrl, bool is_ycbcr_420) { u32 pixel_m, pixel_n; - u32 mvid, nvid, pixel_div = 0, dispcc_input_rate; + u32 mvid, nvid, pixel_div, dispcc_input_rate; u32 const nvid_fixed = DP_LINK_CONSTANT_N_VALUE; u32 const link_rate_hbr2 = 540000; u32 const link_rate_hbr3 = 810000; unsigned long den, num; - if (rate == link_rate_hbr3) + switch (rate) { + case link_rate_hbr3: pixel_div = 6; - else if (rate == 162000 || rate == 270000) - pixel_div = 2; - else if (rate == link_rate_hbr2) + break; + case link_rate_hbr2: pixel_div = 4; - else + break; + case 162000: + case 270000: + pixel_div = 2; + break; + default: + /* + * This cannot be reached but the compiler is not able to know + * that statically so return early to avoid a possibly invalid + * division. + */ DRM_ERROR("Invalid pixel mux divider\n"); + return; + } dispcc_input_rate = (rate * 10) / pixel_div; --- base-commit: 66691e272e40c91305f1704695e0cb340cd162ff change-id: 20260108-drm-msm-dp_ctrl-avoid-zero-div-be5dc40cbc18 Best regards, -- Nathan Chancellor