Re: [PATCH v3] drm/i915/kunit: DP Link: Use if statements instead of for loops
Michał Grzelak <[email protected]>
| Newsgroups | org.freedesktop.lists.intel-gfx,org.freedesktop.lists.intel-xe |
|---|---|
| Message-ID | <[email protected]> |
On Wed, 12 Aug 2026, Jonathan Cavitt wrote: > The static functions get_target_config and get_fallback_config in > intel_dp_link_test.c use for loops to determine if the requested index of > the config set is in the bounds of the config set entry list. > > Reconfigure these functions to use if statements instead, as these for > loops are only run for a single iteration. > > Issue caught by static analysis. > > v2: (Michal) > - Change i <= 0 check to i == 0, as i cannot be negative by assertion > - Remove unnecessary newlines > > v3: > - Misc. checkpatch fixes > - Resubmit to exercise target kunit test > > Signed-off-by: Jonathan Cavitt <[email protected]> > Cc: Imre Deak <[email protected]> > Cc: Michal Grzelak <[email protected]> > Cc: Jani Nikula <[email protected]> CI on intel-xe@ doesn't run i915's KUnit tests so it is absent from CI's report. Nevertheless, here's the report from running it manually on the series: [16:06:01] =============== intel_dp_link (17 subtests) ================ [16:06:01] [PASSED] intel_dp_link_caps_test_baseline [16:06:01] [PASSED] intel_dp_link_caps_test_update_reset [16:06:01] [PASSED] intel_dp_link_caps_test_update_rates_shrink [16:06:01] [PASSED] intel_dp_link_caps_test_update_rates_shrink_disable [16:06:01] [PASSED] intel_dp_link_caps_test_update_rates_expand [16:06:01] [PASSED] intel_dp_link_caps_test_update_rates_expand_disable [16:06:01] [PASSED] intel_dp_link_caps_test_update_lanes_shrink [16:06:01] [PASSED] intel_dp_link_caps_test_update_lanes_shrink_disable [16:06:01] [PASSED] intel_dp_link_caps_test_update_lanes_expand [16:06:01] [PASSED] intel_dp_link_caps_test_update_lanes_expand_disable [16:06:02] [PASSED] intel_dp_link_caps_test_update_params_shrink_random [16:06:02] [PASSED] intel_dp_link_caps_test_update_params_shrink_disable_random [16:06:02] [PASSED] intel_dp_link_caps_test_update_params_expand_random [16:06:02] [PASSED] intel_dp_link_caps_test_update_params_expand_disable_random [16:06:02] [PASSED] intel_dp_link_test_fallback_for_edp [16:06:02] [PASSED] intel_dp_link_test_fallback_for_sst [16:06:02] [PASSED] intel_dp_link_test_fallback_for_mst [16:06:02] ================== [PASSED] intel_dp_link ================== [16:06:02] ============================================================ [16:06:02] Testing complete. Ran 17 tests: passed: 17 [16:06:02] Elapsed time: 3.599s total, 0.001s configuring, 2.128s building, 1.440s running Looks reasonable. Reviewed-by: MichaÂł Grzelak <[email protected]> Tested-by: MichaÂł Grzelak <[email protected]> BR, MichaÂł > --- > .../i915/display/tests/intel_dp_link_test.c | 34 ++++++++----------- > 1 file changed, 15 insertions(+), 19 deletions(-) > > diff --git a/drivers/gpu/drm/i915/display/tests/intel_dp_link_test.c b/drivers/gpu/drm/i915/display/tests/intel_dp_link_test.c > index 67c6fe9f1812..608b7a9d60bf 100644 > --- a/drivers/gpu/drm/i915/display/tests/intel_dp_link_test.c > +++ b/drivers/gpu/drm/i915/display/tests/intel_dp_link_test.c > @@ -1215,22 +1215,20 @@ static bool get_fallback_config(const struct test_config_table *expected_table, > struct kunit *test = expected_table->test; > const struct link_config_set *config_set = > get_fallback_configs_for_output_type(test, output_type); > + const struct intel_dp_link_config *config; > int i; > > i = lookup_config(config_set, target_config); > KUNIT_ASSERT_GE(test, i, 0); > > - for (i--; i >= 0; i--) { > - const struct intel_dp_link_config *config = > - &config_set->entries[i]; > + if (!i) > + return false; > > - assert_config_is_supported(expected_table, config); > - *fallback_config = *config; > + config = &config_set->entries[i - 1]; > + assert_config_is_supported(expected_table, config); > + *fallback_config = *config; > > - return true; > - } > - > - return false; > + return true; > } > > static bool get_target_config(const struct test_config_table *expected_table, > @@ -1240,19 +1238,17 @@ static bool get_target_config(const struct test_config_table *expected_table, > struct kunit *test = expected_table->test; > const struct link_config_set *config_set = > get_target_configs_for_output_type(test, output_type); > - int i; > + const struct intel_dp_link_config *config; > + int i = config_set->size - 1; > > - for (i = config_set->size - 1; i >= 0; i--) { > - const struct intel_dp_link_config *config = > - &config_set->entries[i]; > + if (i < 0) > + return false; > > - assert_config_is_supported(expected_table, config); > - *target = *config; > + config = &config_set->entries[i]; > + assert_config_is_supported(expected_table, config); > + *target = *config; > > - return true; > - } > - > - return false; > + return true; > } > > static void test_fallback_seq(struct kunit *test, > -- > 2.53.0 > >