Skip to content

Commit 9491e0b

Browse files
mripardpelwell
authored andcommitted
drm/vc4: tests: Stop allocating the state in test init
commit 7e0351a upstream. The vc4-pv-muxing-combinations and vc5-pv-muxing-combinations test suites use a common test init function which, in part, allocates the drm atomic state the test will use. That allocation relies on drm_kunit_helper_atomic_state_alloc(), and thus requires a struct drm_modeset_acquire_ctx. This context will then be stored in the allocated state->acquire_ctx field. However, the context is local to the test init function, and is cleared as soon as drm_kunit_helper_atomic_state_alloc() is done. We thus end up with an dangling pointer to a cleared context in state->acquire_ctx for our test to consumes. We should really allocate the context and the state in the test functions, so we can also control when we're done with it. Fixes: 30188df ("drm/tests: Drop drm_kunit_helper_acquire_ctx_alloc()") Reviewed-by: Maíra Canal <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Maxime Ripard <[email protected]>
1 parent 2407ebf commit 9491e0b

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
struct pv_muxing_priv {
2222
struct vc4_dev *vc4;
23-
struct drm_atomic_state *state;
2423
};
2524

2625
static bool check_fifo_conflict(struct kunit *test,
@@ -758,10 +757,19 @@ static void drm_vc4_test_pv_muxing(struct kunit *test)
758757
{
759758
const struct pv_muxing_param *params = test->param_value;
760759
const struct pv_muxing_priv *priv = test->priv;
761-
struct drm_atomic_state *state = priv->state;
760+
struct drm_modeset_acquire_ctx ctx;
761+
struct drm_atomic_state *state;
762+
struct drm_device *drm;
763+
struct vc4_dev *vc4;
762764
unsigned int i;
763765
int ret;
764766

767+
drm_modeset_acquire_init(&ctx, 0);
768+
769+
vc4 = priv->vc4;
770+
drm = &vc4->base;
771+
state = drm_kunit_helper_atomic_state_alloc(test, drm, &ctx);
772+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, state);
765773
for (i = 0; i < params->nencoders; i++) {
766774
struct vc4_dummy_output *output;
767775
enum vc4_encoder_type enc_type = params->encoders[i];
@@ -782,16 +790,29 @@ static void drm_vc4_test_pv_muxing(struct kunit *test)
782790
KUNIT_EXPECT_TRUE(test, check_channel_for_encoder(test, state, enc_type,
783791
params->check_fn));
784792
}
793+
794+
drm_modeset_drop_locks(&ctx);
795+
drm_modeset_acquire_fini(&ctx);
785796
}
786797

787798
static void drm_vc4_test_pv_muxing_invalid(struct kunit *test)
788799
{
789800
const struct pv_muxing_param *params = test->param_value;
790801
const struct pv_muxing_priv *priv = test->priv;
791-
struct drm_atomic_state *state = priv->state;
802+
struct drm_modeset_acquire_ctx ctx;
803+
struct drm_atomic_state *state;
804+
struct drm_device *drm;
805+
struct vc4_dev *vc4;
792806
unsigned int i;
793807
int ret;
794808

809+
drm_modeset_acquire_init(&ctx, 0);
810+
811+
vc4 = priv->vc4;
812+
drm = &vc4->base;
813+
state = drm_kunit_helper_atomic_state_alloc(test, drm, &ctx);
814+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, state);
815+
795816
for (i = 0; i < params->nencoders; i++) {
796817
struct vc4_dummy_output *output;
797818
enum vc4_encoder_type enc_type = params->encoders[i];
@@ -802,14 +823,15 @@ static void drm_vc4_test_pv_muxing_invalid(struct kunit *test)
802823

803824
ret = drm_atomic_check_only(state);
804825
KUNIT_EXPECT_LT(test, ret, 0);
826+
827+
drm_modeset_drop_locks(&ctx);
828+
drm_modeset_acquire_fini(&ctx);
805829
}
806830

807831
static int vc4_pv_muxing_test_init(struct kunit *test)
808832
{
809833
const struct pv_muxing_param *params = test->param_value;
810-
struct drm_modeset_acquire_ctx ctx;
811834
struct pv_muxing_priv *priv;
812-
struct drm_device *drm;
813835
struct vc4_dev *vc4;
814836

815837
priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL);
@@ -820,15 +842,6 @@ static int vc4_pv_muxing_test_init(struct kunit *test)
820842
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, vc4);
821843
priv->vc4 = vc4;
822844

823-
drm_modeset_acquire_init(&ctx, 0);
824-
825-
drm = &vc4->base;
826-
priv->state = drm_kunit_helper_atomic_state_alloc(test, drm, &ctx);
827-
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->state);
828-
829-
drm_modeset_drop_locks(&ctx);
830-
drm_modeset_acquire_fini(&ctx);
831-
832845
return 0;
833846
}
834847

0 commit comments

Comments
 (0)