]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/amd/display: Remove reduntant comparisons by Coverity
authorIvan Lipski <ivlipski@amd.com>
Wed, 29 May 2024 17:47:53 +0000 (13:47 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 14 Jun 2024 20:18:25 +0000 (16:18 -0400)
[WHY]
Coverity analysis of the Upstream display driver code
(amd-staging-drm-next) flagged these three functions as
containing 'CONSTANT_EXPRESSION_RESULT' errors, i. e. the
conditionals are reduntant since their result is predetermined.

fixpt31_32.c:
The two flagged 'ASSERT' lines redundant since they are always true:
- LONG_MAX equals to the largest 'signed long long' number
- res.value is type 'signed long long',

So, the condition inside the 'ASSERTS's is always

link_dp_training.c:
The flagged conditional statement is always false:
- 'max_requested.FFE_PRESET.settings.level' is 4 bits, so its max
  possible value is 15
- 'DP_FFE_PRESET_MAX_LEVEL' equals to 15.

So, the conditional statement is always false and the wrapped code
never executes.

[HOW]
Removed lines flagged by Coverity analysis.

Reviewed-by: Sun peng Li <sunpeng.li@amd.com>
Acked-by: Zaeem Mohamed <zaeem.mohamed@amd.com>
Signed-off-by: Ivan Lipski <ivlipski@amd.com>
Tested-by: Daniel Wheeler <daniel.wheeler@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/dc/basics/fixpt31_32.c
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training.c

index 1726bdf89bae819a0ad947fe988f81eab4553cb7..506f82cd5cc67aa5d249e23194dc6485355dc18e 100644 (file)
@@ -140,8 +140,6 @@ struct fixed31_32 dc_fixpt_mul(struct fixed31_32 arg1, struct fixed31_32 arg2)
 
        res.value = arg1_int * arg2_int;
 
-       ASSERT(res.value <= LONG_MAX);
-
        res.value <<= FIXED31_32_BITS_PER_FRACTIONAL_PART;
 
        tmp = arg1_int * arg2_fra;
@@ -185,8 +183,6 @@ struct fixed31_32 dc_fixpt_sqr(struct fixed31_32 arg)
 
        res.value = arg_int * arg_int;
 
-       ASSERT(res.value <= LONG_MAX);
-
        res.value <<= FIXED31_32_BITS_PER_FRACTIONAL_PART;
 
        tmp = arg_int * arg_fra;
index a93dd83cd8c0e94dad8d94425dde197ae0b0fad2..5a0f574056d4445604ee24a0b29a73bc7b034b10 100644 (file)
@@ -329,8 +329,12 @@ static void maximize_lane_settings(const struct link_training_settings *lt_setti
 
        if (max_requested.PRE_EMPHASIS > PRE_EMPHASIS_MAX_LEVEL)
                max_requested.PRE_EMPHASIS = PRE_EMPHASIS_MAX_LEVEL;
-       if (max_requested.FFE_PRESET.settings.level > DP_FFE_PRESET_MAX_LEVEL)
-               max_requested.FFE_PRESET.settings.level = DP_FFE_PRESET_MAX_LEVEL;
+
+       /* Note, we are not checking
+        * if max_requested.FFE_PRESET.settings.level >  DP_FFE_PRESET_MAX_LEVEL,
+        * since FFE_PRESET.settings.level is 4 bits and DP_FFE_PRESET_MAX_LEVEL equals 15,
+        * so FFE_PRESET.settings.level will never be greater than 15.
+        */
 
        /* make sure the pre-emphasis matches the voltage swing*/
        if (max_requested.PRE_EMPHASIS >