diff mbox series

[v2,5/6] drm/vkms: Switch to managed for CRTC

Message ID 20240827-google-vkms-managed-v2-5-f41104553aeb@bootlin.com (mailing list archive)
State New, archived
Headers show
Series drm/vkms: Switch all vkms object to DRM managed objects | expand

Commit Message

Louis Chauvet Aug. 27, 2024, 9:57 a.m. UTC
The current VKMS driver uses non-managed function to create CRTCs. It
is not an issue yet, but in order to support multiple devices easily,
convert this code to use drm and device managed helpers.

Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
 drivers/gpu/drm/vkms/vkms_crtc.c      | 40 +++++++++++++-------
 drivers/gpu/drm/vkms/vkms_drv.c       |  9 -----
 drivers/gpu/drm/vkms/vkms_drv.h       |  7 ++--
 drivers/gpu/drm/vkms/vkms_output.c    | 69 +++++++++++++++--------------------
 drivers/gpu/drm/vkms/vkms_writeback.c | 14 +++----
 5 files changed, 65 insertions(+), 74 deletions(-)

Comments

kernel test robot Aug. 30, 2024, 9:37 p.m. UTC | #1
Hi Louis,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 071d583e01c88272f6ff216d4f867f8f35e94d7d]

url:    https://github.com/intel-lab-lkp/linux/commits/Louis-Chauvet/drm-vkms-Switch-to-managed-for-connector/20240827-180427
base:   071d583e01c88272f6ff216d4f867f8f35e94d7d
patch link:    https://lore.kernel.org/r/20240827-google-vkms-managed-v2-5-f41104553aeb%40bootlin.com
patch subject: [PATCH v2 5/6] drm/vkms: Switch to managed for CRTC
config: i386-buildonly-randconfig-004-20240831 (https://download.01.org/0day-ci/archive/20240831/202408310524.JPBkb81E-lkp@intel.com/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240831/202408310524.JPBkb81E-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202408310524.JPBkb81E-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/gpu/drm/vkms/vkms_output.c:58:6: warning: variable 'cursor' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
      58 |         if (vkmsdev->config->cursor) {
         |             ^~~~~~~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/vkms/vkms_output.c:65:10: note: uninitialized use occurs here
      65 |                               cursor ? &cursor->base : NULL);
         |                               ^~~~~~
   drivers/gpu/drm/vkms/vkms_output.c:58:2: note: remove the 'if' if its condition is always true
      58 |         if (vkmsdev->config->cursor) {
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/vkms/vkms_output.c:32:37: note: initialize the variable 'cursor' to silence this warning
      32 |         struct vkms_plane *primary, *cursor, *overlay = NULL;
         |                                            ^
         |                                             = NULL
   1 warning generated.


vim +58 drivers/gpu/drm/vkms/vkms_output.c

d16489307a52f0 Rodrigo Siqueira    2018-07-11  29  
e9d85f731de06a Rodrigo Siqueira    2019-06-25  30  int vkms_output_init(struct vkms_device *vkmsdev, int index)
854502fa0a38dc Rodrigo Siqueira    2018-05-16  31  {
2abd7e59001123 Louis Chauvet       2024-08-27  32  	struct vkms_plane *primary, *cursor, *overlay = NULL;
854502fa0a38dc Rodrigo Siqueira    2018-05-16  33  	struct drm_device *dev = &vkmsdev->drm;
a12934d3402c04 Louis Chauvet       2024-08-27  34  	struct drm_connector *connector;
e3b4c152118a04 Louis Chauvet       2024-08-27  35  	struct drm_encoder *encoder;
2abd7e59001123 Louis Chauvet       2024-08-27  36  	struct vkms_crtc *crtc;
df2d385cb4132e José Expósito       2022-01-07  37  	unsigned int n;
2abd7e59001123 Louis Chauvet       2024-08-27  38  	int ret;
854502fa0a38dc Rodrigo Siqueira    2018-05-16  39  
2abd7e59001123 Louis Chauvet       2024-08-27  40  	/*
2abd7e59001123 Louis Chauvet       2024-08-27  41  	 * Initialize used plane. One primary plane is required to perform the composition.
2abd7e59001123 Louis Chauvet       2024-08-27  42  	 *
2abd7e59001123 Louis Chauvet       2024-08-27  43  	 * The overlay and cursor planes are not mandatory, but can be used to perform complex
2abd7e59001123 Louis Chauvet       2024-08-27  44  	 * composition.
2abd7e59001123 Louis Chauvet       2024-08-27  45  	 */
e9d85f731de06a Rodrigo Siqueira    2019-06-25  46  	primary = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_PRIMARY, index);
854502fa0a38dc Rodrigo Siqueira    2018-05-16  47  	if (IS_ERR(primary))
854502fa0a38dc Rodrigo Siqueira    2018-05-16  48  		return PTR_ERR(primary);
854502fa0a38dc Rodrigo Siqueira    2018-05-16  49  
310e506c06e495 Melissa Wen         2021-04-24  50  	if (vkmsdev->config->overlay) {
df2d385cb4132e José Expósito       2022-01-07  51  		for (n = 0; n < NUM_OVERLAY_PLANES; n++) {
2abd7e59001123 Louis Chauvet       2024-08-27  52  			overlay = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_OVERLAY, index);
2abd7e59001123 Louis Chauvet       2024-08-27  53  			if (IS_ERR(overlay))
2abd7e59001123 Louis Chauvet       2024-08-27  54  				return PTR_ERR(overlay);
310e506c06e495 Melissa Wen         2021-04-24  55  		}
df2d385cb4132e José Expósito       2022-01-07  56  	}
310e506c06e495 Melissa Wen         2021-04-24  57  
2df7af93fdadb9 Sumera Priyadarsini 2021-01-12 @58  	if (vkmsdev->config->cursor) {
kernel test robot Aug. 30, 2024, 11:09 p.m. UTC | #2
Hi Louis,

kernel test robot noticed the following build errors:

[auto build test ERROR on 071d583e01c88272f6ff216d4f867f8f35e94d7d]

url:    https://github.com/intel-lab-lkp/linux/commits/Louis-Chauvet/drm-vkms-Switch-to-managed-for-connector/20240827-180427
base:   071d583e01c88272f6ff216d4f867f8f35e94d7d
patch link:    https://lore.kernel.org/r/20240827-google-vkms-managed-v2-5-f41104553aeb%40bootlin.com
patch subject: [PATCH v2 5/6] drm/vkms: Switch to managed for CRTC
config: i386-randconfig-141-20240831 (https://download.01.org/0day-ci/archive/20240831/202408310628.jJbxaMOR-lkp@intel.com/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240831/202408310628.jJbxaMOR-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202408310628.jJbxaMOR-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/gpu/drm/vkms/vkms_output.c:58:6: error: variable 'cursor' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
      58 |         if (vkmsdev->config->cursor) {
         |             ^~~~~~~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/vkms/vkms_output.c:65:10: note: uninitialized use occurs here
      65 |                               cursor ? &cursor->base : NULL);
         |                               ^~~~~~
   drivers/gpu/drm/vkms/vkms_output.c:58:2: note: remove the 'if' if its condition is always true
      58 |         if (vkmsdev->config->cursor) {
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/vkms/vkms_output.c:32:37: note: initialize the variable 'cursor' to silence this warning
      32 |         struct vkms_plane *primary, *cursor, *overlay = NULL;
         |                                            ^
         |                                             = NULL
   1 error generated.


vim +58 drivers/gpu/drm/vkms/vkms_output.c

d16489307a52f0 Rodrigo Siqueira    2018-07-11  29  
e9d85f731de06a Rodrigo Siqueira    2019-06-25  30  int vkms_output_init(struct vkms_device *vkmsdev, int index)
854502fa0a38dc Rodrigo Siqueira    2018-05-16  31  {
2abd7e59001123 Louis Chauvet       2024-08-27  32  	struct vkms_plane *primary, *cursor, *overlay = NULL;
854502fa0a38dc Rodrigo Siqueira    2018-05-16  33  	struct drm_device *dev = &vkmsdev->drm;
a12934d3402c04 Louis Chauvet       2024-08-27  34  	struct drm_connector *connector;
e3b4c152118a04 Louis Chauvet       2024-08-27  35  	struct drm_encoder *encoder;
2abd7e59001123 Louis Chauvet       2024-08-27  36  	struct vkms_crtc *crtc;
df2d385cb4132e José Expósito       2022-01-07  37  	unsigned int n;
2abd7e59001123 Louis Chauvet       2024-08-27  38  	int ret;
854502fa0a38dc Rodrigo Siqueira    2018-05-16  39  
2abd7e59001123 Louis Chauvet       2024-08-27  40  	/*
2abd7e59001123 Louis Chauvet       2024-08-27  41  	 * Initialize used plane. One primary plane is required to perform the composition.
2abd7e59001123 Louis Chauvet       2024-08-27  42  	 *
2abd7e59001123 Louis Chauvet       2024-08-27  43  	 * The overlay and cursor planes are not mandatory, but can be used to perform complex
2abd7e59001123 Louis Chauvet       2024-08-27  44  	 * composition.
2abd7e59001123 Louis Chauvet       2024-08-27  45  	 */
e9d85f731de06a Rodrigo Siqueira    2019-06-25  46  	primary = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_PRIMARY, index);
854502fa0a38dc Rodrigo Siqueira    2018-05-16  47  	if (IS_ERR(primary))
854502fa0a38dc Rodrigo Siqueira    2018-05-16  48  		return PTR_ERR(primary);
854502fa0a38dc Rodrigo Siqueira    2018-05-16  49  
310e506c06e495 Melissa Wen         2021-04-24  50  	if (vkmsdev->config->overlay) {
df2d385cb4132e José Expósito       2022-01-07  51  		for (n = 0; n < NUM_OVERLAY_PLANES; n++) {
2abd7e59001123 Louis Chauvet       2024-08-27  52  			overlay = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_OVERLAY, index);
2abd7e59001123 Louis Chauvet       2024-08-27  53  			if (IS_ERR(overlay))
2abd7e59001123 Louis Chauvet       2024-08-27  54  				return PTR_ERR(overlay);
310e506c06e495 Melissa Wen         2021-04-24  55  		}
df2d385cb4132e José Expósito       2022-01-07  56  	}
310e506c06e495 Melissa Wen         2021-04-24  57  
2df7af93fdadb9 Sumera Priyadarsini 2021-01-12 @58  	if (vkmsdev->config->cursor) {
diff mbox series

Patch

diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c
index 2bf733a1b9f0..ff55099c86ce 100644
--- a/drivers/gpu/drm/vkms/vkms_crtc.c
+++ b/drivers/gpu/drm/vkms/vkms_crtc.c
@@ -6,6 +6,7 @@ 
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_probe_helper.h>
 #include <drm/drm_vblank.h>
+#include <drm/drm_managed.h>
 
 #include "vkms_drv.h"
 
@@ -270,30 +271,41 @@  static const struct drm_crtc_helper_funcs vkms_crtc_helper_funcs = {
 	.atomic_disable	= vkms_crtc_atomic_disable,
 };
 
-int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
-		   struct drm_plane *primary, struct drm_plane *cursor)
+static void vkms_crtc_destroy_workqueue(struct drm_device *dev, void *raw_vkms_crtc)
 {
-	struct vkms_crtc *vkms_crtc = drm_crtc_to_vkms_crtc(crtc);
+	struct vkms_crtc *vkms_crtc = raw_vkms_crtc;
+
+	destroy_workqueue(vkms_crtc->composer_workq);
+}
+
+struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev, struct drm_plane *primary,
+				 struct drm_plane *cursor)
+{
+	struct drm_device *dev = &vkmsdev->drm;
+	struct vkms_crtc *vkms_crtc;
 	int ret;
 
-	ret = drmm_crtc_init_with_planes(dev, crtc, primary, cursor,
-					 &vkms_crtc_funcs, NULL);
-	if (ret) {
-		DRM_ERROR("Failed to init CRTC\n");
-		return ret;
+	vkms_crtc = drmm_crtc_alloc_with_planes(dev, struct vkms_crtc, base, primary, cursor,
+						&vkms_crtc_funcs, NULL);
+	if (IS_ERR(vkms_crtc)) {
+		DRM_DEV_ERROR(vkmsdev->drm.dev, "Failed to init CRTC\n");
+		return vkms_crtc;
 	}
+	drm_crtc_helper_add(&vkms_crtc->base, &vkms_crtc_helper_funcs);
 
-	drm_crtc_helper_add(crtc, &vkms_crtc_helper_funcs);
-
-	drm_mode_crtc_set_gamma_size(crtc, VKMS_LUT_SIZE);
-	drm_crtc_enable_color_mgmt(crtc, 0, false, VKMS_LUT_SIZE);
+	drm_mode_crtc_set_gamma_size(&vkms_crtc->base, VKMS_LUT_SIZE);
+	drm_crtc_enable_color_mgmt(&vkms_crtc->base, 0, false, VKMS_LUT_SIZE);
 
 	spin_lock_init(&vkms_crtc->lock);
 	spin_lock_init(&vkms_crtc->composer_lock);
 
 	vkms_crtc->composer_workq = alloc_ordered_workqueue("vkms_composer", 0);
 	if (!vkms_crtc->composer_workq)
-		return -ENOMEM;
+		return ERR_PTR(-ENOMEM);
+
+	ret = drmm_add_action_or_reset(dev, vkms_crtc_destroy_workqueue, vkms_crtc);
+	if (ret)
+		return ERR_PTR(ret);
 
-	return ret;
+	return vkms_crtc;
 }
diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c
index f2818374f5c9..5282f71b50a6 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.c
+++ b/drivers/gpu/drm/vkms/vkms_drv.c
@@ -53,14 +53,6 @@  MODULE_PARM_DESC(enable_overlay, "Enable/Disable overlay support");
 
 DEFINE_DRM_GEM_FOPS(vkms_driver_fops);
 
-static void vkms_release(struct drm_device *dev)
-{
-	struct vkms_device *vkms = drm_device_to_vkms_device(dev);
-
-	if (vkms->crtc.composer_workq)
-		destroy_workqueue(vkms->crtc.composer_workq);
-}
-
 static void vkms_atomic_commit_tail(struct drm_atomic_state *old_state)
 {
 	struct drm_device *dev = old_state->dev;
@@ -109,7 +101,6 @@  static const struct drm_debugfs_info vkms_config_debugfs_list[] = {
 
 static const struct drm_driver vkms_driver = {
 	.driver_features	= DRIVER_MODESET | DRIVER_ATOMIC | DRIVER_GEM,
-	.release		= vkms_release,
 	.fops			= &vkms_driver_fops,
 	DRM_GEM_SHMEM_DRIVER_OPS,
 
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
index 3501cd9401d5..cff2e0686c04 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -126,7 +126,6 @@  struct vkms_config {
 struct vkms_device {
 	struct drm_device drm;
 	struct platform_device *platform;
-	struct vkms_crtc crtc;
 	const struct vkms_config *config;
 };
 
@@ -143,8 +142,8 @@  struct vkms_device {
 	container_of(target, struct vkms_plane_state, base.base)
 
 /* CRTC */
-int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
-		   struct drm_plane *primary, struct drm_plane *cursor);
+struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev, struct drm_plane *primary,
+				 struct drm_plane *cursor);
 
 int vkms_output_init(struct vkms_device *vkmsdev, int index);
 
@@ -165,6 +164,6 @@  void vkms_compose_row(struct line_buffer *stage_buffer, struct vkms_plane_state
 void vkms_writeback_row(struct vkms_writeback_job *wb, const struct line_buffer *src_buffer, int y);
 
 /* Writeback */
-int vkms_enable_writeback_connector(struct vkms_device *vkmsdev);
+int vkms_enable_writeback_connector(struct vkms_device *vkmsdev, struct vkms_crtc *vkms_crtc);
 
 #endif /* _VKMS_DRV_H_ */
diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c
index cd506dcfd50f..0c585e48fa01 100644
--- a/drivers/gpu/drm/vkms/vkms_output.c
+++ b/drivers/gpu/drm/vkms/vkms_output.c
@@ -27,42 +27,31 @@  static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = {
 	.get_modes    = vkms_conn_get_modes,
 };
 
-static int vkms_add_overlay_plane(struct vkms_device *vkmsdev, int index,
-				  struct drm_crtc *crtc)
-{
-	struct vkms_plane *overlay;
-
-	overlay = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_OVERLAY, index);
-	if (IS_ERR(overlay))
-		return PTR_ERR(overlay);
-
-	if (!overlay->base.possible_crtcs)
-		overlay->base.possible_crtcs = drm_crtc_mask(crtc);
-
-	return 0;
-}
-
 int vkms_output_init(struct vkms_device *vkmsdev, int index)
 {
-	struct vkms_crtc *vkms_crtc = &vkmsdev->crtc;
+	struct vkms_plane *primary, *cursor, *overlay = NULL;
 	struct drm_device *dev = &vkmsdev->drm;
 	struct drm_connector *connector;
 	struct drm_encoder *encoder;
-	struct drm_crtc *crtc = &vkms_crtc->base;
-	struct vkms_plane *primary, *cursor = NULL;
-	int ret;
-	int writeback;
+	struct vkms_crtc *crtc;
 	unsigned int n;
+	int ret;
 
+	/*
+	 * Initialize used plane. One primary plane is required to perform the composition.
+	 *
+	 * The overlay and cursor planes are not mandatory, but can be used to perform complex
+	 * composition.
+	 */
 	primary = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_PRIMARY, index);
 	if (IS_ERR(primary))
 		return PTR_ERR(primary);
 
 	if (vkmsdev->config->overlay) {
 		for (n = 0; n < NUM_OVERLAY_PLANES; n++) {
-			ret = vkms_add_overlay_plane(vkmsdev, index, crtc);
-			if (ret)
-				return ret;
+			overlay = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_OVERLAY, index);
+			if (IS_ERR(overlay))
+				return PTR_ERR(overlay);
 		}
 	}
 
@@ -72,22 +61,24 @@  int vkms_output_init(struct vkms_device *vkmsdev, int index)
 			return PTR_ERR(cursor);
 	}
 
-	ret = vkms_crtc_init(dev, crtc, &primary->base, &cursor->base);
-	if (ret)
-		return ret;
+	crtc = vkms_crtc_init(vkmsdev, &primary->base,
+			      cursor ? &cursor->base : NULL);
+	if (IS_ERR(crtc)) {
+		DRM_ERROR("Failed to allocate CRTC\n");
+		return PTR_ERR(crtc);
+	}
 
 	connector = drmm_kzalloc(dev, sizeof(*connector), GFP_KERNEL);
 	if (!connector) {
 		DRM_ERROR("Failed to allocate connector\n");
-		ret = -ENOMEM;
-		goto err_connector;
+		return -ENOMEM;
 	}
 
 	ret = drmm_connector_init(dev, connector, &vkms_connector_funcs,
 				  DRM_MODE_CONNECTOR_VIRTUAL, NULL);
 	if (ret) {
 		DRM_ERROR("Failed to init connector\n");
-		goto err_connector;
+		return ret;
 	}
 
 	drm_connector_helper_add(connector, &vkms_conn_helper_funcs);
@@ -95,34 +86,34 @@  int vkms_output_init(struct vkms_device *vkmsdev, int index)
 	encoder = drmm_kzalloc(dev, sizeof(*encoder), GFP_KERNEL);
 	if (!encoder) {
 		DRM_ERROR("Failed to allocate encoder\n");
-		ret = -ENOMEM;
-		goto err_connector;
+		return -ENOMEM;
 	}
 
 	ret = drmm_encoder_init(dev, encoder, NULL, DRM_MODE_ENCODER_VIRTUAL, NULL);
 	if (ret) {
 		DRM_ERROR("Failed to init encoder\n");
-		goto err_connector;
+		return ret;
 	}
-	encoder->possible_crtcs = 1;
 
+	encoder->possible_crtcs = drm_crtc_mask(&crtc->base);
+
+	/* Attach the encoder and the connector */
 	ret = drm_connector_attach_encoder(connector, encoder);
 	if (ret) {
 		DRM_ERROR("Failed to attach connector to encoder\n");
 		return ret;
 	}
 
+	/* Initialize the writeback component */
 	if (vkmsdev->config->writeback) {
-		writeback = vkms_enable_writeback_connector(vkmsdev);
-		if (writeback)
+		ret = vkms_enable_writeback_connector(vkmsdev, crtc);
+		if (ret) {
 			DRM_ERROR("Failed to init writeback connector\n");
+			return ret;
+		}
 	}
 
 	drm_mode_config_reset(dev);
 
 	return 0;
-
-err_connector:
-	drm_crtc_cleanup(crtc);
-	return ret;
 }
diff --git a/drivers/gpu/drm/vkms/vkms_writeback.c b/drivers/gpu/drm/vkms/vkms_writeback.c
index e055ad41241b..18aed20cd733 100644
--- a/drivers/gpu/drm/vkms/vkms_writeback.c
+++ b/drivers/gpu/drm/vkms/vkms_writeback.c
@@ -106,7 +106,7 @@  static void vkms_wb_cleanup_job(struct drm_writeback_connector *connector,
 				struct drm_writeback_job *job)
 {
 	struct vkms_writeback_job *vkmsjob = job->priv;
-	struct vkms_device *vkmsdev;
+	struct vkms_crtc *vkms_crtc = container_of(connector, struct vkms_crtc, wb_connector);
 
 	if (!job->fb)
 		return;
@@ -115,8 +115,7 @@  static void vkms_wb_cleanup_job(struct drm_writeback_connector *connector,
 
 	drm_framebuffer_put(vkmsjob->wb_frame_info.fb);
 
-	vkmsdev = drm_device_to_vkms_device(job->fb->dev);
-	vkms_set_composer(&vkmsdev->crtc, false);
+	vkms_set_composer(vkms_crtc, false);
 	kfree(vkmsjob);
 }
 
@@ -125,8 +124,7 @@  static void vkms_wb_atomic_commit(struct drm_connector *conn,
 {
 	struct drm_connector_state *connector_state = drm_atomic_get_new_connector_state(state,
 											 conn);
-	struct vkms_device *vkmsdev = drm_device_to_vkms_device(conn->dev);
-	struct vkms_crtc *vkms_crtc = &vkmsdev->crtc;
+	struct vkms_crtc *vkms_crtc = drm_crtc_to_vkms_crtc(connector_state->crtc);
 	struct drm_writeback_connector *wb_conn = &vkms_crtc->wb_connector;
 	struct drm_connector_state *conn_state = wb_conn->base.state;
 	struct vkms_crtc_state *crtc_state = vkms_crtc->composer_state;
@@ -140,7 +138,7 @@  static void vkms_wb_atomic_commit(struct drm_connector *conn,
 	if (!conn_state)
 		return;
 
-	vkms_set_composer(&vkmsdev->crtc, true);
+	vkms_set_composer(vkms_crtc, true);
 
 	active_wb = conn_state->writeback_job->priv;
 	wb_frame_info = &active_wb->wb_frame_info;
@@ -168,9 +166,9 @@  static const struct drm_connector_helper_funcs vkms_wb_conn_helper_funcs = {
 	.atomic_check = vkms_wb_atomic_check,
 };
 
-int vkms_enable_writeback_connector(struct vkms_device *vkmsdev)
+int vkms_enable_writeback_connector(struct vkms_device *vkmsdev, struct vkms_crtc *vkms_crtc)
 {
-	struct drm_writeback_connector *wb = &vkmsdev->crtc.wb_connector;
+	struct drm_writeback_connector *wb = &vkms_crtc->wb_connector;
 
 	drm_connector_helper_add(&wb->base, &vkms_wb_conn_helper_funcs);