drm/sun4i: dsi: Prevent underflow when computing packet sizes
authorSamuel Holland <samuel@sholland.org>
Fri, 12 Aug 2022 03:16:23 +0000 (22:16 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 25 Aug 2022 09:40:29 +0000 (11:40 +0200)
commit98e28de472ef248352f04f87e29e634ebb0ec240
treeaed43304e075688d43b9e62a258909fab44f7f04
parentfe71d84c1a6c0d54657431e8eeaefc9d24895304
drm/sun4i: dsi: Prevent underflow when computing packet sizes

[ 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 <samuel@sholland.org>
Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Link: https://lore.kernel.org/r/20220812031623.34057-1-samuel@sholland.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c