• Arnd Bergmann's avatar
    drm/kmb: fix array bounds warning · 98fdd004
    Arnd Bergmann authored
    gcc warns about an out-of-bounds access when the using nonzero
    values for 'plane_id' on kmb->plane_status:
    
    drivers/gpu/drm/kmb/kmb_plane.c: In function 'kmb_plane_atomic_disable':
    drivers/gpu/drm/kmb/kmb_plane.c:128:20: warning: array subscript 3 is above array bounds of 'struct layer_status[1]' [-Warray-bounds]
      128 |   kmb->plane_status[plane_id].ctrl = LCD_CTRL_GL2_ENABLE;
          |   ~~~~~~~~~~~~~~~~~^~~~~~~~~~
    drivers/gpu/drm/kmb/kmb_plane.c:125:20: warning: array subscript 2 is above array bounds of 'struct layer_status[1]' [-Warray-bounds]
      125 |   kmb->plane_status[plane_id].ctrl = LCD_CTRL_GL1_ENABLE;
          |   ~~~~~~~~~~~~~~~~~^~~~~~~~~~
    drivers/gpu/drm/kmb/kmb_plane.c:122:20: warning: array subscript 1 is above array bounds of 'struct layer_status[1]' [-Warray-bounds]
      122 |   kmb->plane_status[plane_id].ctrl = LCD_CTRL_VL2_ENABLE;
    
    Having the array truncated to one entry seems intentional, so add
    a range check before indexing it to make it clearer what is going
    on and shut up the warning.
    
    I received the warning from the kernel test robot after a private
    patch that turns on Warray-bounds unconditionally.
    
    Fixes: 7f7b96a8 ("drm/kmb: Add support for KeemBay Display")
    Reported-by: default avatarkernel test robot <lkp@intel.com>
    Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
    Reviewed-by: default avatarAnitha Chrisanthus <anitha.chrisanthus@intel.com>
    Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
    Link: https://patchwork.freedesktop.org/patch/msgid/20201129200927.1854104-1-arnd@kernel.org
    98fdd004
kmb_plane.c 14.4 KB