drm/amdgpu: Fix a NULL pointer dereference in amdgpu_connector_lcd_native_mode()
authorjsg <jsg@openbsd.org>
Thu, 27 Jan 2022 22:41:01 +0000 (22:41 +0000)
committerjsg <jsg@openbsd.org>
Thu, 27 Jan 2022 22:41:01 +0000 (22:41 +0000)
From Zhou Qingyang
1e22b51876fa786c0b972e327ffb5cc686873cd1 in linux 5.15.y/5.15.17
b220110e4cd442156f36e1d9b4914bb9e87b0d00 in mainline linux

sys/dev/pci/drm/amd/amdgpu/amdgpu_connectors.c

index 0de66f5..df1f9b8 100644 (file)
@@ -387,6 +387,9 @@ amdgpu_connector_lcd_native_mode(struct drm_encoder *encoder)
            native_mode->vdisplay != 0 &&
            native_mode->clock != 0) {
                mode = drm_mode_duplicate(dev, native_mode);
+               if (!mode)
+                       return NULL;
+
                mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
                drm_mode_set_name(mode);
 
@@ -401,6 +404,9 @@ amdgpu_connector_lcd_native_mode(struct drm_encoder *encoder)
                 * simpler.
                 */
                mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false);
+               if (!mode)
+                       return NULL;
+
                mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
                DRM_DEBUG_KMS("Adding cvt approximation of native panel mode %s\n", mode->name);
        }