2023-04-13 03:16:09

by Cong Liu

[permalink] [raw]
Subject: [PATCH] drm/i915: Fix memory leaks in i915 selftests

Fixes: c3bfba9a2225 ("drm/i915: Check for integer truncation on scatterlist creation")

Signed-off-by: Cong Liu <[email protected]>
---
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
index 5361ce70d3f2..154801f1c468 100644
--- a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
@@ -69,8 +69,10 @@ static int fake_get_pages(struct drm_i915_gem_object *obj)

rem = round_up(obj->base.size, BIT(31)) >> 31;
/* restricted by sg_alloc_table */
- if (overflows_type(rem, unsigned int))
+ if (overflows_type(rem, unsigned int)) {
+ kfree(pages);
return -E2BIG;
+ }

if (sg_alloc_table(pages, rem, GFP)) {
kfree(pages);
--
2.34.1


No virus found
Checked by Hillstone Network AntiVirus


2023-04-13 06:17:12

by Andrzej Hajda

[permalink] [raw]
Subject: Re: [PATCH] drm/i915: Fix memory leaks in i915 selftests



On 13.04.2023 05:13, Cong Liu wrote:
> Fixes: c3bfba9a2225 ("drm/i915: Check for integer truncation on scatterlist creation")
>
> Signed-off-by: Cong Liu <[email protected]>
> ---

Reviewed-by: Andrzej Hajda <[email protected]>

Regards
Andrzej
> drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
> index 5361ce70d3f2..154801f1c468 100644
> --- a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
> +++ b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
> @@ -69,8 +69,10 @@ static int fake_get_pages(struct drm_i915_gem_object *obj)
>
> rem = round_up(obj->base.size, BIT(31)) >> 31;
> /* restricted by sg_alloc_table */
> - if (overflows_type(rem, unsigned int))
> + if (overflows_type(rem, unsigned int)) {
> + kfree(pages);
> return -E2BIG;
> + }
>
> if (sg_alloc_table(pages, rem, GFP)) {
> kfree(pages);

2023-04-13 07:16:45

by Jani Nikula

[permalink] [raw]
Subject: Re: [PATCH] drm/i915: Fix memory leaks in i915 selftests

On Thu, 13 Apr 2023, Andrzej Hajda <[email protected]> wrote:
> On 13.04.2023 05:13, Cong Liu wrote:

A commit message is still needed.

>> Fixes: c3bfba9a2225 ("drm/i915: Check for integer truncation on scatterlist creation")
>>

No blank line here.

BR,
Jani.

>> Signed-off-by: Cong Liu <[email protected]>
>> ---
>
> Reviewed-by: Andrzej Hajda <[email protected]>
>
> Regards
> Andrzej
>> drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 4 +++-
>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
>> index 5361ce70d3f2..154801f1c468 100644
>> --- a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
>> +++ b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
>> @@ -69,8 +69,10 @@ static int fake_get_pages(struct drm_i915_gem_object *obj)
>>
>> rem = round_up(obj->base.size, BIT(31)) >> 31;
>> /* restricted by sg_alloc_table */
>> - if (overflows_type(rem, unsigned int))
>> + if (overflows_type(rem, unsigned int)) {
>> + kfree(pages);
>> return -E2BIG;
>> + }
>>
>> if (sg_alloc_table(pages, rem, GFP)) {
>> kfree(pages);
>

--
Jani Nikula, Intel Open Source Graphics Center

2023-04-13 08:05:51

by Cong Liu

[permalink] [raw]
Subject: [PATCH] drm/i915: Fix memory leaks in i915 selftests

This patch fixes memory leaks on error escapes in function fake_get_pages

Fixes: c3bfba9a2225 ("drm/i915: Check for integer truncation on scatterlist creation")
Signed-off-by: Cong Liu <[email protected]>
---
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
index 5361ce70d3f2..154801f1c468 100644
--- a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
@@ -69,8 +69,10 @@ static int fake_get_pages(struct drm_i915_gem_object *obj)

rem = round_up(obj->base.size, BIT(31)) >> 31;
/* restricted by sg_alloc_table */
- if (overflows_type(rem, unsigned int))
+ if (overflows_type(rem, unsigned int)) {
+ kfree(pages);
return -E2BIG;
+ }

if (sg_alloc_table(pages, rem, GFP)) {
kfree(pages);
--
2.34.1


No virus found
Checked by Hillstone Network AntiVirus

2023-04-13 08:19:41

by Andi Shyti

[permalink] [raw]
Subject: Re: [PATCH] drm/i915: Fix memory leaks in i915 selftests

Hi Cong,

> Fixes: c3bfba9a2225 ("drm/i915: Check for integer truncation on scatterlist creation")
>
> Signed-off-by: Cong Liu <[email protected]>

As Jani suggested we need a commit message here. Would something
like this work for you?

"
We forget to free 'pages' after checking for overflow. Be sure to
properly free the allocated memory before exiting the
fake_free_pages() function.
"

If it's OK for you, then I can add this message and fix the blank
space before pushing this patch.

In any case:

Reviewed-by: Andi Shyti <[email protected]>

Andi

> ---
> drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
> index 5361ce70d3f2..154801f1c468 100644
> --- a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
> +++ b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
> @@ -69,8 +69,10 @@ static int fake_get_pages(struct drm_i915_gem_object *obj)
>
> rem = round_up(obj->base.size, BIT(31)) >> 31;
> /* restricted by sg_alloc_table */
> - if (overflows_type(rem, unsigned int))
> + if (overflows_type(rem, unsigned int)) {
> + kfree(pages);
> return -E2BIG;
> + }
>
> if (sg_alloc_table(pages, rem, GFP)) {
> kfree(pages);
> --
> 2.34.1
>
>
> No virus found
> Checked by Hillstone Network AntiVirus

2023-04-13 08:53:21

by Andi Shyti

[permalink] [raw]
Subject: Re: [PATCH] drm/i915: Fix memory leaks in i915 selftests

On Thu, Apr 13, 2023 at 03:55:26PM +0800, Cong Liu wrote:
> This patch fixes memory leaks on error escapes in function fake_get_pages
>
> Fixes: c3bfba9a2225 ("drm/i915: Check for integer truncation on scatterlist creation")
> Signed-off-by: Cong Liu <[email protected]>

OK, while I was proposing the adjustments suggested by Jani you
already replied to the e-mail. I will keep your version.

Anyway, next time, please, do not forget to add the r-b's, in
this case it was Andrzej's.

Andi

> ---
> drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
> index 5361ce70d3f2..154801f1c468 100644
> --- a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
> +++ b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
> @@ -69,8 +69,10 @@ static int fake_get_pages(struct drm_i915_gem_object *obj)
>
> rem = round_up(obj->base.size, BIT(31)) >> 31;
> /* restricted by sg_alloc_table */
> - if (overflows_type(rem, unsigned int))
> + if (overflows_type(rem, unsigned int)) {
> + kfree(pages);
> return -E2BIG;
> + }
>
> if (sg_alloc_table(pages, rem, GFP)) {
> kfree(pages);
> --
> 2.34.1
>
>
> No virus found
> Checked by Hillstone Network AntiVirus

2023-04-13 09:09:08

by Cong Liu

[permalink] [raw]
Subject: Re: [PATCH] drm/i915: Fix memory leaks in i915 selftests

Hi Andi,

thank you for your reminder, next time I will pay attention to my
format, and when someone has already
reviewed, add the Reviewed-by field

Regards.

On 2023/4/13 16:44, Andi Shyti wrote:
> On Thu, Apr 13, 2023 at 03:55:26PM +0800, Cong Liu wrote:
>> This patch fixes memory leaks on error escapes in function fake_get_pages
>>
>> Fixes: c3bfba9a2225 ("drm/i915: Check for integer truncation on scatterlist creation")
>> Signed-off-by: Cong Liu <[email protected]>
> OK, while I was proposing the adjustments suggested by Jani you
> already replied to the e-mail. I will keep your version.
>
> Anyway, next time, please, do not forget to add the r-b's, in
> this case it was Andrzej's.
>
> Andi
>
>> ---
>> drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 4 +++-
>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
>> index 5361ce70d3f2..154801f1c468 100644
>> --- a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
>> +++ b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
>> @@ -69,8 +69,10 @@ static int fake_get_pages(struct drm_i915_gem_object *obj)
>>
>> rem = round_up(obj->base.size, BIT(31)) >> 31;
>> /* restricted by sg_alloc_table */
>> - if (overflows_type(rem, unsigned int))
>> + if (overflows_type(rem, unsigned int)) {
>> + kfree(pages);
>> return -E2BIG;
>> + }
>>
>> if (sg_alloc_table(pages, rem, GFP)) {
>> kfree(pages);
>> --
>> 2.34.1
>>
>>
>> No virus found
>> Checked by Hillstone Network AntiVirus