The VC4 mock helpers allocate the CRTC, encoders and connectors using a
call to kunit_kzalloc(), but the DRM device they are attache to survives
for longer than the test itself which leads to use-after-frees reported
by KASAN.
Switch to drmm_kzalloc to tie the lifetime of these objects to the main
DRM device.
Fixes: f759f5b53f
("drm/vc4: tests: Introduce a mocking infrastructure")
Reported-by: Linux Kernel Functional Testing <lkft@linaro.org>
Closes: https://lore.kernel.org/all/CA+G9fYvJA2HGqzR9LGgq63v0SKaUejHAE6f7+z9cwWN-ourJ_g@mail.gmail.com/
Tested-by: Anders Roxell <anders.roxell@linaro.org>
Reviewed-by: Maíra Canal <mcanal@igalia.com>
Signed-off-by: Maxime Ripard <mripard@kernel.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20231024105640.352752-1-mripard@kernel.org
41 lines
1 KiB
C
41 lines
1 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include <drm/drm_atomic_state_helper.h>
|
|
#include <drm/drm_modeset_helper_vtables.h>
|
|
|
|
#include <kunit/test.h>
|
|
|
|
#include "vc4_mock.h"
|
|
|
|
static const struct drm_crtc_helper_funcs vc4_dummy_crtc_helper_funcs = {
|
|
.atomic_check = vc4_crtc_atomic_check,
|
|
};
|
|
|
|
static const struct drm_crtc_funcs vc4_dummy_crtc_funcs = {
|
|
.atomic_destroy_state = vc4_crtc_destroy_state,
|
|
.atomic_duplicate_state = vc4_crtc_duplicate_state,
|
|
.reset = vc4_crtc_reset,
|
|
};
|
|
|
|
struct vc4_dummy_crtc *vc4_mock_pv(struct kunit *test,
|
|
struct drm_device *drm,
|
|
struct drm_plane *plane,
|
|
const struct vc4_crtc_data *data)
|
|
{
|
|
struct vc4_dummy_crtc *dummy_crtc;
|
|
struct vc4_crtc *vc4_crtc;
|
|
int ret;
|
|
|
|
dummy_crtc = drmm_kzalloc(drm, sizeof(*dummy_crtc), GFP_KERNEL);
|
|
KUNIT_ASSERT_NOT_NULL(test, dummy_crtc);
|
|
|
|
vc4_crtc = &dummy_crtc->crtc;
|
|
ret = __vc4_crtc_init(drm, NULL,
|
|
vc4_crtc, data, plane,
|
|
&vc4_dummy_crtc_funcs,
|
|
&vc4_dummy_crtc_helper_funcs,
|
|
false);
|
|
KUNIT_ASSERT_EQ(test, ret, 0);
|
|
|
|
return dummy_crtc;
|
|
}
|