sti_bind() calls drm_dev_register() before
drm_mode_config_create_initial_state(), so the device is exposed to
userspace, through its device node and its connectors sysfs attributes,
while the plane, CRTC and connector states are still NULL. A process
opening the device in that window could then hit a NULL pointer
dereference.

Move drm_mode_config_create_initial_state() before drm_dev_register().

Fixes: 84601dbdea366 ("drm: sti: rework init sequence")
Reported-by: [email protected]
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Maxime Ripard <[email protected]>
---
 drivers/gpu/drm/sti/sti_drv.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/sti/sti_drv.c b/drivers/gpu/drm/sti/sti_drv.c
index 794badf199c9..7db8de8744a4 100644
--- a/drivers/gpu/drm/sti/sti_drv.c
+++ b/drivers/gpu/drm/sti/sti_drv.c
@@ -195,24 +195,22 @@ static int sti_bind(struct device *dev)
 
        ret = component_bind_all(ddev->dev, ddev);
        if (ret)
                goto err_cleanup;
 
-       ret = drm_dev_register(ddev, 0);
+       ret = drm_mode_config_create_initial_state(ddev);
        if (ret)
                goto err_cleanup;
 
-       ret = drm_mode_config_create_initial_state(ddev);
+       ret = drm_dev_register(ddev, 0);
        if (ret)
-               goto err_unregister;
+               goto err_cleanup;
 
        drm_client_setup(ddev, NULL);
 
        return 0;
 
-err_unregister:
-       drm_dev_unregister(ddev);
 err_cleanup:
        sti_cleanup(ddev);
 err_drm_dev_put:
        drm_dev_put(ddev);
        return ret;

-- 
2.56.1

Reply via email to