* [PATCH 1/3] PM / devfreq: fix indentation in devfreq_add_device()
@ 2019-01-19 16:04 ` Yangtao Li
2019-01-19 16:04 ` [PATCH 2/3] PM / devfreq: fix missing check of return value " Yangtao Li
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Yangtao Li @ 2019-01-19 16:04 UTC (permalink / raw)
To: myungjoo.ham, kyungmin.park, cw00.choi, linux-pm; +Cc: linux-kernel, Yangtao Li
To beautify the code format.
Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
---
drivers/devfreq/devfreq.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index 0ae3de76833b..076b1c2f40a4 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -683,16 +683,15 @@ struct devfreq *devfreq_add_device(struct device *dev,
goto err_out;
}
- devfreq->trans_table =
- devm_kzalloc(&devfreq->dev,
- array3_size(sizeof(unsigned int),
- devfreq->profile->max_state,
- devfreq->profile->max_state),
- GFP_KERNEL);
+ devfreq->trans_table = devm_kzalloc(&devfreq->dev,
+ array3_size(sizeof(unsigned int),
+ devfreq->profile->max_state,
+ devfreq->profile->max_state),
+ GFP_KERNEL);
devfreq->time_in_state = devm_kcalloc(&devfreq->dev,
- devfreq->profile->max_state,
- sizeof(unsigned long),
- GFP_KERNEL);
+ devfreq->profile->max_state,
+ sizeof(unsigned long),
+ GFP_KERNEL);
devfreq->last_stat_updated = jiffies;
srcu_init_notifier_head(&devfreq->transition_notifier_list);
--
2.17.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/3] PM / devfreq: fix missing check of return value in devfreq_add_device()
2019-01-19 16:04 ` [PATCH 1/3] PM / devfreq: fix indentation in devfreq_add_device() Yangtao Li
@ 2019-01-19 16:04 ` Yangtao Li
2019-01-19 16:04 ` [PATCH 3/3] PM / devfreq: fix mem leak " Yangtao Li
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Yangtao Li @ 2019-01-19 16:04 UTC (permalink / raw)
To: myungjoo.ham, kyungmin.park, cw00.choi, linux-pm; +Cc: linux-kernel, Yangtao Li
devm_kzalloc() could fail, so insert a check of its return value. And
if it fails, returns -ENOMEM.
Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
---
drivers/devfreq/devfreq.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index 076b1c2f40a4..923889229a0b 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -688,10 +688,22 @@ struct devfreq *devfreq_add_device(struct device *dev,
devfreq->profile->max_state,
devfreq->profile->max_state),
GFP_KERNEL);
+ if (!devfreq->trans_table) {
+ mutex_unlock(&devfreq->lock);
+ err = -ENOMEM;
+ goto err_devfreq;
+ }
+
devfreq->time_in_state = devm_kcalloc(&devfreq->dev,
devfreq->profile->max_state,
sizeof(unsigned long),
GFP_KERNEL);
+ if (!devfreq->time_in_state) {
+ mutex_unlock(&devfreq->lock);
+ err = -ENOMEM;
+ goto err_devfreq;
+ }
+
devfreq->last_stat_updated = jiffies;
srcu_init_notifier_head(&devfreq->transition_notifier_list);
@@ -725,7 +737,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
err_init:
mutex_unlock(&devfreq_list_lock);
-
+err_devfreq:
devfreq_remove_device(devfreq);
devfreq = NULL;
err_dev:
--
2.17.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/3] PM / devfreq: fix mem leak in devfreq_add_device()
2019-01-19 16:04 ` [PATCH 1/3] PM / devfreq: fix indentation in devfreq_add_device() Yangtao Li
2019-01-19 16:04 ` [PATCH 2/3] PM / devfreq: fix missing check of return value " Yangtao Li
@ 2019-01-19 16:04 ` Yangtao Li
2019-01-21 1:42 ` Chanwoo Choi
[not found] ` <CGME20190119183505epcas1p15efda0795b3c94601bcb2f442ab15232@epcms1p5>
` (2 subsequent siblings)
4 siblings, 1 reply; 8+ messages in thread
From: Yangtao Li @ 2019-01-19 16:04 UTC (permalink / raw)
To: myungjoo.ham, kyungmin.park, cw00.choi, linux-pm; +Cc: linux-kernel, Yangtao Li
'devfreq' is malloced in devfreq_add_device() and should be freed in
the error handling cases, otherwise it will cause memory leak.
Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
---
drivers/devfreq/devfreq.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index 923889229a0b..fe6c157cb7e0 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -651,7 +651,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
mutex_unlock(&devfreq->lock);
err = set_freq_table(devfreq);
if (err < 0)
- goto err_out;
+ goto err_dev;
mutex_lock(&devfreq->lock);
}
--
2.17.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* RE: [PATCH 3/3] PM / devfreq: fix mem leak in devfreq_add_device()
[not found] ` <CGME20190119183505epcas1p15efda0795b3c94601bcb2f442ab15232@epcms1p5>
@ 2019-01-21 1:23 ` MyungJoo Ham
0 siblings, 0 replies; 8+ messages in thread
From: MyungJoo Ham @ 2019-01-21 1:23 UTC (permalink / raw)
To: linux-pm, Yangtao Li; +Cc: Kyungmin Park, Chanwoo Choi, linux-kernel
>'devfreq' is malloced in devfreq_add_device() and should be freed in
>the error handling cases, otherwise it will cause memory leak.
>
>Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
Acked-by: MyungJoo Ham <myungjoo.ham@samsung.com>
>---
> drivers/devfreq/devfreq.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
>index 923889229a0b..fe6c157cb7e0 100644
>--- a/drivers/devfreq/devfreq.c
>+++ b/drivers/devfreq/devfreq.c
>@@ -651,7 +651,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
> mutex_unlock(&devfreq->lock);
> err = set_freq_table(devfreq);
> if (err < 0)
>- goto err_out;
>+ goto err_dev;
> mutex_lock(&devfreq->lock);
> }
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [PATCH 2/3] PM / devfreq: fix missing check of return value in devfreq_add_device()
[not found] ` <CGME20190119183509epcas1p27012fefeafe539c3f82030caf85ad308@epcms1p1>
@ 2019-01-21 1:27 ` MyungJoo Ham
0 siblings, 0 replies; 8+ messages in thread
From: MyungJoo Ham @ 2019-01-21 1:27 UTC (permalink / raw)
To: Kyungmin Park, Chanwoo Choi, linux-pm; +Cc: linux-kernel, Yangtao Li
>devm_kzalloc() could fail, so insert a check of its return value. And
>if it fails, returns -ENOMEM.
>
>Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
>---
> drivers/devfreq/devfreq.c | 14 +++++++++++++-
> 1 file changed, 13 insertions(+), 1 deletion(-)
>
>diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
>index 076b1c2f40a4..923889229a0b 100644
>--- a/drivers/devfreq/devfreq.c
>+++ b/drivers/devfreq/devfreq.c
Acked-by: MyungJoo Ham <myungjoo.ham@samsung.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] PM / devfreq: fix mem leak in devfreq_add_device()
2019-01-19 16:04 ` [PATCH 3/3] PM / devfreq: fix mem leak " Yangtao Li
@ 2019-01-21 1:42 ` Chanwoo Choi
0 siblings, 0 replies; 8+ messages in thread
From: Chanwoo Choi @ 2019-01-21 1:42 UTC (permalink / raw)
To: Yangtao Li, myungjoo.ham, kyungmin.park, linux-pm; +Cc: linux-kernel
Hi,
On 19. 1. 20. 오전 1:04, Yangtao Li wrote:
> 'devfreq' is malloced in devfreq_add_device() and should be freed in
> the error handling cases, otherwise it will cause memory leak.
>
> Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
> ---
> drivers/devfreq/devfreq.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> index 923889229a0b..fe6c157cb7e0 100644
> --- a/drivers/devfreq/devfreq.c
> +++ b/drivers/devfreq/devfreq.c
> @@ -651,7 +651,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
> mutex_unlock(&devfreq->lock);
> err = set_freq_table(devfreq);
> if (err < 0)
> - goto err_out;
> + goto err_dev;
> mutex_lock(&devfreq->lock);
> }
>
>
Reviewed-by: Chanwoo Choi <cw00.choi@samsung.com>
--
Best Regards,
Chanwoo Choi
Samsung Electronics
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] PM / devfreq: fix indentation in devfreq_add_device()
2019-01-19 16:04 ` [PATCH 1/3] PM / devfreq: fix indentation in devfreq_add_device() Yangtao Li
` (3 preceding siblings ...)
[not found] ` <CGME20190119183509epcas1p27012fefeafe539c3f82030caf85ad308@epcms1p1>
@ 2019-01-21 1:58 ` Chanwoo Choi
2019-01-21 16:39 ` Joe Perches
4 siblings, 1 reply; 8+ messages in thread
From: Chanwoo Choi @ 2019-01-21 1:58 UTC (permalink / raw)
To: Yangtao Li, myungjoo.ham, kyungmin.park, linux-pm; +Cc: linux-kernel
Hi,
On 19. 1. 20. 오전 1:04, Yangtao Li wrote:
> To beautify the code format.
>
> Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
> ---
> drivers/devfreq/devfreq.c | 17 ++++++++---------
> 1 file changed, 8 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> index 0ae3de76833b..076b1c2f40a4 100644
> --- a/drivers/devfreq/devfreq.c
> +++ b/drivers/devfreq/devfreq.c
> @@ -683,16 +683,15 @@ struct devfreq *devfreq_add_device(struct device *dev,
> goto err_out;
> }
>
> - devfreq->trans_table =
> - devm_kzalloc(&devfreq->dev,
> - array3_size(sizeof(unsigned int),
> - devfreq->profile->max_state,
> - devfreq->profile->max_state),
> - GFP_KERNEL);
> + devfreq->trans_table = devm_kzalloc(&devfreq->dev,
> + array3_size(sizeof(unsigned int),
> + devfreq->profile->max_state,
> + devfreq->profile->max_state),
> + GFP_KERNEL);
> devfreq->time_in_state = devm_kcalloc(&devfreq->dev,
> - devfreq->profile->max_state,
> - sizeof(unsigned long),
> - GFP_KERNEL);
> + devfreq->profile->max_state,
> + sizeof(unsigned long),
> + GFP_KERNEL);
> devfreq->last_stat_updated = jiffies;
>
> srcu_init_notifier_head(&devfreq->transition_notifier_list);
>
Reviewed-by: Chanwoo Choi <cw00.choi@samsung.com>
--
Best Regards,
Chanwoo Choi
Samsung Electronics
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] PM / devfreq: fix indentation in devfreq_add_device()
2019-01-21 1:58 ` [PATCH 1/3] PM / devfreq: fix indentation " Chanwoo Choi
@ 2019-01-21 16:39 ` Joe Perches
0 siblings, 0 replies; 8+ messages in thread
From: Joe Perches @ 2019-01-21 16:39 UTC (permalink / raw)
To: Chanwoo Choi, Yangtao Li, myungjoo.ham, kyungmin.park, linux-pm
Cc: linux-kernel
On Mon, 2019-01-21 at 10:58 +0900, Chanwoo Choi wrote:
> On 19. 1. 20. 오전 1:04, Yangtao Li wrote:
> > To beautify the code format.
I believe half of the changes are actually _less_ beautiful.
> > diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
[]
> > @@ -683,16 +683,15 @@ struct devfreq *devfreq_add_device(struct device *dev,
> > goto err_out;
> > }
> >
> > - devfreq->trans_table =
> > - devm_kzalloc(&devfreq->dev,
> > - array3_size(sizeof(unsigned int),
> > - devfreq->profile->max_state,
> > - devfreq->profile->max_state),
> > - GFP_KERNEL);
> > + devfreq->trans_table = devm_kzalloc(&devfreq->dev,
> > + array3_size(sizeof(unsigned int),
> > + devfreq->profile->max_state,
> > + devfreq->profile->max_state),
> > + GFP_KERNEL);
I think this bit is worse because the array3_size arguments
are no longer aligned.
> > devfreq->time_in_state = devm_kcalloc(&devfreq->dev,
> > - devfreq->profile->max_state,
> > - sizeof(unsigned long),
> > - GFP_KERNEL);
> > + devfreq->profile->max_state,
> > + sizeof(unsigned long),
> > + GFP_KERNEL);
and this bit is better.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2019-01-21 16:39 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <CGME20190119183407epcas1p4958e4526d07c36605307c49b0c0e2e2c@epcas1p4.samsung.com>
2019-01-19 16:04 ` [PATCH 1/3] PM / devfreq: fix indentation in devfreq_add_device() Yangtao Li
2019-01-19 16:04 ` [PATCH 2/3] PM / devfreq: fix missing check of return value " Yangtao Li
2019-01-19 16:04 ` [PATCH 3/3] PM / devfreq: fix mem leak " Yangtao Li
2019-01-21 1:42 ` Chanwoo Choi
[not found] ` <CGME20190119183505epcas1p15efda0795b3c94601bcb2f442ab15232@epcms1p5>
2019-01-21 1:23 ` MyungJoo Ham
[not found] ` <CGME20190119183509epcas1p27012fefeafe539c3f82030caf85ad308@epcms1p1>
2019-01-21 1:27 ` [PATCH 2/3] PM / devfreq: fix missing check of return value " MyungJoo Ham
2019-01-21 1:58 ` [PATCH 1/3] PM / devfreq: fix indentation " Chanwoo Choi
2019-01-21 16:39 ` Joe Perches
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).