All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][next] drm/amdgpu: Fix memory leak of object caps on error return paths
@ 2021-01-29 12:07 ` Colin King
  0 siblings, 0 replies; 6+ messages in thread
From: Colin King @ 2021-01-29 12:07 UTC (permalink / raw)
  To: Alex Deucher, Christian König, David Airlie, Daniel Vetter,
	Leo Liu, amd-gfx, dri-devel
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently there are three error return paths that don't kfree object
caps.  Fix this by performing the allocation of caps after the checks
and error return paths to avoid the premature allocation and memory
leaking.

Addresses-Coverity: ("Resource leak")
Fixes: 555fc7fbb2a2 ("drm/amdgpu: add INFO ioctl support for querying video caps")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index 84b666fcfaf6..730f4ac7487b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -988,10 +988,6 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 		struct drm_amdgpu_info_video_caps *caps;
 		int r;
 
-	        caps = kzalloc(sizeof(*caps), GFP_KERNEL);
-		if (!caps)
-			return -ENOMEM;
-
 		switch (info->video_cap.type) {
 		case AMDGPU_INFO_VIDEO_CAPS_DECODE:
 			r = amdgpu_asic_query_video_codecs(adev, false, &codecs);
@@ -1009,6 +1005,11 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 				      info->video_cap.type);
 			return -EINVAL;
 		}
+
+		caps = kzalloc(sizeof(*caps), GFP_KERNEL);
+		if (!caps)
+			return -ENOMEM;
+
 		for (i = 0; i < codecs->codec_count; i++) {
 			int idx = codecs->codec_array[i].codec_type;
 
-- 
2.29.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH][next] drm/amdgpu: Fix memory leak of object caps on error return paths
@ 2021-01-29 12:07 ` Colin King
  0 siblings, 0 replies; 6+ messages in thread
From: Colin King @ 2021-01-29 12:07 UTC (permalink / raw)
  To: Alex Deucher, Christian König, David Airlie, Daniel Vetter,
	Leo Liu, amd-gfx, dri-devel
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently there are three error return paths that don't kfree object
caps.  Fix this by performing the allocation of caps after the checks
and error return paths to avoid the premature allocation and memory
leaking.

Addresses-Coverity: ("Resource leak")
Fixes: 555fc7fbb2a2 ("drm/amdgpu: add INFO ioctl support for querying video caps")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index 84b666fcfaf6..730f4ac7487b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -988,10 +988,6 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 		struct drm_amdgpu_info_video_caps *caps;
 		int r;
 
-	        caps = kzalloc(sizeof(*caps), GFP_KERNEL);
-		if (!caps)
-			return -ENOMEM;
-
 		switch (info->video_cap.type) {
 		case AMDGPU_INFO_VIDEO_CAPS_DECODE:
 			r = amdgpu_asic_query_video_codecs(adev, false, &codecs);
@@ -1009,6 +1005,11 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 				      info->video_cap.type);
 			return -EINVAL;
 		}
+
+		caps = kzalloc(sizeof(*caps), GFP_KERNEL);
+		if (!caps)
+			return -ENOMEM;
+
 		for (i = 0; i < codecs->codec_count; i++) {
 			int idx = codecs->codec_array[i].codec_type;
 
-- 
2.29.2

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH][next] drm/amdgpu: Fix memory leak of object caps on error return paths
  2021-01-29 12:07 ` Colin King
  (?)
  (?)
@ 2021-01-29 19:28   ` Alex Deucher
  -1 siblings, 0 replies; 6+ messages in thread
From: Alex Deucher @ 2021-01-29 19:28 UTC (permalink / raw)
  To: Colin King
  Cc: Alex Deucher, Christian König, David Airlie, Daniel Vetter,
	Leo Liu, amd-gfx list, Maling list - DRI developers,
	kernel-janitors, LKML

On Fri, Jan 29, 2021 at 7:08 AM Colin King <colin.king@canonical.com> wrote:
>
> From: Colin Ian King <colin.king@canonical.com>
>
> Currently there are three error return paths that don't kfree object
> caps.  Fix this by performing the allocation of caps after the checks
> and error return paths to avoid the premature allocation and memory
> leaking.
>
> Addresses-Coverity: ("Resource leak")
> Fixes: 555fc7fbb2a2 ("drm/amdgpu: add INFO ioctl support for querying video caps")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Applied.  Thanks!

Alex


> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index 84b666fcfaf6..730f4ac7487b 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -988,10 +988,6 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
>                 struct drm_amdgpu_info_video_caps *caps;
>                 int r;
>
> -               caps = kzalloc(sizeof(*caps), GFP_KERNEL);
> -               if (!caps)
> -                       return -ENOMEM;
> -
>                 switch (info->video_cap.type) {
>                 case AMDGPU_INFO_VIDEO_CAPS_DECODE:
>                         r = amdgpu_asic_query_video_codecs(adev, false, &codecs);
> @@ -1009,6 +1005,11 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
>                                       info->video_cap.type);
>                         return -EINVAL;
>                 }
> +
> +               caps = kzalloc(sizeof(*caps), GFP_KERNEL);
> +               if (!caps)
> +                       return -ENOMEM;
> +
>                 for (i = 0; i < codecs->codec_count; i++) {
>                         int idx = codecs->codec_array[i].codec_type;
>
> --
> 2.29.2
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][next] drm/amdgpu: Fix memory leak of object caps on error return paths
@ 2021-01-29 19:28   ` Alex Deucher
  0 siblings, 0 replies; 6+ messages in thread
From: Alex Deucher @ 2021-01-29 19:28 UTC (permalink / raw)
  To: Colin King
  Cc: David Airlie, kernel-janitors, LKML, amd-gfx list,
	Maling list - DRI developers, Daniel Vetter, Alex Deucher,
	Leo Liu, Christian König

On Fri, Jan 29, 2021 at 7:08 AM Colin King <colin.king@canonical.com> wrote:
>
> From: Colin Ian King <colin.king@canonical.com>
>
> Currently there are three error return paths that don't kfree object
> caps.  Fix this by performing the allocation of caps after the checks
> and error return paths to avoid the premature allocation and memory
> leaking.
>
> Addresses-Coverity: ("Resource leak")
> Fixes: 555fc7fbb2a2 ("drm/amdgpu: add INFO ioctl support for querying video caps")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Applied.  Thanks!

Alex


> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index 84b666fcfaf6..730f4ac7487b 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -988,10 +988,6 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
>                 struct drm_amdgpu_info_video_caps *caps;
>                 int r;
>
> -               caps = kzalloc(sizeof(*caps), GFP_KERNEL);
> -               if (!caps)
> -                       return -ENOMEM;
> -
>                 switch (info->video_cap.type) {
>                 case AMDGPU_INFO_VIDEO_CAPS_DECODE:
>                         r = amdgpu_asic_query_video_codecs(adev, false, &codecs);
> @@ -1009,6 +1005,11 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
>                                       info->video_cap.type);
>                         return -EINVAL;
>                 }
> +
> +               caps = kzalloc(sizeof(*caps), GFP_KERNEL);
> +               if (!caps)
> +                       return -ENOMEM;
> +
>                 for (i = 0; i < codecs->codec_count; i++) {
>                         int idx = codecs->codec_array[i].codec_type;
>
> --
> 2.29.2
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][next] drm/amdgpu: Fix memory leak of object caps on error return paths
@ 2021-01-29 19:28   ` Alex Deucher
  0 siblings, 0 replies; 6+ messages in thread
From: Alex Deucher @ 2021-01-29 19:28 UTC (permalink / raw)
  To: Colin King
  Cc: David Airlie, kernel-janitors, LKML, amd-gfx list,
	Maling list - DRI developers, Alex Deucher, Leo Liu,
	Christian König

On Fri, Jan 29, 2021 at 7:08 AM Colin King <colin.king@canonical.com> wrote:
>
> From: Colin Ian King <colin.king@canonical.com>
>
> Currently there are three error return paths that don't kfree object
> caps.  Fix this by performing the allocation of caps after the checks
> and error return paths to avoid the premature allocation and memory
> leaking.
>
> Addresses-Coverity: ("Resource leak")
> Fixes: 555fc7fbb2a2 ("drm/amdgpu: add INFO ioctl support for querying video caps")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Applied.  Thanks!

Alex


> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index 84b666fcfaf6..730f4ac7487b 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -988,10 +988,6 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
>                 struct drm_amdgpu_info_video_caps *caps;
>                 int r;
>
> -               caps = kzalloc(sizeof(*caps), GFP_KERNEL);
> -               if (!caps)
> -                       return -ENOMEM;
> -
>                 switch (info->video_cap.type) {
>                 case AMDGPU_INFO_VIDEO_CAPS_DECODE:
>                         r = amdgpu_asic_query_video_codecs(adev, false, &codecs);
> @@ -1009,6 +1005,11 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
>                                       info->video_cap.type);
>                         return -EINVAL;
>                 }
> +
> +               caps = kzalloc(sizeof(*caps), GFP_KERNEL);
> +               if (!caps)
> +                       return -ENOMEM;
> +
>                 for (i = 0; i < codecs->codec_count; i++) {
>                         int idx = codecs->codec_array[i].codec_type;
>
> --
> 2.29.2
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][next] drm/amdgpu: Fix memory leak of object caps on error return paths
@ 2021-01-29 19:28   ` Alex Deucher
  0 siblings, 0 replies; 6+ messages in thread
From: Alex Deucher @ 2021-01-29 19:28 UTC (permalink / raw)
  To: Colin King
  Cc: David Airlie, kernel-janitors, LKML, amd-gfx list,
	Maling list - DRI developers, Daniel Vetter, Alex Deucher,
	Leo Liu, Christian König

On Fri, Jan 29, 2021 at 7:08 AM Colin King <colin.king@canonical.com> wrote:
>
> From: Colin Ian King <colin.king@canonical.com>
>
> Currently there are three error return paths that don't kfree object
> caps.  Fix this by performing the allocation of caps after the checks
> and error return paths to avoid the premature allocation and memory
> leaking.
>
> Addresses-Coverity: ("Resource leak")
> Fixes: 555fc7fbb2a2 ("drm/amdgpu: add INFO ioctl support for querying video caps")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Applied.  Thanks!

Alex


> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index 84b666fcfaf6..730f4ac7487b 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -988,10 +988,6 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
>                 struct drm_amdgpu_info_video_caps *caps;
>                 int r;
>
> -               caps = kzalloc(sizeof(*caps), GFP_KERNEL);
> -               if (!caps)
> -                       return -ENOMEM;
> -
>                 switch (info->video_cap.type) {
>                 case AMDGPU_INFO_VIDEO_CAPS_DECODE:
>                         r = amdgpu_asic_query_video_codecs(adev, false, &codecs);
> @@ -1009,6 +1005,11 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
>                                       info->video_cap.type);
>                         return -EINVAL;
>                 }
> +
> +               caps = kzalloc(sizeof(*caps), GFP_KERNEL);
> +               if (!caps)
> +                       return -ENOMEM;
> +
>                 for (i = 0; i < codecs->codec_count; i++) {
>                         int idx = codecs->codec_array[i].codec_type;
>
> --
> 2.29.2
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-01-29 19:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-29 12:07 [PATCH][next] drm/amdgpu: Fix memory leak of object caps on error return paths Colin King
2021-01-29 12:07 ` Colin King
2021-01-29 19:28 ` Alex Deucher
2021-01-29 19:28   ` Alex Deucher
2021-01-29 19:28   ` Alex Deucher
2021-01-29 19:28   ` Alex Deucher

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.