drm/radeon/dpm: fix a memleak in sumo_parse_power_table

Message ID 20231203171643.3287229-1-alexious@zju.edu.cn
State New
Headers
Series drm/radeon/dpm: fix a memleak in sumo_parse_power_table |

Commit Message

Zhipeng Lu Dec. 3, 2023, 5:16 p.m. UTC
  The rdev->pm.dpm.ps allocated by kcalloc should be freed in every
following error-handling path. However, in the error-handling of
rdev->pm.power_state[i].clock_info the rdev->pm.dpm.ps is not freed,
resulting in a memleak in this function.

Fixes: 80ea2c129c76 ("drm/radeon/kms: add dpm support for sumo asics (v2)")
Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
---
 drivers/gpu/drm/radeon/sumo_dpm.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Christian König Dec. 4, 2023, 8:17 a.m. UTC | #1
Am 03.12.23 um 18:16 schrieb Zhipeng Lu:
> The rdev->pm.dpm.ps allocated by kcalloc should be freed in every
> following error-handling path. However, in the error-handling of
> rdev->pm.power_state[i].clock_info the rdev->pm.dpm.ps is not freed,
> resulting in a memleak in this function.
>
> Fixes: 80ea2c129c76 ("drm/radeon/kms: add dpm support for sumo asics (v2)")
> Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
> ---
>   drivers/gpu/drm/radeon/sumo_dpm.c | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/drivers/gpu/drm/radeon/sumo_dpm.c b/drivers/gpu/drm/radeon/sumo_dpm.c
> index f74f381af05f..bde640053708 100644
> --- a/drivers/gpu/drm/radeon/sumo_dpm.c
> +++ b/drivers/gpu/drm/radeon/sumo_dpm.c
> @@ -1494,6 +1494,7 @@ static int sumo_parse_power_table(struct radeon_device *rdev)
>   		non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
>   			&non_clock_info_array->nonClockInfo[non_clock_array_index];
>   		if (!rdev->pm.power_state[i].clock_info)
> +			kfree(rdev->pm.dpm.ps);
>   			return -EINVAL;

That change is obviously not correct since you now always return -EINVAL.

You need to at least add {} here.

Regards,
Christian.

>   		ps = kzalloc(sizeof(struct sumo_ps), GFP_KERNEL);
>   		if (ps == NULL) {
  
Zhipeng Lu Dec. 4, 2023, 8:46 a.m. UTC | #2
> Am 03.12.23 um 18:16 schrieb Zhipeng Lu:
> > The rdev->pm.dpm.ps allocated by kcalloc should be freed in every
> > following error-handling path. However, in the error-handling of
> > rdev->pm.power_state[i].clock_info the rdev->pm.dpm.ps is not freed,
> > resulting in a memleak in this function.
> >
> > Fixes: 80ea2c129c76 ("drm/radeon/kms: add dpm support for sumo asics (v2)")
> > Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
> > ---
> >   drivers/gpu/drm/radeon/sumo_dpm.c | 1 +
> >   1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/gpu/drm/radeon/sumo_dpm.c b/drivers/gpu/drm/radeon/sumo_dpm.c
> > index f74f381af05f..bde640053708 100644
> > --- a/drivers/gpu/drm/radeon/sumo_dpm.c
> > +++ b/drivers/gpu/drm/radeon/sumo_dpm.c
> > @@ -1494,6 +1494,7 @@ static int sumo_parse_power_table(struct radeon_device *rdev)
> >   		non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
> >   			&non_clock_info_array->nonClockInfo[non_clock_array_index];
> >   		if (!rdev->pm.power_state[i].clock_info)
> > +			kfree(rdev->pm.dpm.ps);
> >   			return -EINVAL;
> 
> That change is obviously not correct since you now always return -EINVAL.
> 
> You need to at least add {} here.
> 

I'm sorry for my mistake and I'll send a new patch soon.

Regards,
Zhipeng
  

Patch

diff --git a/drivers/gpu/drm/radeon/sumo_dpm.c b/drivers/gpu/drm/radeon/sumo_dpm.c
index f74f381af05f..bde640053708 100644
--- a/drivers/gpu/drm/radeon/sumo_dpm.c
+++ b/drivers/gpu/drm/radeon/sumo_dpm.c
@@ -1494,6 +1494,7 @@  static int sumo_parse_power_table(struct radeon_device *rdev)
 		non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
 			&non_clock_info_array->nonClockInfo[non_clock_array_index];
 		if (!rdev->pm.power_state[i].clock_info)
+			kfree(rdev->pm.dpm.ps);
 			return -EINVAL;
 		ps = kzalloc(sizeof(struct sumo_ps), GFP_KERNEL);
 		if (ps == NULL) {