To avoid having dangling pointers in struct vkms_config, remove all of them when the device is destroyed. Signed-off-by: Louis Chauvet <louis.chauvet@xxxxxxxxxxx> --- drivers/gpu/drm/vkms/vkms_config.c | 23 +++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_config.h | 3 ++- drivers/gpu/drm/vkms/vkms_drv.c | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c index a20644031ce923fad98d486a8bb2ec7859038dcd..8ac9cd52cc00f7c317f2514a73c3d2f3908b085b 100644 --- a/drivers/gpu/drm/vkms/vkms_config.c +++ b/drivers/gpu/drm/vkms/vkms_config.c @@ -167,6 +167,29 @@ struct vkms_config_connector *vkms_config_create_connector(struct vkms_config *v return vkms_config_connector; } +void vkms_config_disconnect_dev(struct vkms_config *vkms_config) +{ + struct vkms_config_connector *connector, *tmp_connector; + struct vkms_config_encoder *encoder, *tmp_encoder; + struct vkms_config_plane *plane, *tmp_plane; + struct vkms_config_crtc *crtc, *tmp_crtc; + + vkms_config->dev = NULL; + + list_for_each_entry_safe(connector, tmp_connector, &vkms_config->connectors, link) { + connector->connector = NULL; + } + list_for_each_entry_safe(encoder, tmp_encoder, &vkms_config->encoders, link) { + encoder->encoder = NULL; + } + list_for_each_entry_safe(plane, tmp_plane, &vkms_config->planes, link) { + plane->plane = NULL; + } + list_for_each_entry_safe(crtc, tmp_crtc, &vkms_config->crtcs, link) { + crtc->output = NULL; + } +} + void vkms_config_connector_update_status(struct vkms_config_connector *vkms_config_connector, enum drm_connector_status status) { diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h index 23f420291cfc0044ccb2be90688d021aab10c1c0..2e5d2aa34a4f039c738cb9ac5642f3c75df36ba7 100644 --- a/drivers/gpu/drm/vkms/vkms_config.h +++ b/drivers/gpu/drm/vkms/vkms_config.h @@ -109,10 +109,11 @@ struct vkms_config_connector { char edid_blob[PAGE_SIZE]; int edid_blob_len; - /* Internal usage */ + /* Set only when the device is enabled */ struct drm_connector *connector; }; +void vkms_config_disconnect_dev(struct vkms_config *vkms_config); void vkms_config_connector_update_status(struct vkms_config_connector *vkms_config_connector, enum drm_connector_status status); diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index 5f1958d59cc4c3102352599eee7a8e139fbb899c..afbd1fbe00d469bea8367096a3aa0ed07b66ed1a 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -240,7 +240,7 @@ void vkms_destroy(struct vkms_config *config) devres_release_group(&pdev->dev, NULL); platform_device_unregister(pdev); - config->dev = NULL; + vkms_config_disconnect_dev(config); } static void __exit vkms_exit(void) -- 2.47.1