diff mbox

PM / clk: ensure we don't allocate a -ve size of count clks

Message ID 1460811003-31806-1-git-send-email-colin.king@canonical.com (mailing list archive)
State Accepted, archived
Delegated to: Rafael Wysocki
Headers show

Commit Message

Colin King April 16, 2016, 12:50 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

It is entirely possible for of_count_phandle_wit_args to
return a -ve error return value so we need to check for this
otherwise we end up allocating a negative number of clk objects.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/base/power/clock_ops.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Pavel Machek April 16, 2016, 12:52 p.m. UTC | #1
On Sat 2016-04-16 13:50:03, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> It is entirely possible for of_count_phandle_wit_args to
> return a -ve error return value so we need to check for this
> otherwise we end up allocating a negative number of clk objects.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Acked-by: Pavel Machek <pavel@ucw.cz>


> diff --git a/drivers/base/power/clock_ops.c b/drivers/base/power/clock_ops.c
> index 0e64a1b..3657ac1 100644
> --- a/drivers/base/power/clock_ops.c
> +++ b/drivers/base/power/clock_ops.c
> @@ -159,7 +159,7 @@ int of_pm_clk_add_clks(struct device *dev)
>  
>  	count = of_count_phandle_with_args(dev->of_node, "clocks",
>  					   "#clock-cells");
> -	if (count == 0)
> +	if (count <= 0)
>  		return -ENODEV;

Would it make sense to propagate the error value?

									Pavel
Colin King April 16, 2016, 1:49 p.m. UTC | #2
On 16/04/16 13:52, Pavel Machek wrote:
> On Sat 2016-04-16 13:50:03, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> It is entirely possible for of_count_phandle_wit_args to
>> return a -ve error return value so we need to check for this
>> otherwise we end up allocating a negative number of clk objects.
>>
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> 
> Acked-by: Pavel Machek <pavel@ucw.cz>
> 
> 
>> diff --git a/drivers/base/power/clock_ops.c b/drivers/base/power/clock_ops.c
>> index 0e64a1b..3657ac1 100644
>> --- a/drivers/base/power/clock_ops.c
>> +++ b/drivers/base/power/clock_ops.c
>> @@ -159,7 +159,7 @@ int of_pm_clk_add_clks(struct device *dev)
>>  
>>  	count = of_count_phandle_with_args(dev->of_node, "clocks",
>>  					   "#clock-cells");
>> -	if (count == 0)
>> +	if (count <= 0)
>>  		return -ENODEV;
> 
> Would it make sense to propagate the error value?

I don't think it will contribute much more than the current return.

> 
> 									Pavel
> 

--
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
Rafael J. Wysocki April 27, 2016, 9:36 p.m. UTC | #3
On Saturday, April 16, 2016 01:50:03 PM Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> It is entirely possible for of_count_phandle_wit_args to
> return a -ve error return value so we need to check for this
> otherwise we end up allocating a negative number of clk objects.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Applied, thanks!

--
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/base/power/clock_ops.c b/drivers/base/power/clock_ops.c
index 0e64a1b..3657ac1 100644
--- a/drivers/base/power/clock_ops.c
+++ b/drivers/base/power/clock_ops.c
@@ -159,7 +159,7 @@  int of_pm_clk_add_clks(struct device *dev)
 
 	count = of_count_phandle_with_args(dev->of_node, "clocks",
 					   "#clock-cells");
-	if (count == 0)
+	if (count <= 0)
 		return -ENODEV;
 
 	clks = kcalloc(count, sizeof(*clks), GFP_KERNEL);