drm/amdgpu/powerplay/psm: Fix memory leak in power state init

Message ID 20221018005357.887009-1-rafaelmendsr@gmail.com
State New
Headers
Series drm/amdgpu/powerplay/psm: Fix memory leak in power state init |

Commit Message

Rafael Mendonca Oct. 18, 2022, 12:53 a.m. UTC
  Commit 902bc65de0b3 ("drm/amdgpu/powerplay/psm: return an error in power
state init") made the power state init function return early in case of
failure to get an entry from the powerplay table, but it missed to clean up
the allocated memory for the current power state before returning.

Fixes: 902bc65de0b3 ("drm/amdgpu/powerplay/psm: return an error in power state init")
Signed-off-by: Rafael Mendonca <rafaelmendsr@gmail.com>
---
 drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

Evan Quan Oct. 18, 2022, 1:06 a.m. UTC | #1
[AMD Official Use Only - General]

Reviewed-by: Evan Quan <evan.quan@amd.com>

> -----Original Message-----
> From: Rafael Mendonca <rafaelmendsr@gmail.com>
> Sent: Tuesday, October 18, 2022 8:54 AM
> To: Quan, Evan <Evan.Quan@amd.com>; Deucher, Alexander
> <Alexander.Deucher@amd.com>; Koenig, Christian
> <Christian.Koenig@amd.com>; Pan, Xinhui <Xinhui.Pan@amd.com>; David
> Airlie <airlied@gmail.com>; Daniel Vetter <daniel@ffwll.ch>
> Cc: Rafael Mendonca <rafaelmendsr@gmail.com>; amd-
> gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org; linux-
> kernel@vger.kernel.org
> Subject: [PATCH] drm/amdgpu/powerplay/psm: Fix memory leak in power
> state init
> 
> Commit 902bc65de0b3 ("drm/amdgpu/powerplay/psm: return an error in
> power state init") made the power state init function return early in case of
> failure to get an entry from the powerplay table, but it missed to clean up the
> allocated memory for the current power state before returning.
> 
> Fixes: 902bc65de0b3 ("drm/amdgpu/powerplay/psm: return an error in
> power state init")
> Signed-off-by: Rafael Mendonca <rafaelmendsr@gmail.com>
> ---
>  drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c
> b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c
> index 67d7da0b6fed..1d829402cd2e 100644
> --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c
> +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c
> @@ -75,8 +75,10 @@ int psm_init_power_state_table(struct pp_hwmgr
> *hwmgr)
>  	for (i = 0; i < table_entries; i++) {
>  		result = hwmgr->hwmgr_func->get_pp_table_entry(hwmgr,
> i, state);
>  		if (result) {
> +			kfree(hwmgr->current_ps);
>  			kfree(hwmgr->request_ps);
>  			kfree(hwmgr->ps);
> +			hwmgr->current_ps = NULL;
>  			hwmgr->request_ps = NULL;
>  			hwmgr->ps = NULL;
>  			return -EINVAL;
> --
> 2.34.1
  
Alex Deucher Oct. 18, 2022, 3:59 p.m. UTC | #2
Applied.  Thanks!

Alex

On Mon, Oct 17, 2022 at 9:07 PM Quan, Evan <Evan.Quan@amd.com> wrote:
>
> [AMD Official Use Only - General]
>
> Reviewed-by: Evan Quan <evan.quan@amd.com>
>
> > -----Original Message-----
> > From: Rafael Mendonca <rafaelmendsr@gmail.com>
> > Sent: Tuesday, October 18, 2022 8:54 AM
> > To: Quan, Evan <Evan.Quan@amd.com>; Deucher, Alexander
> > <Alexander.Deucher@amd.com>; Koenig, Christian
> > <Christian.Koenig@amd.com>; Pan, Xinhui <Xinhui.Pan@amd.com>; David
> > Airlie <airlied@gmail.com>; Daniel Vetter <daniel@ffwll.ch>
> > Cc: Rafael Mendonca <rafaelmendsr@gmail.com>; amd-
> > gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org; linux-
> > kernel@vger.kernel.org
> > Subject: [PATCH] drm/amdgpu/powerplay/psm: Fix memory leak in power
> > state init
> >
> > Commit 902bc65de0b3 ("drm/amdgpu/powerplay/psm: return an error in
> > power state init") made the power state init function return early in case of
> > failure to get an entry from the powerplay table, but it missed to clean up the
> > allocated memory for the current power state before returning.
> >
> > Fixes: 902bc65de0b3 ("drm/amdgpu/powerplay/psm: return an error in
> > power state init")
> > Signed-off-by: Rafael Mendonca <rafaelmendsr@gmail.com>
> > ---
> >  drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c
> > b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c
> > index 67d7da0b6fed..1d829402cd2e 100644
> > --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c
> > +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c
> > @@ -75,8 +75,10 @@ int psm_init_power_state_table(struct pp_hwmgr
> > *hwmgr)
> >       for (i = 0; i < table_entries; i++) {
> >               result = hwmgr->hwmgr_func->get_pp_table_entry(hwmgr,
> > i, state);
> >               if (result) {
> > +                     kfree(hwmgr->current_ps);
> >                       kfree(hwmgr->request_ps);
> >                       kfree(hwmgr->ps);
> > +                     hwmgr->current_ps = NULL;
> >                       hwmgr->request_ps = NULL;
> >                       hwmgr->ps = NULL;
> >                       return -EINVAL;
> > --
> > 2.34.1
  

Patch

diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c
index 67d7da0b6fed..1d829402cd2e 100644
--- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c
+++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c
@@ -75,8 +75,10 @@  int psm_init_power_state_table(struct pp_hwmgr *hwmgr)
 	for (i = 0; i < table_entries; i++) {
 		result = hwmgr->hwmgr_func->get_pp_table_entry(hwmgr, i, state);
 		if (result) {
+			kfree(hwmgr->current_ps);
 			kfree(hwmgr->request_ps);
 			kfree(hwmgr->ps);
+			hwmgr->current_ps = NULL;
 			hwmgr->request_ps = NULL;
 			hwmgr->ps = NULL;
 			return -EINVAL;