[PATCH] drm/virtio: fix NULL pointer dereference in virtio_gpu_conn_get_modes

Chia-I Wu olvaffe at gmail.com
Thu Mar 24 19:54:07 UTC 2022


On Wed, Mar 23, 2022 at 4:01 AM Liu Zixian <liuzixian4 at huawei.com> wrote:
> diff --git a/drivers/gpu/drm/virtio/virtgpu_display.c b/drivers/gpu/drm/virtio/virtgpu_display.c
> index 5b00310ac..f73352e7b 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_display.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_display.c
> @@ -179,6 +179,8 @@ static int virtio_gpu_conn_get_modes(struct drm_connector *connector)
>                 DRM_DEBUG("add mode: %dx%d\n", width, height);
>                 mode = drm_cvt_mode(connector->dev, width, height, 60,
>                                     false, false, false);
> +               if (!mode)
> +                       return count;
>                 mode->type |= DRM_MODE_TYPE_PREFERRED;
>                 drm_mode_probed_add(connector, mode);
>                 count++;
Can we avoid early return here?  Something like

  mode = drm_cvt_mode(...);
  if (mode) {
    DRM_DEBUG("add mode: %dx%d\n", width, height);
    mode->type |= DRM_MODE_TYPE_PREFERRED
    drm_mode_probed_add(connector, mode);
    count++;
  }

is more future proof.

> --
> 2.33.0
>


More information about the dri-devel mailing list