Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1508438 > unrolled thread

[PATCH] PM / Domains: check for negative return from of_count_phandle_with_args

Started byColin King <colin.king@canonical.com>
First post2016-10-25 18:40 +0200
Last post2016-10-26 13:10 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] PM / Domains: check for negative return from of_count_phandle_with_args Colin King <colin.king@canonical.com> - 2016-10-25 18:40 +0200
    Re: [PATCH] PM / Domains: check for negative return from of_count_phandle_with_args Kevin Hilman <khilman@baylibre.com> - 2016-10-25 20:20 +0200
      Re: [PATCH] PM / Domains: check for negative return from  of_count_phandle_with_args Pavel Machek <pavel@ucw.cz> - 2016-10-26 13:10 +0200

#1508438 — [PATCH] PM / Domains: check for negative return from of_count_phandle_with_args

FromColin King <colin.king@canonical.com>
Date2016-10-25 18:40 +0200
Subject[PATCH] PM / Domains: check for negative return from of_count_phandle_with_args
Message-ID<swcVA-86H-19@gated-at.bofh.it>
From: Colin Ian King <colin.king@canonical.com>

The return from of_count_phandle_with_args can be negative, so we
should avoid kcalloc of a negative count of genpd_power_stat structs
by sanity checking if count is zero or less.

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

diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index aac656a..661737c 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -2113,7 +2113,7 @@ int of_genpd_parse_idle_states(struct device_node *dn,
 	struct of_phandle_iterator it;
 
 	count = of_count_phandle_with_args(dn, "domain-idle-states", NULL);
-	if (!count)
+	if (count <= 0)
 		return -EINVAL;
 
 	st = kcalloc(count, sizeof(*st), GFP_KERNEL);
-- 
2.9.3

[toc] | [next] | [standalone]


#1508541

FromKevin Hilman <khilman@baylibre.com>
Date2016-10-25 20:20 +0200
Message-ID<sweul-Lo-25@gated-at.bofh.it>
In reply to#1508438
Colin King <colin.king@canonical.com> writes:

> From: Colin Ian King <colin.king@canonical.com>
>
> The return from of_count_phandle_with_args can be negative, so we
> should avoid kcalloc of a negative count of genpd_power_stat structs
> by sanity checking if count is zero or less.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Acked-by: Kevin Hilman <khilman@baylibre.com>

> ---
>  drivers/base/power/domain.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
> index aac656a..661737c 100644
> --- a/drivers/base/power/domain.c
> +++ b/drivers/base/power/domain.c
> @@ -2113,7 +2113,7 @@ int of_genpd_parse_idle_states(struct device_node *dn,
>  	struct of_phandle_iterator it;
>  
>  	count = of_count_phandle_with_args(dn, "domain-idle-states", NULL);
> -	if (!count)
> +	if (count <= 0)
>  		return -EINVAL;
>  
>  	st = kcalloc(count, sizeof(*st), GFP_KERNEL);

[toc] | [prev] | [next] | [standalone]


#1509061 — Re: [PATCH] PM / Domains: check for negative return from of_count_phandle_with_args

FromPavel Machek <pavel@ucw.cz>
Date2016-10-26 13:10 +0200
SubjectRe: [PATCH] PM / Domains: check for negative return from of_count_phandle_with_args
Message-ID<swufL-2OE-1@gated-at.bofh.it>
In reply to#1508541

[Multipart message — attachments visible in raw view] — view raw

On Tue 2016-10-25 11:14:40, Kevin Hilman wrote:
> Colin King <colin.king@canonical.com> writes:
> 
> > From: Colin Ian King <colin.king@canonical.com>
> >
> > The return from of_count_phandle_with_args can be negative, so we
> > should avoid kcalloc of a negative count of genpd_power_stat structs
> > by sanity checking if count is zero or less.
> >
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> 
> Acked-by: Kevin Hilman <khilman@baylibre.com>

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

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web