From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755973AbcJYSOo (ORCPT ); Tue, 25 Oct 2016 14:14:44 -0400 Received: from mail-pf0-f181.google.com ([209.85.192.181]:34187 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754788AbcJYSOm (ORCPT ); Tue, 25 Oct 2016 14:14:42 -0400 From: Kevin Hilman To: Colin King Cc: "Rafael J . Wysocki" , Ulf Hansson , Pavel Machek , Len Brown , Greg Kroah-Hartman , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] PM / Domains: check for negative return from of_count_phandle_with_args Organization: BayLibre References: <20161025163327.2179-1-colin.king@canonical.com> Date: Tue, 25 Oct 2016 11:14:40 -0700 In-Reply-To: <20161025163327.2179-1-colin.king@canonical.com> (Colin King's message of "Tue, 25 Oct 2016 17:33:27 +0100") Message-ID: <7htwc0thwv.fsf@baylibre.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Colin King writes: > From: Colin Ian King > > 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 Acked-by: Kevin Hilman > --- > 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);