To beautify the code format.
Signed-off-by: Yangtao Li <[email protected]>
---
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
'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 <[email protected]>
---
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
devm_kzalloc() could fail, so insert a check of its return value. And
if it fails, returns -ENOMEM.
Signed-off-by: Yangtao Li <[email protected]>
---
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
>devm_kzalloc() could fail, so insert a check of its return value. And
>if it fails, returns -ENOMEM.
>
>Signed-off-by: Yangtao Li <[email protected]>
>---
> 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 <[email protected]>
>'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 <[email protected]>
Acked-by: MyungJoo Ham <[email protected]>
>---
> 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);
> }
>
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 <[email protected]>
> ---
> 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 <[email protected]>
--
Best Regards,
Chanwoo Choi
Samsung Electronics
Hi,
On 19. 1. 20. 오전 1:04, Yangtao Li wrote:
> To beautify the code format.
>
> Signed-off-by: Yangtao Li <[email protected]>
> ---
> 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 <[email protected]>
--
Best Regards,
Chanwoo Choi
Samsung Electronics
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.