diff mbox series

PM / devfreq: Fix leak in devfreq_dev_release()

Message ID 20230809113108.2306272-1-boris.brezillon@collabora.com (mailing list archive)
State Accepted
Delegated to: Chanwoo Choi
Headers show
Series PM / devfreq: Fix leak in devfreq_dev_release() | expand

Commit Message

Boris Brezillon Aug. 9, 2023, 11:31 a.m. UTC
srcu_init_notifier_head() allocates resources that need to be released
with a srcu_cleanup_notifier_head() call.

Reported by kmemleak.

Fixes: 0fe3a66410a3 ("PM / devfreq: Add new DEVFREQ_TRANSITION_NOTIFIER notifier")
Cc: <stable@vger.kernel.org>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
---
 drivers/devfreq/devfreq.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Dhruva Gole Aug. 10, 2023, 5:21 a.m. UTC | #1
On Aug 09, 2023 at 13:31:08 +0200, Boris Brezillon wrote:
> srcu_init_notifier_head() allocates resources that need to be released
> with a srcu_cleanup_notifier_head() call.
> 
> Reported by kmemleak.

Probably want to give a proper mention like:
	Reported-by: Name <email-id>
?

> 
> Fixes: 0fe3a66410a3 ("PM / devfreq: Add new DEVFREQ_TRANSITION_NOTIFIER notifier")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
> ---
>  drivers/devfreq/devfreq.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> index e36cbb920ec8..9464f8d3cb5b 100644
> --- a/drivers/devfreq/devfreq.c
> +++ b/drivers/devfreq/devfreq.c
> @@ -763,6 +763,7 @@ static void devfreq_dev_release(struct device *dev)
>  		dev_pm_opp_put_opp_table(devfreq->opp_table);
>  
>  	mutex_destroy(&devfreq->lock);
> +	srcu_cleanup_notifier_head(&devfreq->transition_notifier_list);

Good catch!
Reviewed-by: Dhruva Gole <d-gole@ti.com>

>  	kfree(devfreq);
>  }
>  
> -- 
> 2.41.0
>
Boris Brezillon Aug. 10, 2023, 6:49 a.m. UTC | #2
On Thu, 10 Aug 2023 10:51:09 +0530
Dhruva Gole <d-gole@ti.com> wrote:

> On Aug 09, 2023 at 13:31:08 +0200, Boris Brezillon wrote:
> > srcu_init_notifier_head() allocates resources that need to be released
> > with a srcu_cleanup_notifier_head() call.
> > 
> > Reported by kmemleak.  
> 
> Probably want to give a proper mention like:
> 	Reported-by: Name <email-id>
> ?

Does kmemleak have a standard Reported-by tag? Otherwise, the reported
is me (ran kmemleak when developing a driver, and this showed up), and
since I'm also the one fixing the bug, I'm not sure it's worth
mentioning.

> 
> > 
> > Fixes: 0fe3a66410a3 ("PM / devfreq: Add new DEVFREQ_TRANSITION_NOTIFIER notifier")
> > Cc: <stable@vger.kernel.org>
> > Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
> > ---
> >  drivers/devfreq/devfreq.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> > index e36cbb920ec8..9464f8d3cb5b 100644
> > --- a/drivers/devfreq/devfreq.c
> > +++ b/drivers/devfreq/devfreq.c
> > @@ -763,6 +763,7 @@ static void devfreq_dev_release(struct device *dev)
> >  		dev_pm_opp_put_opp_table(devfreq->opp_table);
> >  
> >  	mutex_destroy(&devfreq->lock);
> > +	srcu_cleanup_notifier_head(&devfreq->transition_notifier_list);  
> 
> Good catch!
> Reviewed-by: Dhruva Gole <d-gole@ti.com>
> 
> >  	kfree(devfreq);
> >  }
> >  
> > -- 
> > 2.41.0
> >   
>
Chanwoo Choi Aug. 10, 2023, 1:50 p.m. UTC | #3
On 23. 8. 9. 20:31, Boris Brezillon wrote:
> srcu_init_notifier_head() allocates resources that need to be released
> with a srcu_cleanup_notifier_head() call.
> 
> Reported by kmemleak.
> 
> Fixes: 0fe3a66410a3 ("PM / devfreq: Add new DEVFREQ_TRANSITION_NOTIFIER notifier")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
> ---
>  drivers/devfreq/devfreq.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> index e36cbb920ec8..9464f8d3cb5b 100644
> --- a/drivers/devfreq/devfreq.c
> +++ b/drivers/devfreq/devfreq.c
> @@ -763,6 +763,7 @@ static void devfreq_dev_release(struct device *dev)
>  		dev_pm_opp_put_opp_table(devfreq->opp_table);
>  
>  	mutex_destroy(&devfreq->lock);
> +	srcu_cleanup_notifier_head(&devfreq->transition_notifier_list);
>  	kfree(devfreq);
>  }
>  

Applied it. Thanks.
diff mbox series

Patch

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index e36cbb920ec8..9464f8d3cb5b 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -763,6 +763,7 @@  static void devfreq_dev_release(struct device *dev)
 		dev_pm_opp_put_opp_table(devfreq->opp_table);
 
 	mutex_destroy(&devfreq->lock);
+	srcu_cleanup_notifier_head(&devfreq->transition_notifier_list);
 	kfree(devfreq);
 }