From nobody Thu Dec 18 13:01:03 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 673D6C32772 for ; Tue, 23 Aug 2022 09:07:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240553AbiHWJHb (ORCPT ); Tue, 23 Aug 2022 05:07:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240382AbiHWJGN (ORCPT ); Tue, 23 Aug 2022 05:06:13 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C466185FE1; Tue, 23 Aug 2022 01:29:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B977FB81C58; Tue, 23 Aug 2022 08:29:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C82CC433D6; Tue, 23 Aug 2022 08:29:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661243341; bh=BkWQsObRD0qHdiFNBqOcDLLUMiSRZ6gAZkju3pfvCZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JIuSCHcy9xkaEOYAgYkhuHnDug6Wx8v/TTtki0OciE2vDkkRcVgwjUgoaXl7b+ED+ l8DStnsE1d1YbsretWzuD2AAi7XRDaYPY9itLP5qaNdSOpE/5nEVtLqXbqBOrCDSXn FXcJTMj37Xq3oK8dMRn0dNYMG8I21KmY5lmZwDqo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Samuel Holland , Jernej Skrabec , Maxime Ripard , Sasha Levin Subject: [PATCH 5.19 247/365] drm/sun4i: dsi: Prevent underflow when computing packet sizes Date: Tue, 23 Aug 2022 10:02:28 +0200 Message-Id: <20220823080128.539277076@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080118.128342613@linuxfoundation.org> References: <20220823080118.128342613@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Samuel Holland [ Upstream commit 82a1356a933d8443139f8886f11b63c974a09a67 ] Currently, the packet overhead is subtracted using unsigned arithmetic. With a short sync pulse, this could underflow and wrap around to near the maximal u16 value. Fix this by using signed subtraction. The call to max() will correctly handle any negative numbers that are produced. Apply the same fix to the other timings, even though those subtractions are less likely to underflow. Fixes: 133add5b5ad4 ("drm/sun4i: Add Allwinner A31 MIPI-DSI controller supp= ort") Signed-off-by: Samuel Holland Reviewed-by: Jernej Skrabec Signed-off-by: Maxime Ripard Link: https://lore.kernel.org/r/20220812031623.34057-1-samuel@sholland.org Signed-off-by: Sasha Levin --- drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c b/drivers/gpu/drm/sun4i= /sun6i_mipi_dsi.c index b4dfa166eccd..34234a144e87 100644 --- a/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c +++ b/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c @@ -531,7 +531,7 @@ static void sun6i_dsi_setup_timings(struct sun6i_dsi *d= si, struct drm_display_mode *mode) { struct mipi_dsi_device *device =3D dsi->device; - unsigned int Bpp =3D mipi_dsi_pixel_format_to_bpp(device->format) / 8; + int Bpp =3D mipi_dsi_pixel_format_to_bpp(device->format) / 8; u16 hbp =3D 0, hfp =3D 0, hsa =3D 0, hblk =3D 0, vblk =3D 0; u32 basic_ctl =3D 0; size_t bytes; @@ -555,7 +555,7 @@ static void sun6i_dsi_setup_timings(struct sun6i_dsi *d= si, * (4 bytes). Its minimal size is therefore 10 bytes */ #define HSA_PACKET_OVERHEAD 10 - hsa =3D max((unsigned int)HSA_PACKET_OVERHEAD, + hsa =3D max(HSA_PACKET_OVERHEAD, (mode->hsync_end - mode->hsync_start) * Bpp - HSA_PACKET_OVERHEAD); =20 /* @@ -564,7 +564,7 @@ static void sun6i_dsi_setup_timings(struct sun6i_dsi *d= si, * therefore 6 bytes */ #define HBP_PACKET_OVERHEAD 6 - hbp =3D max((unsigned int)HBP_PACKET_OVERHEAD, + hbp =3D max(HBP_PACKET_OVERHEAD, (mode->htotal - mode->hsync_end) * Bpp - HBP_PACKET_OVERHEAD); =20 /* @@ -574,7 +574,7 @@ static void sun6i_dsi_setup_timings(struct sun6i_dsi *d= si, * 16 bytes */ #define HFP_PACKET_OVERHEAD 16 - hfp =3D max((unsigned int)HFP_PACKET_OVERHEAD, + hfp =3D max(HFP_PACKET_OVERHEAD, (mode->hsync_start - mode->hdisplay) * Bpp - HFP_PACKET_OVERHEAD); =20 /* @@ -583,7 +583,7 @@ static void sun6i_dsi_setup_timings(struct sun6i_dsi *d= si, * bytes). Its minimal size is therefore 10 bytes. */ #define HBLK_PACKET_OVERHEAD 10 - hblk =3D max((unsigned int)HBLK_PACKET_OVERHEAD, + hblk =3D max(HBLK_PACKET_OVERHEAD, (mode->htotal - (mode->hsync_end - mode->hsync_start)) * Bpp - HBLK_PACKET_OVERHEAD); =20 --=20 2.35.1