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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux