summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGong Yuanjun <ruc_gongyuanjun@163.com>2022-05-17 17:57:00 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-06-14 18:12:01 +0200
commit28fd384c78d7d8ed8af0d086d778c3e438ba7f60 (patch)
treee131dc51164872fc81980a03339f389eeb001b96
parent9223144fdd64582d61edab35fee7174135ef2fad (diff)
downloadlinux-stable-28fd384c78d7d8ed8af0d086d778c3e438ba7f60.tar.gz
linux-stable-28fd384c78d7d8ed8af0d086d778c3e438ba7f60.tar.bz2
linux-stable-28fd384c78d7d8ed8af0d086d778c3e438ba7f60.zip
drm/radeon: fix a possible null pointer dereference
[ Upstream commit a2b28708b645c5632dc93669ab06e97874c8244f ] In radeon_fp_native_mode(), the return value of drm_mode_duplicate() is assigned to mode, which will lead to a NULL pointer dereference on failure of drm_mode_duplicate(). Add a check to avoid npd. The failure status of drm_cvt_mode() on the other path is checked too. Signed-off-by: Gong Yuanjun <ruc_gongyuanjun@163.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--drivers/gpu/drm/radeon/radeon_connectors.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/drivers/gpu/drm/radeon/radeon_connectors.c b/drivers/gpu/drm/radeon/radeon_connectors.c
index bc63f4cecf5d..ca6ccd69424e 100644
--- a/drivers/gpu/drm/radeon/radeon_connectors.c
+++ b/drivers/gpu/drm/radeon/radeon_connectors.c
@@ -477,6 +477,8 @@ static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encode
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);
@@ -491,6 +493,8 @@ static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encode
* 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);
}