diff mbox

PM / OPP: Handle return value of kasprintf

Message ID 15cec6eac63ffc9f12f1d16aff913eccad670f77.1505817563.git.arvind.yadav.cs@gmail.com (mailing list archive)
State Changes Requested, archived
Headers show

Commit Message

Arvind Yadav Sept. 20, 2017, 6:59 a.m. UTC
kasprintf() can fail here and we must check its return value.

Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
---
 drivers/base/power/opp/debugfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Joe Perches Sept. 20, 2017, 11:17 a.m. UTC | #1
On Wed, 2017-09-20 at 12:29 +0530, Arvind Yadav wrote:
> kasprintf() can fail here and we must check its return value.
[]
> diff --git a/drivers/base/power/opp/debugfs.c b/drivers/base/power/opp/debugfs.c
[]
> @@ -45,7 +45,8 @@ static bool opp_debug_create_supplies(struct dev_pm_opp *opp,
>  
>  	for (i = 0; i < opp_table->regulator_count; i++) {
>  		name = kasprintf(GFP_KERNEL, "supply-%d", i);
> -
> +		if (!name)
> +			return false;
>  		/* Create per-opp directory */
>  		d = debugfs_create_dir(name, pdentry);

Probably more sensible to avoid the kasprintf/kfree
and just have
	char name[20];
on the stack
Viresh Kumar Sept. 20, 2017, 2:49 p.m. UTC | #2
On 20-09-17, 04:17, Joe Perches wrote:
> On Wed, 2017-09-20 at 12:29 +0530, Arvind Yadav wrote:
> > kasprintf() can fail here and we must check its return value.
> []
> > diff --git a/drivers/base/power/opp/debugfs.c b/drivers/base/power/opp/debugfs.c
> []
> > @@ -45,7 +45,8 @@ static bool opp_debug_create_supplies(struct dev_pm_opp *opp,
> >  
> >  	for (i = 0; i < opp_table->regulator_count; i++) {
> >  		name = kasprintf(GFP_KERNEL, "supply-%d", i);
> > -
> > +		if (!name)
> > +			return false;
> >  		/* Create per-opp directory */
> >  		d = debugfs_create_dir(name, pdentry);
> 
> Probably more sensible to avoid the kasprintf/kfree
> and just have
> 	char name[20];
> on the stack

Sure.

@Arvind: I will let you write that patch.
Arvind Yadav Sept. 20, 2017, 4:58 p.m. UTC | #3
Hi,

On Wednesday 20 September 2017 08:19 PM, Viresh Kumar wrote:
> On 20-09-17, 04:17, Joe Perches wrote:
>> On Wed, 2017-09-20 at 12:29 +0530, Arvind Yadav wrote:
>>> kasprintf() can fail here and we must check its return value.
>> []
>>> diff --git a/drivers/base/power/opp/debugfs.c b/drivers/base/power/opp/debugfs.c
>> []
>>> @@ -45,7 +45,8 @@ static bool opp_debug_create_supplies(struct dev_pm_opp *opp,
>>>   
>>>   	for (i = 0; i < opp_table->regulator_count; i++) {
>>>   		name = kasprintf(GFP_KERNEL, "supply-%d", i);
>>> -
>>> +		if (!name)
>>> +			return false;
>>>   		/* Create per-opp directory */
>>>   		d = debugfs_create_dir(name, pdentry);
>> Probably more sensible to avoid the kasprintf/kfree
>> and just have
>> 	char name[20];
>> on the stack
> Sure.
>
> @Arvind: I will let you write that patch.
Yes, I will do.
>
~arvind
diff mbox

Patch

diff --git a/drivers/base/power/opp/debugfs.c b/drivers/base/power/opp/debugfs.c
index 81cf120..226d6ae 100644
--- a/drivers/base/power/opp/debugfs.c
+++ b/drivers/base/power/opp/debugfs.c
@@ -45,7 +45,8 @@  static bool opp_debug_create_supplies(struct dev_pm_opp *opp,
 
 	for (i = 0; i < opp_table->regulator_count; i++) {
 		name = kasprintf(GFP_KERNEL, "supply-%d", i);
-
+		if (!name)
+			return false;
 		/* Create per-opp directory */
 		d = debugfs_create_dir(name, pdentry);