Hi Carlos,
On 8/25/23 13:07, Carlos Eduardo Gallo Filho wrote:
The dev_private member of drm_device is deprecated and its use should
be avoided. Stop using it by embedding the drm_device onto a mock struct
with a void pointer like dev_private, using it instead.
Signed-off-by: Carlos Eduardo Gallo Filho <gcarlos@xxxxxxxxxxx>
---
drivers/gpu/drm/tests/drm_framebuffer_test.c | 29 +++++++++++++-------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c
index f759d9f3b76e..173d42b145ed 100644
--- a/drivers/gpu/drm/tests/drm_framebuffer_test.c
+++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c
@@ -317,11 +317,17 @@ static const struct drm_framebuffer_test drm_framebuffer_create_cases[] = {
},
};
+struct drm_mock {
+ struct drm_device dev;
+ void *private;
+};
Could we call it drm_device_mock or maybe drm_framebuffer_mock? I
believe that drm_mock its a bit generic.
Also, wouldn't be better to create a `int buffer_created` variable
instead of creating a `void *private`?
Best Regards,
- Maíra
+
static struct drm_framebuffer *fb_create_mock(struct drm_device *dev,
struct drm_file *file_priv,
const struct drm_mode_fb_cmd2 *mode_cmd)
{
- int *buffer_created = dev->dev_private;
+ struct drm_mock *mock = container_of(dev, typeof(*mock), dev);
+ int *buffer_created = mock->private;
*buffer_created = 1;
return ERR_PTR(-EINVAL);
}
@@ -332,16 +338,18 @@ static struct drm_mode_config_funcs mock_config_funcs = {
static int drm_framebuffer_test_init(struct kunit *test)
{
- struct drm_device *mock;
+ struct drm_mock *mock;
+ struct drm_device *dev;
mock = kunit_kzalloc(test, sizeof(*mock), GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mock);
+ dev = &mock->dev;
- mock->mode_config.min_width = MIN_WIDTH;
- mock->mode_config.max_width = MAX_WIDTH;
- mock->mode_config.min_height = MIN_HEIGHT;
- mock->mode_config.max_height = MAX_HEIGHT;
- mock->mode_config.funcs = &mock_config_funcs;
+ dev->mode_config.min_width = MIN_WIDTH;
+ dev->mode_config.max_width = MAX_WIDTH;
+ dev->mode_config.min_height = MIN_HEIGHT;
+ dev->mode_config.max_height = MAX_HEIGHT;
+ dev->mode_config.funcs = &mock_config_funcs;
test->priv = mock;
return 0;
@@ -350,11 +358,12 @@ static int drm_framebuffer_test_init(struct kunit *test)
static void drm_test_framebuffer_create(struct kunit *test)
{
const struct drm_framebuffer_test *params = test->param_value;
- struct drm_device *mock = test->priv;
+ struct drm_mock *mock = test->priv;
+ struct drm_device *dev = &mock->dev;
int buffer_created = 0;
- mock->dev_private = &buffer_created;
- drm_internal_framebuffer_create(mock, ¶ms->cmd, NULL);
+ mock->private = &buffer_created;
+ drm_internal_framebuffer_create(dev, ¶ms->cmd, NULL);
KUNIT_EXPECT_EQ(test, params->buffer_created, buffer_created);
}