]> Git Repo - linux.git/commitdiff
drm/i915/display: fix compiler warning about array overrun
authorLinus Torvalds <[email protected]>
Sat, 8 May 2021 18:30:22 +0000 (11:30 -0700)
committerLinus Torvalds <[email protected]>
Sat, 8 May 2021 18:30:22 +0000 (11:30 -0700)
intel_dp_check_mst_status() uses a 14-byte array to read the DPRX Event
Status Indicator data, but then passes that buffer at offset 10 off as
an argument to drm_dp_channel_eq_ok().

End result: there are only 4 bytes remaining of the buffer, yet
drm_dp_channel_eq_ok() wants a 6-byte buffer.  gcc-11 correctly warns
about this case:

  drivers/gpu/drm/i915/display/intel_dp.c: In function ‘intel_dp_check_mst_status’:
  drivers/gpu/drm/i915/display/intel_dp.c:3491:22: warning: ‘drm_dp_channel_eq_ok’ reading 6 bytes from a region of size 4 [-Wstringop-overread]
   3491 |                     !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
        |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  drivers/gpu/drm/i915/display/intel_dp.c:3491:22: note: referencing argument 1 of type ‘const u8 *’ {aka ‘const unsigned char *’}
  In file included from drivers/gpu/drm/i915/display/intel_dp.c:38:
  include/drm/drm_dp_helper.h:1466:6: note: in a call to function ‘drm_dp_channel_eq_ok’
   1466 | bool drm_dp_channel_eq_ok(const u8 link_status[DP_LINK_STATUS_SIZE],
        |      ^~~~~~~~~~~~~~~~~~~~
       6:14 elapsed

This commit just extends the original array by 2 zero-initialized bytes,
avoiding the warning.

There may be some underlying bug in here that caused this confusion, but
this is at least no worse than the existing situation that could use
random data off the stack.

Cc: Jani Nikula <[email protected]>
Cc: Ville Syrjälä <[email protected]>
Cc: Joonas Lahtinen <[email protected]>
Cc: Rodrigo Vivi <[email protected]>
Cc: Daniel Vetter <[email protected]>
Cc: Dave Airlie <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
drivers/gpu/drm/i915/display/intel_dp.c

index a560468765c0d46c5ff45902bcd7057c254cc7e9..6a2dee8cef1f16d530f9d6b3809385df91deda65 100644 (file)
@@ -3474,7 +3474,18 @@ intel_dp_check_mst_status(struct intel_dp *intel_dp)
        drm_WARN_ON_ONCE(&i915->drm, intel_dp->active_mst_links < 0);
 
        for (;;) {
-               u8 esi[DP_DPRX_ESI_LEN] = {};
+               /*
+                * The +2 is because DP_DPRX_ESI_LEN is 14, but we then
+                * pass in "esi+10" to drm_dp_channel_eq_ok(), which
+                * takes a 6-byte array. So we actually need 16 bytes
+                * here.
+                *
+                * Somebody who knows what the limits actually are
+                * should check this, but for now this is at least
+                * harmless and avoids a valid compiler warning about
+                * using more of the array than we have allocated.
+                */
+               u8 esi[DP_DPRX_ESI_LEN+2] = {};
                bool handled;
                int retry;
 
This page took 0.074988 seconds and 4 git commands to generate.