Skip to contentSkip to conversation

drm/i2c/ch7006: fix a possible null pointer dereference

PATCH New Ma Ke 1 participant 1 message Oct 10, 2023

Subsystems (2)
lore
Share & tools
lore

Ma Ke

author
#0 lore raw

PATCH v2 1/1 drm/i2c/ch7006: fix a possible null pointer dereference

In ch7006_encoder_get_modes(), 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.

---
 drivers/gpu/drm/i2c/ch7006_drv.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/i2c/ch7006_drv.c +5 -2
index 131512a5f3bd..619f626c8371 100644
@@ -229,6 +229,7 @@ static int ch7006_encoder_get_modes(struct drm_encoder *encoder,
 {
 	struct ch7006_priv *priv = to_ch7006_priv(encoder);
 	const struct ch7006_mode *mode;
+	struct drm_display_mode *encoder_mode;
 	int n = 0;
 
 	for (mode = ch7006_modes; mode->mode.clock; mode++) {
@@ -236,8 +237,10 @@ static int ch7006_encoder_get_modes(struct drm_encoder *encoder,
 		    ~mode->valid_norms & 1<<priv->norm)
 			continue;
 
-		drm_mode_probed_add(connector,
-				drm_mode_duplicate(encoder->dev, &mode->mode));
+		encoder_mode = drm_mode_duplicate(encoder->dev, &mode->mode);
+		if (!encoder_mode)
+			continue;
+		drm_mode_probed_add(connector, encoder_mode);
 
 		n++;
 	}
Signature · 1 line
2.37.2