diff mbox series

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

Message ID 20241025073408.27481-2-zhangzekun11@huawei.com (mailing list archive)
State New, archived
Headers show
Series drm: Add a check to prevent NULL pointer dereference | expand

Commit Message

zhangzekun (A) Oct. 25, 2024, 7:34 a.m. UTC
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@huawei.com>
---
 drivers/gpu/drm/i2c/ch7006_drv.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Dmitry Baryshkov Oct. 31, 2024, 9:49 p.m. UTC | #1
On Fri, Oct 25, 2024 at 03:34:07PM +0800, Zhang Zekun wrote:
> 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@huawei.com>
> ---
>  drivers/gpu/drm/i2c/ch7006_drv.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 

Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
diff mbox series

Patch

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++;
 	}