drm: Fix potential null-ptr-deref due to drmm_mode_config_init()
authorjsg <jsg@openbsd.org>
Mon, 27 Mar 2023 03:21:12 +0000 (03:21 +0000)
committerjsg <jsg@openbsd.org>
Mon, 27 Mar 2023 03:21:12 +0000 (03:21 +0000)
From Shang XiaoJing
b14147464251f66e38fa39f0aae9780466db8610 in linux-6.1.y/6.1.16
834c23e4f798dcdc8af251b3c428ceef94741991 in mainline linux

sys/dev/pci/drm/drm_mode_config.c

index 682478a..b5d597a 100644 (file)
@@ -399,6 +399,8 @@ static void drm_mode_config_init_release(struct drm_device *dev, void *ptr)
  */
 int drmm_mode_config_init(struct drm_device *dev)
 {
+       int ret;
+
        rw_init(&dev->mode_config.mutex, "mcrwl");
        drm_modeset_lock_init(&dev->mode_config.connection_mutex);
        rw_init(&dev->mode_config.idr_mutex, "idrlk");
@@ -420,7 +422,11 @@ int drmm_mode_config_init(struct drm_device *dev)
        init_llist_head(&dev->mode_config.connector_free_list);
        INIT_WORK(&dev->mode_config.connector_free_work, drm_connector_free_work_fn);
 
-       drm_mode_create_standard_properties(dev);
+       ret = drm_mode_create_standard_properties(dev);
+       if (ret) {
+               drm_mode_config_cleanup(dev);
+               return ret;
+       }
 
        /* Just to be sure */
        dev->mode_config.num_fb = 0;