diff mbox

[1/6] PM / devfreq: Fix the checkpatch warnings

Message ID 1479963668-22845-2-git-send-email-cw00.choi@samsung.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Chanwoo Choi Nov. 24, 2016, 5:01 a.m. UTC
This patch just fixes the checkpatch warnings.

Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
---
 drivers/devfreq/devfreq.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

Comments

Joe Perches Nov. 24, 2016, 10:20 a.m. UTC | #1
On Thu, 2016-11-24 at 14:01 +0900, Chanwoo Choi wrote:
> This patch just fixes the checkpatch warnings.

unrelated trivia:

> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
[]
> @@ -538,15 +538,14 @@ struct devfreq *devfreq_add_device(struct device *dev,
>  	devfreq = find_device_devfreq(dev);
>  	mutex_unlock(&devfreq_list_lock);
>  	if (!IS_ERR(devfreq)) {
> -		dev_err(dev, "%s: Unable to create devfreq for the device. It already has one.\n", __func__);
> +		dev_err(dev, "%s: Unable to create devfreq for the device.\n",
> +			__func__);
>  		err = -EINVAL;
>  		goto err_out;
>  	}

It seems to be simpler if find_device_devfreq just returned NULL
in the error cases as the only test is IS_ERR and not a
specific error return type.  Then these IS_ERR calls could be
a NULL pointer test instead.

> @@ -576,11 +575,13 @@ struct devfreq *devfreq_add_device(struct device *dev,
>  		goto err_out;
>  	}
>  
> -	devfreq->trans_table =	devm_kzalloc(&devfreq->dev, sizeof(unsigned int) *
> +	devfreq->trans_table =	devm_kzalloc(&devfreq->dev,
> +						sizeof(unsigned int) *
>  						devfreq->profile->max_state *
>  						devfreq->profile->max_state,
>  						GFP_KERNEL);
> -	devfreq->time_in_state = devm_kzalloc(&devfreq->dev, sizeof(unsigned long) *
> +	devfreq->time_in_state = devm_kzalloc(&devfreq->dev,
> +						sizeof(unsigned long) *
>  						devfreq->profile->max_state,
>  						GFP_KERNEL);

Maybe these should be devm_kcalloc calls

>  	devfreq->last_stat_updated = jiffies;
> @@ -990,7 +991,7 @@ static ssize_t cur_freq_show(struct device *dev, struct device_attribute *attr,
>  
>  	if (devfreq->profile->get_cur_freq &&
>  		!devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq))
> -			return sprintf(buf, "%lu\n", freq);
> +		return sprintf(buf, "%lu\n", freq);

Be nicer to align the second line in the if test here too

	if (devfreq->profile->get_cur_freq &&
	    !devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq))
		return sprintf(buf, "%lu\n", freq); 

>  	return sprintf(buf, "%lu\n", devfreq->previous_freq);
>  }
--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Chanwoo Choi Nov. 24, 2016, 10:46 a.m. UTC | #2
On 2016년 11월 24일 19:20, Joe Perches wrote:
> On Thu, 2016-11-24 at 14:01 +0900, Chanwoo Choi wrote:
>> This patch just fixes the checkpatch warnings.
> 
> unrelated trivia:
> 
>> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> []
>> @@ -538,15 +538,14 @@ struct devfreq *devfreq_add_device(struct device *dev,
>>  	devfreq = find_device_devfreq(dev);
>>  	mutex_unlock(&devfreq_list_lock);
>>  	if (!IS_ERR(devfreq)) {
>> -		dev_err(dev, "%s: Unable to create devfreq for the device. It already has one.\n", __func__);
>> +		dev_err(dev, "%s: Unable to create devfreq for the device.\n",
>> +			__func__);
>>  		err = -EINVAL;
>>  		goto err_out;
>>  	}
> 
> It seems to be simpler if find_device_devfreq just returned NULL
> in the error cases as the only test is IS_ERR and not a
> specific error return type.  Then these IS_ERR calls could be
> a NULL pointer test instead.
> 
>> @@ -576,11 +575,13 @@ struct devfreq *devfreq_add_device(struct device *dev,
>>  		goto err_out;
>>  	}
>>  
>> -	devfreq->trans_table =	devm_kzalloc(&devfreq->dev, sizeof(unsigned int) *
>> +	devfreq->trans_table =	devm_kzalloc(&devfreq->dev,
>> +						sizeof(unsigned int) *
>>  						devfreq->profile->max_state *
>>  						devfreq->profile->max_state,
>>  						GFP_KERNEL);
>> -	devfreq->time_in_state = devm_kzalloc(&devfreq->dev, sizeof(unsigned long) *
>> +	devfreq->time_in_state = devm_kzalloc(&devfreq->dev,
>> +						sizeof(unsigned long) *
>>  						devfreq->profile->max_state,
>>  						GFP_KERNEL);
> 
> Maybe these should be devm_kcalloc calls

Why should devfreq use the devm_kcalloc?

> 
>>  	devfreq->last_stat_updated = jiffies;
>> @@ -990,7 +991,7 @@ static ssize_t cur_freq_show(struct device *dev, struct device_attribute *attr,
>>  
>>  	if (devfreq->profile->get_cur_freq &&
>>  		!devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq))
>> -			return sprintf(buf, "%lu\n", freq);
>> +		return sprintf(buf, "%lu\n", freq);
> 
> Be nicer to align the second line in the if test here too
> 
> 	if (devfreq->profile->get_cur_freq &&
> 	    !devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq))
> 		return sprintf(buf, "%lu\n", freq); 
> 
>>  	return sprintf(buf, "%lu\n", devfreq->previous_freq);
>>  }
> 
> 
>
Joe Perches Nov. 24, 2016, 10:52 a.m. UTC | #3
On Thu, 2016-11-24 at 19:46 +0900, Chanwoo Choi wrote:
> On 2016년 11월 24일 19:20, Joe Perches wrote:
> > On Thu, 2016-11-24 at 14:01 +0900, Chanwoo Choi wrote:
> > > This patch just fixes the checkpatch warnings.
> > 
> > unrelated trivia:
> > 
> > > diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
[]
> > > @@ -576,11 +575,13 @@ struct devfreq *devfreq_add_device(struct device *dev,
> > >  		goto err_out;
> > >  	}
> > >  
> > > -	devfreq->trans_table =	devm_kzalloc(&devfreq->dev, sizeof(unsigned int) *
> > > +	devfreq->trans_table =	devm_kzalloc(&devfreq->dev,
> > > +						sizeof(unsigned int) *
> > >  						devfreq->profile->max_state *
> > >  						devfreq->profile->max_state,
> > >  						GFP_KERNEL);
> > > -	devfreq->time_in_state = devm_kzalloc(&devfreq->dev, sizeof(unsigned long) *
> > > +	devfreq->time_in_state = devm_kzalloc(&devfreq->dev,
> > > +						sizeof(unsigned long) *
> > >  						devfreq->profile->max_state,
> > >  						GFP_KERNEL);
> > 
> > Maybe these should be devm_kcalloc calls
> 
> Why should devfreq use the devm_kcalloc?

Because these are allocating zeroed arrays of a specific size.

--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Chanwoo Choi Nov. 24, 2016, 11:37 p.m. UTC | #4
On 2016년 11월 24일 19:52, Joe Perches wrote:
> On Thu, 2016-11-24 at 19:46 +0900, Chanwoo Choi wrote:
>> On 2016년 11월 24일 19:20, Joe Perches wrote:
>>> On Thu, 2016-11-24 at 14:01 +0900, Chanwoo Choi wrote:
>>>> This patch just fixes the checkpatch warnings.
>>>
>>> unrelated trivia:
>>>
>>>> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> []
>>>> @@ -576,11 +575,13 @@ struct devfreq *devfreq_add_device(struct device *dev,
>>>>  		goto err_out;
>>>>  	}
>>>>  
>>>> -	devfreq->trans_table =	devm_kzalloc(&devfreq->dev, sizeof(unsigned int) *
>>>> +	devfreq->trans_table =	devm_kzalloc(&devfreq->dev,
>>>> +						sizeof(unsigned int) *
>>>>  						devfreq->profile->max_state *
>>>>  						devfreq->profile->max_state,
>>>>  						GFP_KERNEL);
>>>> -	devfreq->time_in_state = devm_kzalloc(&devfreq->dev, sizeof(unsigned long) *
>>>> +	devfreq->time_in_state = devm_kzalloc(&devfreq->dev,
>>>> +						sizeof(unsigned long) *
>>>>  						devfreq->profile->max_state,
>>>>  						GFP_KERNEL);
>>>
>>> Maybe these should be devm_kcalloc calls
>>
>> Why should devfreq use the devm_kcalloc?
> 
> Because these are allocating zeroed arrays of a specific size.

kzalloc is already set to zero.

[1]https://www.kernel.org/doc/htmldocs/kernel-api/API-kzalloc.html

--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index a324801d6a66..dfef5ea57e4c 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -538,15 +538,14 @@  struct devfreq *devfreq_add_device(struct device *dev,
 	devfreq = find_device_devfreq(dev);
 	mutex_unlock(&devfreq_list_lock);
 	if (!IS_ERR(devfreq)) {
-		dev_err(dev, "%s: Unable to create devfreq for the device. It already has one.\n", __func__);
+		dev_err(dev, "%s: Unable to create devfreq for the device.\n",
+			__func__);
 		err = -EINVAL;
 		goto err_out;
 	}
 
 	devfreq = kzalloc(sizeof(struct devfreq), GFP_KERNEL);
 	if (!devfreq) {
-		dev_err(dev, "%s: Unable to create devfreq for the device\n",
-			__func__);
 		err = -ENOMEM;
 		goto err_out;
 	}
@@ -576,11 +575,13 @@  struct devfreq *devfreq_add_device(struct device *dev,
 		goto err_out;
 	}
 
-	devfreq->trans_table =	devm_kzalloc(&devfreq->dev, sizeof(unsigned int) *
+	devfreq->trans_table =	devm_kzalloc(&devfreq->dev,
+						sizeof(unsigned int) *
 						devfreq->profile->max_state *
 						devfreq->profile->max_state,
 						GFP_KERNEL);
-	devfreq->time_in_state = devm_kzalloc(&devfreq->dev, sizeof(unsigned long) *
+	devfreq->time_in_state = devm_kzalloc(&devfreq->dev,
+						sizeof(unsigned long) *
 						devfreq->profile->max_state,
 						GFP_KERNEL);
 	devfreq->last_stat_updated = jiffies;
@@ -990,7 +991,7 @@  static ssize_t cur_freq_show(struct device *dev, struct device_attribute *attr,
 
 	if (devfreq->profile->get_cur_freq &&
 		!devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq))
-			return sprintf(buf, "%lu\n", freq);
+		return sprintf(buf, "%lu\n", freq);
 
 	return sprintf(buf, "%lu\n", devfreq->previous_freq);
 }