thermal: cpu_cooling: Replace kmalloc with kmalloc_array

Message ID eff10695c92ff2d2e9733987d1b06adf559c07b0.1495522926.git.viresh.kumar@linaro.org
State New
Headers show

Commit Message

Viresh Kumar May 23, 2017, 7:03 a.m.
Checkpatch reports following:

WARNING: Prefer kmalloc_array over kmalloc with multiply
+	cpufreq_cdev->freq_table = kmalloc(sizeof(*cpufreq_cdev->freq_table) * i,

Fix that.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

---
 drivers/thermal/cpu_cooling.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

-- 
2.13.0.70.g6367777092d9

Comments

Eduardo Valentin May 24, 2017, 2:27 a.m. | #1
Hello,

On Tue, May 23, 2017 at 12:33:06PM +0530, Viresh Kumar wrote:
> Checkpatch reports following:

> 

> WARNING: Prefer kmalloc_array over kmalloc with multiply

> +	cpufreq_cdev->freq_table = kmalloc(sizeof(*cpufreq_cdev->freq_table) * i,

> 

> Fix that.


That is how the patch would apply. Enter to continue

WARNING: line over 80 characters
#159: FILE: drivers/thermal/cpu_cooling.c:783:
+	cpufreq_cdev->freq_table = kmalloc(sizeof(*cpufreq_cdev->freq_table) * i,

WARNING: Prefer kmalloc_array over kmalloc with multiply
#159: FILE: drivers/thermal/cpu_cooling.c:783:
+	cpufreq_cdev->freq_table = kmalloc(sizeof(*cpufreq_cdev->freq_table) * i,
+					  GFP_KERNEL);

WARNING: line over 80 characters
#190: FILE: include/linux/cpufreq.h:859:
+static inline int cpufreq_table_count_valid_entries(const struct cpufreq_policy *policy)


> 

> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

> ---

>  drivers/thermal/cpu_cooling.c | 5 +++--

>  1 file changed, 3 insertions(+), 2 deletions(-)

> 

> diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c

> index 1305020790b2..908a8014cf76 100644

> --- a/drivers/thermal/cpu_cooling.c

> +++ b/drivers/thermal/cpu_cooling.c

> @@ -724,8 +724,9 @@ __cpufreq_cooling_register(struct device_node *np,

>  	/* max_level is an index, not a counter */

>  	cpufreq_cdev->max_level = i - 1;

>  

> -	cpufreq_cdev->freq_table = kmalloc(sizeof(*cpufreq_cdev->freq_table) * i,

> -					  GFP_KERNEL);

> +	cpufreq_cdev->freq_table = kmalloc_array(i,

> +					sizeof(*cpufreq_cdev->freq_table),

> +					GFP_KERNEL);

>  	if (!cpufreq_cdev->freq_table) {

>  		cdev = ERR_PTR(-ENOMEM);

>  		goto free_idle_time;

> -- 

> 2.13.0.70.g6367777092d9

>
Viresh Kumar May 24, 2017, 3:51 a.m. | #2
On 23-05-17, 19:27, Eduardo Valentin wrote:
> Hello,

> 

> On Tue, May 23, 2017 at 12:33:06PM +0530, Viresh Kumar wrote:

> > Checkpatch reports following:

> > 

> > WARNING: Prefer kmalloc_array over kmalloc with multiply

> > +	cpufreq_cdev->freq_table = kmalloc(sizeof(*cpufreq_cdev->freq_table) * i,

> > 

> > Fix that.

> 

> That is how the patch would apply. Enter to continue

> 

> WARNING: line over 80 characters

> #159: FILE: drivers/thermal/cpu_cooling.c:783:

> +	cpufreq_cdev->freq_table = kmalloc(sizeof(*cpufreq_cdev->freq_table) * i,

> 

> WARNING: Prefer kmalloc_array over kmalloc with multiply

> #159: FILE: drivers/thermal/cpu_cooling.c:783:

> +	cpufreq_cdev->freq_table = kmalloc(sizeof(*cpufreq_cdev->freq_table) * i,

> +					  GFP_KERNEL);

> 

> WARNING: line over 80 characters

> #190: FILE: include/linux/cpufreq.h:859:

> +static inline int cpufreq_table_count_valid_entries(const struct cpufreq_policy *policy)


I am not sure what you meant here. Above doesn't looks something that
this patch can generate. This was fixing the problem that you reported
above.
 
> > 

> > Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

> > ---

> >  drivers/thermal/cpu_cooling.c | 5 +++--

> >  1 file changed, 3 insertions(+), 2 deletions(-)

> > 

> > diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c

> > index 1305020790b2..908a8014cf76 100644

> > --- a/drivers/thermal/cpu_cooling.c

> > +++ b/drivers/thermal/cpu_cooling.c

> > @@ -724,8 +724,9 @@ __cpufreq_cooling_register(struct device_node *np,

> >  	/* max_level is an index, not a counter */

> >  	cpufreq_cdev->max_level = i - 1;

> >  

> > -	cpufreq_cdev->freq_table = kmalloc(sizeof(*cpufreq_cdev->freq_table) * i,

> > -					  GFP_KERNEL);

> > +	cpufreq_cdev->freq_table = kmalloc_array(i,

> > +					sizeof(*cpufreq_cdev->freq_table),

> > +					GFP_KERNEL);

> >  	if (!cpufreq_cdev->freq_table) {


-- 
viresh

Patch hide | download patch | download mbox

diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 1305020790b2..908a8014cf76 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -724,8 +724,9 @@  __cpufreq_cooling_register(struct device_node *np,
 	/* max_level is an index, not a counter */
 	cpufreq_cdev->max_level = i - 1;
 
-	cpufreq_cdev->freq_table = kmalloc(sizeof(*cpufreq_cdev->freq_table) * i,
-					  GFP_KERNEL);
+	cpufreq_cdev->freq_table = kmalloc_array(i,
+					sizeof(*cpufreq_cdev->freq_table),
+					GFP_KERNEL);
 	if (!cpufreq_cdev->freq_table) {
 		cdev = ERR_PTR(-ENOMEM);
 		goto free_idle_time;