diff mbox series

drm/amdgpu: check for allocation failure in amdgpu_vkms_sw_init()

Message ID 20210806150518.GC15586@kili (mailing list archive)
State New, archived
Headers show
Series drm/amdgpu: check for allocation failure in amdgpu_vkms_sw_init() | expand

Commit Message

Dan Carpenter Aug. 6, 2021, 3:05 p.m. UTC
Check whether the kcalloc() fails and return -ENOMEM if it does.

Fixes: eeba0b9046fc ("drm/amdgpu: create amdgpu_vkms (v4)")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Christian König Aug. 6, 2021, 3:09 p.m. UTC | #1
Am 06.08.21 um 17:05 schrieb Dan Carpenter:
> Check whether the kcalloc() fails and return -ENOMEM if it does.
>
> Fixes: eeba0b9046fc ("drm/amdgpu: create amdgpu_vkms (v4)")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
> index 50bdc39733aa..ce982afeff91 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
> @@ -482,6 +482,8 @@ static int amdgpu_vkms_sw_init(void *handle)
>   		return r;
>   
>   	adev->amdgpu_vkms_output = kcalloc(adev->mode_info.num_crtc, sizeof(struct amdgpu_vkms_output), GFP_KERNEL);

Is the line above not a bit long?

> +	if (!adev->amdgpu_vkms_output)
> +		return -ENOMEM;
>   
>   	/* allocate crtcs, encoders, connectors */
>   	for (i = 0; i < adev->mode_info.num_crtc; i++) {
Alex Deucher Aug. 6, 2021, 7:57 p.m. UTC | #2
Applied.  Thanks!

Alex

On Fri, Aug 6, 2021 at 11:09 AM Christian König
<christian.koenig@amd.com> wrote:
>
> Am 06.08.21 um 17:05 schrieb Dan Carpenter:
> > Check whether the kcalloc() fails and return -ENOMEM if it does.
> >
> > Fixes: eeba0b9046fc ("drm/amdgpu: create amdgpu_vkms (v4)")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> Reviewed-by: Christian König <christian.koenig@amd.com>
>
> > ---
> >   drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 2 ++
> >   1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
> > index 50bdc39733aa..ce982afeff91 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
> > @@ -482,6 +482,8 @@ static int amdgpu_vkms_sw_init(void *handle)
> >               return r;
> >
> >       adev->amdgpu_vkms_output = kcalloc(adev->mode_info.num_crtc, sizeof(struct amdgpu_vkms_output), GFP_KERNEL);
>
> Is the line above not a bit long?
>
> > +     if (!adev->amdgpu_vkms_output)
> > +             return -ENOMEM;
> >
> >       /* allocate crtcs, encoders, connectors */
> >       for (i = 0; i < adev->mode_info.num_crtc; i++) {
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
index 50bdc39733aa..ce982afeff91 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
@@ -482,6 +482,8 @@  static int amdgpu_vkms_sw_init(void *handle)
 		return r;
 
 	adev->amdgpu_vkms_output = kcalloc(adev->mode_info.num_crtc, sizeof(struct amdgpu_vkms_output), GFP_KERNEL);
+	if (!adev->amdgpu_vkms_output)
+		return -ENOMEM;
 
 	/* allocate crtcs, encoders, connectors */
 	for (i = 0; i < adev->mode_info.num_crtc; i++) {