public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 01/12] PM / devfreq: Fix memory leak when fail to register device
       [not found] ` <1503538979-22693-1-git-send-email-cw00.choi@samsung.com>
@ 2017-08-24  1:42   ` Chanwoo Choi
  2017-08-28  0:17     ` MyungJoo Ham
  2017-08-24  1:42   ` [PATCH 02/12] PM / devfreq: Fix locking range for making the frequency table Chanwoo Choi
  1 sibling, 1 reply; 6+ messages in thread
From: Chanwoo Choi @ 2017-08-24  1:42 UTC (permalink / raw)
  To: myungjoo.ham, kyungmin.park, cw00.choi
  Cc: rafael.j.wysocki, chanwoo, inki.dae, linux-kernel, linux-pm,
	stable

When the devfreq_add_device fails to register deivce, the memory
leak of devfreq instance happen. So, this patch fix the memory
leak issue. Before freeing the devfreq instance checks whether
devfreq instance is NULL or not because the device_unregister()
frees the devfreq instance when jumping to the 'err_init'.
It is to prevent the duplicate the kfee(devfreq).

Cc: stable@vger.kernel.org
Fixes: ac4b281176a5 ("PM / devfreq: fix duplicated kfree on devfreq pointer")
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
---
 drivers/devfreq/devfreq.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index dea04871b50d..a1c4ee818614 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -564,7 +564,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
 	err = device_register(&devfreq->dev);
 	if (err) {
 		mutex_unlock(&devfreq->lock);
-		goto err_out;
+		goto err_dev;
 	}
 
 	devfreq->trans_table =	devm_kzalloc(&devfreq->dev,
@@ -610,6 +610,9 @@ struct devfreq *devfreq_add_device(struct device *dev,
 	mutex_unlock(&devfreq_list_lock);
 
 	device_unregister(&devfreq->dev);
+err_dev:
+	if (devfreq)
+		kfree(devfreq);
 err_out:
 	return ERR_PTR(err);
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 02/12] PM / devfreq: Fix locking range for making the frequency table
       [not found] ` <1503538979-22693-1-git-send-email-cw00.choi@samsung.com>
  2017-08-24  1:42   ` [PATCH 01/12] PM / devfreq: Fix memory leak when fail to register device Chanwoo Choi
@ 2017-08-24  1:42   ` Chanwoo Choi
  2017-08-28  0:25     ` MyungJoo Ham
  1 sibling, 1 reply; 6+ messages in thread
From: Chanwoo Choi @ 2017-08-24  1:42 UTC (permalink / raw)
  To: myungjoo.ham, kyungmin.park, cw00.choi
  Cc: rafael.j.wysocki, chanwoo, inki.dae, linux-kernel, linux-pm,
	stable

Even if the freq_table is included in the struct devfreq,
the commit 0ec09ac2cebe ("PM / devfreq: Set the freq_table
of devfreq device") set the frequency table outside the mutex locking.

So, this patch initializes the frequency table within the mutex locking.

Cc: stable@vger.kernel.org
Fixes: 0ec09ac2cebe ("PM / devfreq: Set the freq_table of devfreq device")
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
---
 drivers/devfreq/devfreq.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index a1c4ee818614..3c5ccb96e165 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -553,11 +553,8 @@ struct devfreq *devfreq_add_device(struct device *dev,
 	devfreq->data = data;
 	devfreq->nb.notifier_call = devfreq_notifier_call;
 
-	if (!devfreq->profile->max_state && !devfreq->profile->freq_table) {
-		mutex_unlock(&devfreq->lock);
+	if (!devfreq->profile->max_state && !devfreq->profile->freq_table)
 		devfreq_set_freq_table(devfreq);
-		mutex_lock(&devfreq->lock);
-	}
 
 	dev_set_name(&devfreq->dev, "devfreq%d",
 				atomic_inc_return(&devfreq_no));
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* RE: [PATCH 01/12] PM / devfreq: Fix memory leak when fail to register device
  2017-08-24  1:42   ` [PATCH 01/12] PM / devfreq: Fix memory leak when fail to register device Chanwoo Choi
@ 2017-08-28  0:17     ` MyungJoo Ham
  2017-08-28  0:23       ` Chanwoo Choi
  0 siblings, 1 reply; 6+ messages in thread
From: MyungJoo Ham @ 2017-08-28  0:17 UTC (permalink / raw)
  To: Chanwoo Choi, Kyungmin Park
  Cc: rafael.j.wysocki@intel.com, chanwoo@kernel.org, Inki Dae,
	linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
	stable@vger.kernel.org

> When the devfreq_add_device fails to register deivce, the memory
> leak of devfreq instance happen. So, this patch fix the memory
> leak issue. Before freeing the devfreq instance checks whether
> devfreq instance is NULL or not because the device_unregister()
> frees the devfreq instance when jumping to the 'err_init'.
> It is to prevent the duplicate the kfee(devfreq).
> 
> Cc: stable@vger.kernel.org
> Fixes: ac4b281176a5 ("PM / devfreq: fix duplicated kfree on devfreq pointer")
> Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
> ---
>  drivers/devfreq/devfreq.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)

This looks like to be duplicated. Please check your repo basis.


Cheers,
MyungJoo

> 
> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> index dea04871b50d..a1c4ee818614 100644
> --- a/drivers/devfreq/devfreq.c
> +++ b/drivers/devfreq/devfreq.c
> @@ -564,7 +564,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
>  	err = device_register(&devfreq->dev);
>  	if (err) {
>  		mutex_unlock(&devfreq->lock);
> -		goto err_out;
> +		goto err_dev;
>  	}
>  
>  	devfreq->trans_table =	devm_kzalloc(&devfreq->dev,
> @@ -610,6 +610,9 @@ struct devfreq *devfreq_add_device(struct device *dev,
>  	mutex_unlock(&devfreq_list_lock);
>  
>  	device_unregister(&devfreq->dev);
> +err_dev:
> +	if (devfreq)
> +		kfree(devfreq);
>  err_out:
>  	return ERR_PTR(err);
>  }
> -- 
> 1.9.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 01/12] PM / devfreq: Fix memory leak when fail to register device
  2017-08-28  0:17     ` MyungJoo Ham
@ 2017-08-28  0:23       ` Chanwoo Choi
  2017-08-28  1:30         ` MyungJoo Ham
  0 siblings, 1 reply; 6+ messages in thread
From: Chanwoo Choi @ 2017-08-28  0:23 UTC (permalink / raw)
  To: myungjoo.ham, Kyungmin Park
  Cc: rafael.j.wysocki@intel.com, chanwoo@kernel.org, Inki Dae,
	linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
	stable@vger.kernel.org

On 2017년 08월 28일 09:17, MyungJoo Ham wrote:
>> When the devfreq_add_device fails to register deivce, the memory
>> leak of devfreq instance happen. So, this patch fix the memory
>> leak issue. Before freeing the devfreq instance checks whether
>> devfreq instance is NULL or not because the device_unregister()
>> frees the devfreq instance when jumping to the 'err_init'.
>> It is to prevent the duplicate the kfee(devfreq).
>>
>> Cc: stable@vger.kernel.org
>> Fixes: ac4b281176a5 ("PM / devfreq: fix duplicated kfree on devfreq pointer")
>> Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
>> ---
>>  drivers/devfreq/devfreq.c | 5 ++++-
>>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> This looks like to be duplicated. Please check your repo basis.

These patches is based on the v4.13-rc6.

After merged ("PM / devfreq: fix duplicated kfree on devfreq pointer"),
this patch doesn't consider the free of memory when error case.

After applying this patch, this patch consider the error case
when jumping the err_dev statement with goto.
		device_unregister(&devfreq->dev);
	err_dev:
		if (devfreq)		
			kfree(devfreq);


> 
> 
> Cheers,
> MyungJoo
> 
>>
>> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
>> index dea04871b50d..a1c4ee818614 100644
>> --- a/drivers/devfreq/devfreq.c
>> +++ b/drivers/devfreq/devfreq.c
>> @@ -564,7 +564,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
>>  	err = device_register(&devfreq->dev);
>>  	if (err) {
>>  		mutex_unlock(&devfreq->lock);
>> -		goto err_out;
>> +		goto err_dev;
>>  	}
>>  
>>  	devfreq->trans_table =	devm_kzalloc(&devfreq->dev,
>> @@ -610,6 +610,9 @@ struct devfreq *devfreq_add_device(struct device *dev,
>>  	mutex_unlock(&devfreq_list_lock);
>>  
>>  	device_unregister(&devfreq->dev);
>> +err_dev:
>> +	if (devfreq)
>> +		kfree(devfreq);
>>  err_out:
>>  	return ERR_PTR(err);
>>  }
>> -- 
>> 1.9.1
> 
> 


-- 
Best Regards,
Chanwoo Choi
Samsung Electronics

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH 02/12] PM / devfreq: Fix locking range for making the frequency table
  2017-08-24  1:42   ` [PATCH 02/12] PM / devfreq: Fix locking range for making the frequency table Chanwoo Choi
@ 2017-08-28  0:25     ` MyungJoo Ham
  0 siblings, 0 replies; 6+ messages in thread
From: MyungJoo Ham @ 2017-08-28  0:25 UTC (permalink / raw)
  To: Chanwoo Choi, Kyungmin Park
  Cc: rafael.j.wysocki@intel.com, chanwoo@kernel.org, Inki Dae,
	linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
	stable@vger.kernel.org

> Even if the freq_table is included in the struct devfreq,
> the commit 0ec09ac2cebe ("PM / devfreq: Set the freq_table
> of devfreq device") set the frequency table outside the mutex locking.
> 
> So, this patch initializes the frequency table within the mutex locking.
> 
> Cc: stable@vger.kernel.org
> Fixes: 0ec09ac2cebe ("PM / devfreq: Set the freq_table of devfreq device")
> Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>

Is this because you do not have locks inside
devfreq_set_freq_table() anymore?

> ---
>  drivers/devfreq/devfreq.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> index a1c4ee818614..3c5ccb96e165 100644
> --- a/drivers/devfreq/devfreq.c
> +++ b/drivers/devfreq/devfreq.c
> @@ -553,11 +553,8 @@ struct devfreq *devfreq_add_device(struct device *dev,
>  	devfreq->data = data;
>  	devfreq->nb.notifier_call = devfreq_notifier_call;
>  
> -	if (!devfreq->profile->max_state && !devfreq->profile->freq_table) {
> -		mutex_unlock(&devfreq->lock);
> +	if (!devfreq->profile->max_state && !devfreq->profile->freq_table)
>  		devfreq_set_freq_table(devfreq);
> -		mutex_lock(&devfreq->lock);
> -	}
>  
>  	dev_set_name(&devfreq->dev, "devfreq%d",
>  				atomic_inc_return(&devfreq_no));

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: Re: [PATCH 01/12] PM / devfreq: Fix memory leak when fail to register device
  2017-08-28  0:23       ` Chanwoo Choi
@ 2017-08-28  1:30         ` MyungJoo Ham
  0 siblings, 0 replies; 6+ messages in thread
From: MyungJoo Ham @ 2017-08-28  1:30 UTC (permalink / raw)
  To: Chanwoo Choi, Kyungmin Park
  Cc: rafael.j.wysocki@intel.com, chanwoo@kernel.org, Inki Dae,
	linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
	stable@vger.kernel.org

> On 2017년 08월 28일 09:17, MyungJoo Ham wrote:

> >> When the devfreq_add_device fails to register deivce, the memory

> >> leak of devfreq instance happen. So, this patch fix the memory

> >> leak issue. Before freeing the devfreq instance checks whether

> >> devfreq instance is NULL or not because the device_unregister()

> >> frees the devfreq instance when jumping to the 'err_init'.

> >> It is to prevent the duplicate the kfee(devfreq).

> >>

> >> Cc: stable@vger.kernel.org

> >> Fixes: ac4b281176a5 ("PM / devfreq: fix duplicated kfree on devfreq pointer")

> >> Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>

> >> ---

> >>  drivers/devfreq/devfreq.c | 5 ++++-

> >>  1 file changed, 4 insertions(+), 1 deletion(-)

> > 

> > This looks like to be duplicated. Please check your repo basis.

> 

> These patches is based on the v4.13-rc6.

> 

> After merged ("PM / devfreq: fix duplicated kfree on devfreq pointer"),

> this patch doesn't consider the free of memory when error case.

> 

> After applying this patch, this patch consider the error case

> when jumping the err_dev statement with goto.

> 		device_unregister(&devfreq->dev);

> 	err_dev:

> 		if (devfreq)		

> 			kfree(devfreq);



Ah sorry. It looks like I was confused of - and + somehow.



Acked-By: MyungJoo Ham.



(I'll merge trivial fixes first)



> 

> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-08-28  1:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CGME20170824014259epcas2p398a53a9a76d9aff7e35cf8515ec4e46a@epcas2p3.samsung.com>
     [not found] ` <1503538979-22693-1-git-send-email-cw00.choi@samsung.com>
2017-08-24  1:42   ` [PATCH 01/12] PM / devfreq: Fix memory leak when fail to register device Chanwoo Choi
2017-08-28  0:17     ` MyungJoo Ham
2017-08-28  0:23       ` Chanwoo Choi
2017-08-28  1:30         ` MyungJoo Ham
2017-08-24  1:42   ` [PATCH 02/12] PM / devfreq: Fix locking range for making the frequency table Chanwoo Choi
2017-08-28  0:25     ` MyungJoo Ham

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox