mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 10:00:17 +00:00
drm/vc4: tests: Stop allocating the state in test init
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: 30188df0c3 ("drm/tests: Drop drm_kunit_helper_acquire_ctx_alloc()")
Reviewed-by: Maíra Canal <mcanal@igalia.com>
Link: https://lore.kernel.org/r/20250403-drm-vc4-kunit-failures-v2-3-e09195cc8840@kernel.org
Signed-off-by: Maxime Ripard <mripard@kernel.org>
This commit is contained in:
@@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
struct pv_muxing_priv {
|
struct pv_muxing_priv {
|
||||||
struct vc4_dev *vc4;
|
struct vc4_dev *vc4;
|
||||||
struct drm_atomic_state *state;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool check_fifo_conflict(struct kunit *test,
|
static bool check_fifo_conflict(struct kunit *test,
|
||||||
@@ -677,10 +676,19 @@ static void drm_vc4_test_pv_muxing(struct kunit *test)
|
|||||||
{
|
{
|
||||||
const struct pv_muxing_param *params = test->param_value;
|
const struct pv_muxing_param *params = test->param_value;
|
||||||
const struct pv_muxing_priv *priv = test->priv;
|
const struct pv_muxing_priv *priv = test->priv;
|
||||||
struct drm_atomic_state *state = priv->state;
|
struct drm_modeset_acquire_ctx ctx;
|
||||||
|
struct drm_atomic_state *state;
|
||||||
|
struct drm_device *drm;
|
||||||
|
struct vc4_dev *vc4;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
drm_modeset_acquire_init(&ctx, 0);
|
||||||
|
|
||||||
|
vc4 = priv->vc4;
|
||||||
|
drm = &vc4->base;
|
||||||
|
state = drm_kunit_helper_atomic_state_alloc(test, drm, &ctx);
|
||||||
|
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, state);
|
||||||
for (i = 0; i < params->nencoders; i++) {
|
for (i = 0; i < params->nencoders; i++) {
|
||||||
enum vc4_encoder_type enc_type = params->encoders[i];
|
enum vc4_encoder_type enc_type = params->encoders[i];
|
||||||
|
|
||||||
@@ -700,16 +708,29 @@ static void drm_vc4_test_pv_muxing(struct kunit *test)
|
|||||||
KUNIT_EXPECT_TRUE(test, check_channel_for_encoder(test, state, enc_type,
|
KUNIT_EXPECT_TRUE(test, check_channel_for_encoder(test, state, enc_type,
|
||||||
params->check_fn));
|
params->check_fn));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drm_modeset_drop_locks(&ctx);
|
||||||
|
drm_modeset_acquire_fini(&ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void drm_vc4_test_pv_muxing_invalid(struct kunit *test)
|
static void drm_vc4_test_pv_muxing_invalid(struct kunit *test)
|
||||||
{
|
{
|
||||||
const struct pv_muxing_param *params = test->param_value;
|
const struct pv_muxing_param *params = test->param_value;
|
||||||
const struct pv_muxing_priv *priv = test->priv;
|
const struct pv_muxing_priv *priv = test->priv;
|
||||||
struct drm_atomic_state *state = priv->state;
|
struct drm_modeset_acquire_ctx ctx;
|
||||||
|
struct drm_atomic_state *state;
|
||||||
|
struct drm_device *drm;
|
||||||
|
struct vc4_dev *vc4;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
drm_modeset_acquire_init(&ctx, 0);
|
||||||
|
|
||||||
|
vc4 = priv->vc4;
|
||||||
|
drm = &vc4->base;
|
||||||
|
state = drm_kunit_helper_atomic_state_alloc(test, drm, &ctx);
|
||||||
|
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, state);
|
||||||
|
|
||||||
for (i = 0; i < params->nencoders; i++) {
|
for (i = 0; i < params->nencoders; i++) {
|
||||||
enum vc4_encoder_type enc_type = params->encoders[i];
|
enum vc4_encoder_type enc_type = params->encoders[i];
|
||||||
|
|
||||||
@@ -719,14 +740,15 @@ static void drm_vc4_test_pv_muxing_invalid(struct kunit *test)
|
|||||||
|
|
||||||
ret = drm_atomic_check_only(state);
|
ret = drm_atomic_check_only(state);
|
||||||
KUNIT_EXPECT_LT(test, ret, 0);
|
KUNIT_EXPECT_LT(test, ret, 0);
|
||||||
|
|
||||||
|
drm_modeset_drop_locks(&ctx);
|
||||||
|
drm_modeset_acquire_fini(&ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vc4_pv_muxing_test_init(struct kunit *test)
|
static int vc4_pv_muxing_test_init(struct kunit *test)
|
||||||
{
|
{
|
||||||
const struct pv_muxing_param *params = test->param_value;
|
const struct pv_muxing_param *params = test->param_value;
|
||||||
struct drm_modeset_acquire_ctx ctx;
|
|
||||||
struct pv_muxing_priv *priv;
|
struct pv_muxing_priv *priv;
|
||||||
struct drm_device *drm;
|
|
||||||
struct vc4_dev *vc4;
|
struct vc4_dev *vc4;
|
||||||
|
|
||||||
priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL);
|
priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL);
|
||||||
@@ -737,15 +759,6 @@ static int vc4_pv_muxing_test_init(struct kunit *test)
|
|||||||
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, vc4);
|
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, vc4);
|
||||||
priv->vc4 = vc4;
|
priv->vc4 = vc4;
|
||||||
|
|
||||||
drm_modeset_acquire_init(&ctx, 0);
|
|
||||||
|
|
||||||
drm = &vc4->base;
|
|
||||||
priv->state = drm_kunit_helper_atomic_state_alloc(test, drm, &ctx);
|
|
||||||
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->state);
|
|
||||||
|
|
||||||
drm_modeset_drop_locks(&ctx);
|
|
||||||
drm_modeset_acquire_fini(&ctx);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user