[ It's not clear to me why Smatch is complaining about 2 year old code
  but that seems like the buggy commit? ]

Hello Roman Li,

The patch 3a83e4e64bb1: "drm/amd/display: Add dcn3.01 support to DC
(v2)" from Sep 29, 2020, leads to the following Smatch static checker
warning:

        
drivers/gpu/drm/amd/amdgpu/../display/dc/clk_mgr/dcn301/vg_clk_mgr.c:539 
find_dcfclk_for_voltage()
        error: buffer overflow 'clock_table->DcfClocks' 7 <= 7

drivers/gpu/drm/amd/amdgpu/../display/dc/clk_mgr/dcn301/vg_clk_mgr.c
    532 static unsigned int find_dcfclk_for_voltage(const struct vg_dpm_clocks 
*clock_table,
    533                 unsigned int voltage)
    534 {
    535         int i;
    536 
    537         for (i = 0; i < VG_NUM_SOC_VOLTAGE_LEVELS; i++) {
    538                 if (clock_table->SocVoltage[i] == voltage)
--> 539                         return clock_table->DcfClocks[i];
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^
The ->SocVoltage[] array has 8 elements but the ->DcfClocks[] array
only has 7 and the mismatch leads to an out of bounds.

    540         }
    541 
    542         ASSERT(0);
    543         return 0;
    544 }

regards,
dan carpenter

Reply via email to