qxl_modeset_init() calls qxl_create_monitors_object() early on: it
allocates, pins and vmaps the monitors_config_bo buffer object, and
points qdev->ram_header->monitors_config to its physical address.

If drm_vblank_init() fails later on, qxl_modeset_init() returns an
error and qxl_pci_probe() jumps to the unload label, which calls
qxl_device_fini(). qxl_gem_fini() then force-frees the still pinned
and mapped monitors_config_bo, and iounmap() unmaps the RAM header.

The devres cleanup of the DRM device later calls qxl_drm_release(),
which in turn calls qxl_modeset_fini() and
qxl_destroy_monitors_object(). Those write to the unmapped RAM header,
and unmap and unreference the freed buffer object.

Destroy the monitors object on the error path, so that
qxl_destroy_monitors_object() has nothing left to do when it runs
again during the device release.

It will also be needed when drm_mode_config_reset() gets replaced by
drm_mode_config_create_initial_state(), whose state allocation can
fail.

Fixes: e485883c815ee ("drm/qxl: Use vblank timer")
Reported-by: [email protected]
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Maxime Ripard <[email protected]>
---
 drivers/gpu/drm/qxl/qxl_display.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/qxl/qxl_display.c 
b/drivers/gpu/drm/qxl/qxl_display.c
index 204c47d61373..77fbf3c864cc 100644
--- a/drivers/gpu/drm/qxl/qxl_display.c
+++ b/drivers/gpu/drm/qxl/qxl_display.c
@@ -1308,14 +1308,18 @@ int qxl_modeset_init(struct qxl_device *qdev)
 
        qxl_display_read_client_monitors_config(qdev);
 
        ret = drm_vblank_init(&qdev->ddev, qxl_num_crtc);
        if (ret)
-               return ret;
+               goto destroy_monitors_object;
 
        drm_mode_config_reset(&qdev->ddev);
        return 0;
+
+destroy_monitors_object:
+       qxl_destroy_monitors_object(qdev);
+       return ret;
 }
 
 void qxl_modeset_fini(struct qxl_device *qdev)
 {
        if (qdev->dumb_shadow_bo) {

-- 
2.56.1

Reply via email to