diff mbox series

drm/qxl: Add check for drm_cvt_mode

Message ID 20240621071031.1987974-1-nichen@iscas.ac.cn (mailing list archive)
State New, archived
Headers show
Series drm/qxl: Add check for drm_cvt_mode | expand

Commit Message

Chen Ni June 21, 2024, 7:10 a.m. UTC
Add check for the return value of drm_cvt_mode() and return the error if
it fails in order to avoid NULL pointer dereference.

Fixes: 1b043677d4be ("drm/qxl: add qxl_add_mode helper function")
Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
---
 drivers/gpu/drm/qxl/qxl_display.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Heng Qi June 21, 2024, 8:48 a.m. UTC | #1
在 2024/6/21 下午3:10, Chen Ni 写道:
> Add check for the return value of drm_cvt_mode() and return the error if
> it fails in order to avoid NULL pointer dereference.
>
> Fixes: 1b043677d4be ("drm/qxl: add qxl_add_mode helper function")
> Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
> ---
>   drivers/gpu/drm/qxl/qxl_display.c | 3 +++
>   1 file changed, 3 insertions(+)
>
> diff --git a/drivers/gpu/drm/qxl/qxl_display.c b/drivers/gpu/drm/qxl/qxl_display.c
> index c6d35c33d5d6..86a5dea710c0 100644
> --- a/drivers/gpu/drm/qxl/qxl_display.c
> +++ b/drivers/gpu/drm/qxl/qxl_display.c
> @@ -236,6 +236,9 @@ static int qxl_add_mode(struct drm_connector *connector,
>   		return 0;
>   
>   	mode = drm_cvt_mode(dev, width, height, 60, false, false, false);
> +	if (!mode)
> +		return 0;
> +
>   	if (preferred)
>   		mode->type |= DRM_MODE_TYPE_PREFERRED;
>   	mode->hdisplay = width;

Reviewed-by: Heng Qi <hengqi@linux.alibaba.com>

Thanks.
Maxime Ripard June 26, 2024, 1:35 p.m. UTC | #2
On Fri, 21 Jun 2024 15:10:31 +0800, Chen Ni wrote:
> Add check for the return value of drm_cvt_mode() and return the error if
> it fails in order to avoid NULL pointer dereference.
> 
> 

Applied to misc/kernel.git (drm-misc-next).

Thanks!
Maxime
diff mbox series

Patch

diff --git a/drivers/gpu/drm/qxl/qxl_display.c b/drivers/gpu/drm/qxl/qxl_display.c
index c6d35c33d5d6..86a5dea710c0 100644
--- a/drivers/gpu/drm/qxl/qxl_display.c
+++ b/drivers/gpu/drm/qxl/qxl_display.c
@@ -236,6 +236,9 @@  static int qxl_add_mode(struct drm_connector *connector,
 		return 0;
 
 	mode = drm_cvt_mode(dev, width, height, 60, false, false, false);
+	if (!mode)
+		return 0;
+
 	if (preferred)
 		mode->type |= DRM_MODE_TYPE_PREFERRED;
 	mode->hdisplay = width;