Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3413814rwa; Tue, 23 Aug 2022 04:30:02 -0700 (PDT) X-Google-Smtp-Source: AA6agR7SzGQNjbSpTrYVlwBuKuoVQ75uFkVzGZgUNvtLWmozNQ39KFEE62KNBQ+fM+mjZIJ0WgUK X-Received: by 2002:a65:5806:0:b0:429:f9a2:10ca with SMTP id g6-20020a655806000000b00429f9a210camr19888466pgr.541.1661254202558; Tue, 23 Aug 2022 04:30:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254202; cv=none; d=google.com; s=arc-20160816; b=G3PJDf4iRb5xUHK0WYQk5v8zNHE9+FGVIRgUUQnpe5eBC26jwXWJZuYPa4D+wAwPFX Yj3bY8PB7YEvrZIJg2GOMa/+zJ6PeUmMKuwq9BfDEOfVM9Fzo2d3kYElJOECCrgEoalH tgDWwjM/a7eVV0uNY/xFF/oxQxaH44mDHQEuj1BzzPZMGhWBP5ZV9pyKpQ179V9H++0z 3ENTnFkMg5RYaw9eYaou5/3nAF5/APaTyDDYhhV/MmCrjnzHH1IMUoApT5q07FCe4/KJ 4tXqWFWT5bm2G7sBP1rWncuuVFqhApUsdak2xH4q/DchyuukpvheMlPgxFtkr2cI5J4h VZaA== 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=R5z6gF2MWA0lA27PyP2Ht+AOhzrUqkwIsx4s9nrAHag=; b=MUKau6CpDsoLPFHIo+Uf31VimayYA/cXZyAnUZlU9Aio/kULawiwUTljiDQ0hV4fy5 alHhK9MOn3ZEZ0tGik7uvXTCeTSzbAyrlqiAb4M0yGfqgsyhUR64quvB6XVjUIi7ljLi urisQEs0vORSLfCJpq9s7GK3SgNJmPLzpCzUG4cjabBzfRnHLz5+vy5uPtVCM1eJKm9y N4anevOdsKiKQogrKA67CASziu4aepMCKml8tjdg8JwI34a4kjxG9Z71HuDbcYs0cc1e nlEm2cF50CnWyxnS0QsZ5h/NmVVrgbHneeVmViYXnPOnK66UencMK9htWsfJRa2wrM2W 0I9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Up3Xp/Mb"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d66-20020a636845000000b0042a02350c42si14459460pgc.245.2022.08.23.04.29.51; Tue, 23 Aug 2022 04:30:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Up3Xp/Mb"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353943AbiHWKQY (ORCPT + 99 others); Tue, 23 Aug 2022 06:16:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241254AbiHWKGf (ORCPT ); Tue, 23 Aug 2022 06:06:35 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE8823205B; Tue, 23 Aug 2022 01:53:49 -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 3DBA8B8105C; Tue, 23 Aug 2022 08:53:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6A0AC433C1; Tue, 23 Aug 2022 08:53:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244827; bh=4xd33p/pVu1mA6EQYzbUK+uFzqw0xRsu7Ph4j4WK9e4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Up3Xp/Mb+ACTUhDUj2tCllOm89mocLaZAFDOz7E6bQSAtdptyBwtvmtqUlFYLPIvU pp34HF+KQD4OwonfioHg9Cgv53ya3KPlzAa3vZNskb/hLDnyAKaoXnKSHMbdmLGBL+ uxdTjTJypLB02iMuHAjNdMcfXUrR042VudyVvodg= 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.15 158/244] drm/sun4i: dsi: Prevent underflow when computing packet sizes Date: Tue, 23 Aug 2022 10:25:17 +0200 Message-Id: <20220823080104.469108091@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 support") 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 4f5efcace68e..51edb4244af7 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 *dsi, struct drm_display_mode *mode) { struct mipi_dsi_device *device = dsi->device; - unsigned int Bpp = mipi_dsi_pixel_format_to_bpp(device->format) / 8; + int Bpp = mipi_dsi_pixel_format_to_bpp(device->format) / 8; u16 hbp = 0, hfp = 0, hsa = 0, hblk = 0, vblk = 0; u32 basic_ctl = 0; size_t bytes; @@ -555,7 +555,7 @@ static void sun6i_dsi_setup_timings(struct sun6i_dsi *dsi, * (4 bytes). Its minimal size is therefore 10 bytes */ #define HSA_PACKET_OVERHEAD 10 - hsa = max((unsigned int)HSA_PACKET_OVERHEAD, + hsa = max(HSA_PACKET_OVERHEAD, (mode->hsync_end - mode->hsync_start) * Bpp - HSA_PACKET_OVERHEAD); /* @@ -564,7 +564,7 @@ static void sun6i_dsi_setup_timings(struct sun6i_dsi *dsi, * therefore 6 bytes */ #define HBP_PACKET_OVERHEAD 6 - hbp = max((unsigned int)HBP_PACKET_OVERHEAD, + hbp = max(HBP_PACKET_OVERHEAD, (mode->htotal - mode->hsync_end) * Bpp - HBP_PACKET_OVERHEAD); /* @@ -574,7 +574,7 @@ static void sun6i_dsi_setup_timings(struct sun6i_dsi *dsi, * 16 bytes */ #define HFP_PACKET_OVERHEAD 16 - hfp = max((unsigned int)HFP_PACKET_OVERHEAD, + hfp = max(HFP_PACKET_OVERHEAD, (mode->hsync_start - mode->hdisplay) * Bpp - HFP_PACKET_OVERHEAD); /* @@ -583,7 +583,7 @@ static void sun6i_dsi_setup_timings(struct sun6i_dsi *dsi, * bytes). Its minimal size is therefore 10 bytes. */ #define HBLK_PACKET_OVERHEAD 10 - hblk = max((unsigned int)HBLK_PACKET_OVERHEAD, + hblk = max(HBLK_PACKET_OVERHEAD, (mode->htotal - (mode->hsync_end - mode->hsync_start)) * Bpp - HBLK_PACKET_OVERHEAD); -- 2.35.1