[PATCH 1/2] drm/i2c/ch7006: Add a check to prevent NULL pointer dereference

Zhang Zekun zhangzekun11 at huawei.com
Fri Oct 25 07:34:07 UTC 2024


drm_mode_duplicate() could return NULL due to lack of memory,
which will then call NULL pointer dereference. Add a check to
prevent it.

Fixes: 6ee738610f41 ("drm/nouveau: Add DRM driver for NVIDIA GPUs")
Signed-off-by: Zhang Zekun <zhangzekun11 at huawei.com>
---
 drivers/gpu/drm/i2c/ch7006_drv.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/i2c/ch7006_drv.c b/drivers/gpu/drm/i2c/ch7006_drv.c
index 131512a5f3bd..a2942f497c60 100644
--- a/drivers/gpu/drm/i2c/ch7006_drv.c
+++ b/drivers/gpu/drm/i2c/ch7006_drv.c
@@ -232,12 +232,16 @@ static int ch7006_encoder_get_modes(struct drm_encoder *encoder,
 	int n = 0;
 
 	for (mode = ch7006_modes; mode->mode.clock; mode++) {
+		struct drm_display_mode *new_mode;
+
 		if (~mode->valid_scales & 1<<priv->scale ||
 		    ~mode->valid_norms & 1<<priv->norm)
 			continue;
 
-		drm_mode_probed_add(connector,
-				drm_mode_duplicate(encoder->dev, &mode->mode));
+		new_mode = drm_mode_duplicate(encoder->dev, &mode->mode);
+		if (!new_mode)
+			continue;
+		drm_mode_probed_add(connector, new_mode);
 
 		n++;
 	}
-- 
2.17.1



More information about the dri-devel mailing list