Skip to content

Commit 82a1356

Browse files
smaeulmripard
authored andcommitted
drm/sun4i: dsi: Prevent underflow when computing packet sizes
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: 133add5 ("drm/sun4i: Add Allwinner A31 MIPI-DSI controller support") Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Jernej Skrabec <[email protected]> Signed-off-by: Maxime Ripard <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 2a29f80 commit 82a1356

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ static void sun6i_dsi_setup_timings(struct sun6i_dsi *dsi,
531531
struct drm_display_mode *mode)
532532
{
533533
struct mipi_dsi_device *device = dsi->device;
534-
unsigned int Bpp = mipi_dsi_pixel_format_to_bpp(device->format) / 8;
534+
int Bpp = mipi_dsi_pixel_format_to_bpp(device->format) / 8;
535535
u16 hbp = 0, hfp = 0, hsa = 0, hblk = 0, vblk = 0;
536536
u32 basic_ctl = 0;
537537
size_t bytes;
@@ -555,7 +555,7 @@ static void sun6i_dsi_setup_timings(struct sun6i_dsi *dsi,
555555
* (4 bytes). Its minimal size is therefore 10 bytes
556556
*/
557557
#define HSA_PACKET_OVERHEAD 10
558-
hsa = max((unsigned int)HSA_PACKET_OVERHEAD,
558+
hsa = max(HSA_PACKET_OVERHEAD,
559559
(mode->hsync_end - mode->hsync_start) * Bpp - HSA_PACKET_OVERHEAD);
560560

561561
/*
@@ -564,7 +564,7 @@ static void sun6i_dsi_setup_timings(struct sun6i_dsi *dsi,
564564
* therefore 6 bytes
565565
*/
566566
#define HBP_PACKET_OVERHEAD 6
567-
hbp = max((unsigned int)HBP_PACKET_OVERHEAD,
567+
hbp = max(HBP_PACKET_OVERHEAD,
568568
(mode->htotal - mode->hsync_end) * Bpp - HBP_PACKET_OVERHEAD);
569569

570570
/*
@@ -574,7 +574,7 @@ static void sun6i_dsi_setup_timings(struct sun6i_dsi *dsi,
574574
* 16 bytes
575575
*/
576576
#define HFP_PACKET_OVERHEAD 16
577-
hfp = max((unsigned int)HFP_PACKET_OVERHEAD,
577+
hfp = max(HFP_PACKET_OVERHEAD,
578578
(mode->hsync_start - mode->hdisplay) * Bpp - HFP_PACKET_OVERHEAD);
579579

580580
/*
@@ -583,7 +583,7 @@ static void sun6i_dsi_setup_timings(struct sun6i_dsi *dsi,
583583
* bytes). Its minimal size is therefore 10 bytes.
584584
*/
585585
#define HBLK_PACKET_OVERHEAD 10
586-
hblk = max((unsigned int)HBLK_PACKET_OVERHEAD,
586+
hblk = max(HBLK_PACKET_OVERHEAD,
587587
(mode->htotal - (mode->hsync_end - mode->hsync_start)) * Bpp -
588588
HBLK_PACKET_OVERHEAD);
589589

0 commit comments

Comments
 (0)