diff mbox series

[v2,1/2] drm/nouveau: Fix ida leak

Message ID 20210511082841.4181-2-thunder.leizhen@huawei.com (mailing list archive)
State New, archived
Headers show
Series Fix ida leak and error return code | expand

Commit Message

Leizhen (ThunderTown) May 11, 2021, 8:28 a.m. UTC
When the 'nb' value allocated from 'bl_ida' is greater than or equal to
100, it will not be released. In fact, we can simplify operations by
limiting the range of idas that can be applied for.

By the way, delete the const modifier of the local variable 'nb'.

Fixes: db1a0ae21461 ("drm/nouveau/bl: Assign different names to interfaces")
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
 drivers/gpu/drm/nouveau/nouveau_backlight.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Pierre Moreau May 12, 2021, 6:39 a.m. UTC | #1
Why remove the const modifier on `nb`?

On 2021-05-11 — 16:28, Zhen Lei wrote:
> When the 'nb' value allocated from 'bl_ida' is greater than or equal to
> 100, it will not be released. In fact, we can simplify operations by
> limiting the range of idas that can be applied for.
> 
> By the way, delete the const modifier of the local variable 'nb'.
> 
> Fixes: db1a0ae21461 ("drm/nouveau/bl: Assign different names to interfaces")
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
> ---
>  drivers/gpu/drm/nouveau/nouveau_backlight.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nouveau_backlight.c b/drivers/gpu/drm/nouveau/nouveau_backlight.c
> index 72f35a2babcb20e..d1c998e645fb4b6 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_backlight.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_backlight.c
> @@ -51,8 +51,9 @@ static bool
>  nouveau_get_backlight_name(char backlight_name[BL_NAME_SIZE],
>  			   struct nouveau_backlight *bl)
>  {
> -	const int nb = ida_simple_get(&bl_ida, 0, 0, GFP_KERNEL);
> -	if (nb < 0 || nb >= 100)
> +	int nb = ida_simple_get(&bl_ida, 0, 100, GFP_KERNEL);
> +
> +	if (nb < 0)
>  		return false;
>  	if (nb > 0)
>  		snprintf(backlight_name, BL_NAME_SIZE, "nv_backlight%d", nb);
> -- 
> 2.26.0.106.g9fadedd
> 
> 
> _______________________________________________
> Nouveau mailing list
> Nouveau@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/nouveau
Leizhen (ThunderTown) May 12, 2021, 6:57 a.m. UTC | #2
On 2021/5/12 14:39, Pierre Moreau wrote:
> Why remove the const modifier on `nb`?

A non-pointer local variable, I don't think it's necessary to
add const modifier to make the syntax too complicated.

> 
> On 2021-05-11 — 16:28, Zhen Lei wrote:
>> When the 'nb' value allocated from 'bl_ida' is greater than or equal to
>> 100, it will not be released. In fact, we can simplify operations by
>> limiting the range of idas that can be applied for.
>>
>> By the way, delete the const modifier of the local variable 'nb'.
>>
>> Fixes: db1a0ae21461 ("drm/nouveau/bl: Assign different names to interfaces")
>> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
>> ---
>>  drivers/gpu/drm/nouveau/nouveau_backlight.c | 5 +++--
>>  1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/nouveau/nouveau_backlight.c b/drivers/gpu/drm/nouveau/nouveau_backlight.c
>> index 72f35a2babcb20e..d1c998e645fb4b6 100644
>> --- a/drivers/gpu/drm/nouveau/nouveau_backlight.c
>> +++ b/drivers/gpu/drm/nouveau/nouveau_backlight.c
>> @@ -51,8 +51,9 @@ static bool
>>  nouveau_get_backlight_name(char backlight_name[BL_NAME_SIZE],
>>  			   struct nouveau_backlight *bl)
>>  {
>> -	const int nb = ida_simple_get(&bl_ida, 0, 0, GFP_KERNEL);
>> -	if (nb < 0 || nb >= 100)
>> +	int nb = ida_simple_get(&bl_ida, 0, 100, GFP_KERNEL);
>> +
>> +	if (nb < 0)
>>  		return false;
>>  	if (nb > 0)
>>  		snprintf(backlight_name, BL_NAME_SIZE, "nv_backlight%d", nb);
>> -- 
>> 2.26.0.106.g9fadedd
>>
>>
>> _______________________________________________
>> Nouveau mailing list
>> Nouveau@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/nouveau
> 
> .
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/nouveau/nouveau_backlight.c b/drivers/gpu/drm/nouveau/nouveau_backlight.c
index 72f35a2babcb20e..d1c998e645fb4b6 100644
--- a/drivers/gpu/drm/nouveau/nouveau_backlight.c
+++ b/drivers/gpu/drm/nouveau/nouveau_backlight.c
@@ -51,8 +51,9 @@  static bool
 nouveau_get_backlight_name(char backlight_name[BL_NAME_SIZE],
 			   struct nouveau_backlight *bl)
 {
-	const int nb = ida_simple_get(&bl_ida, 0, 0, GFP_KERNEL);
-	if (nb < 0 || nb >= 100)
+	int nb = ida_simple_get(&bl_ida, 0, 100, GFP_KERNEL);
+
+	if (nb < 0)
 		return false;
 	if (nb > 0)
 		snprintf(backlight_name, BL_NAME_SIZE, "nv_backlight%d", nb);