From patchwork Thu Sep 17 17:00:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 53838 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by patches.linaro.org (Postfix) with ESMTPS id D9CBC22A0D for ; Thu, 17 Sep 2015 17:00:37 +0000 (UTC) Received: by lagj9 with SMTP id j9sf9805828lag.0 for ; Thu, 17 Sep 2015 10:00:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=I3hVngjrU39Bm3MBiDmi/5iuvMbyhpPsvvvqBR+vixE=; b=Y1dzG9PN5EUmvYAIWudCe1oJ3h4+ZwmsYGBzV1u2yoIXrXnLs5Mdh4vAPcZJns7lsU xggHxTtj3ox3Wz1omso+WOdm3YGfkFyP3K88eg5EkgC66D/WmH3RZX+l/dCeXEVJxsS8 4sjDkroJRahsCEv52jJl9PDGzMgJWQ7RgJrUwzS3Be3cuJ8EBYTCdGOj4ebroJZNdXKF dSlOHoafK02uyMO61sZYR/CP4z79MCwhp99KJ3a1ZedyFpZiIhSLCQURmkbHSRjukSq+ 1bq0W0+VFraczO8TwFZ3G12o0vGVgz3Q5R9k3GBlgIvG95eki2KQRo/o8AKlS8cdcNJP e00w== X-Gm-Message-State: ALoCoQmhFkXTZ9bbIxmJ886kfupFKb2ZCm3z5te8cbIZTcA5c0Borq8m3U/tsp2lOB+ptdRS3YUO X-Received: by 10.112.26.212 with SMTP id n20mr39249lbg.2.1442509236750; Thu, 17 Sep 2015 10:00:36 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.237.36 with SMTP id uz4ls132815lac.6.gmail; Thu, 17 Sep 2015 10:00:36 -0700 (PDT) X-Received: by 10.152.45.41 with SMTP id j9mr235253lam.110.1442509236582; Thu, 17 Sep 2015 10:00:36 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id qc10si2841828lbb.17.2015.09.17.10.00.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Sep 2015 10:00:36 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by lbcao8 with SMTP id ao8so12647454lbc.3 for ; Thu, 17 Sep 2015 10:00:36 -0700 (PDT) X-Received: by 10.112.199.70 with SMTP id ji6mr184148lbc.73.1442509235936; Thu, 17 Sep 2015 10:00:35 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp3185861lbq; Thu, 17 Sep 2015 10:00:34 -0700 (PDT) X-Received: by 10.68.163.5 with SMTP id ye5mr314349pbb.120.1442509234535; Thu, 17 Sep 2015 10:00:34 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id dn2si6548632pbb.210.2015.09.17.10.00.34; Thu, 17 Sep 2015 10:00:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751527AbbIQRAc (ORCPT + 12 others); Thu, 17 Sep 2015 13:00:32 -0400 Received: from mail-pa0-f45.google.com ([209.85.220.45]:33138 "EHLO mail-pa0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750792AbbIQRAc (ORCPT ); Thu, 17 Sep 2015 13:00:32 -0400 Received: by pacex6 with SMTP id ex6so24750745pac.0 for ; Thu, 17 Sep 2015 10:00:31 -0700 (PDT) X-Received: by 10.68.98.5 with SMTP id ee5mr233391pbb.95.1442509231529; Thu, 17 Sep 2015 10:00:31 -0700 (PDT) Received: from localhost ([122.172.95.6]) by smtp.gmail.com with ESMTPSA id de9sm4432417pad.44.2015.09.17.10.00.30 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 17 Sep 2015 10:00:30 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, sboyd@codeaurora.org, nm@ti.com, Viresh Kumar , Greg Kroah-Hartman , Len Brown , linux-kernel@vger.kernel.org (open list), Pavel Machek Subject: [PATCH] PM / OPP: of_property_count_u32_elems() can return errors Date: Thu, 17 Sep 2015 22:30:22 +0530 Message-Id: <46a47430b8d65f509d47fe3ad1264c6b23086d61.1442508974.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.4.0 Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , of_property_count_u32_elems() will never return 0, but a -ve error value of a positive count. And so the current !count check is wrong. Also, a missing "opp-microvolt" property isn't a problem and so we need to do of_find_property() separately to confirm that. Fixes: 274659029c9d ("PM / OPP: Add support to parse "operating-points-v2" bindings") Signed-off-by: Viresh Kumar --- For 4.3. drivers/base/power/opp.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c index 28cd75c535b0..2048164d6c53 100644 --- a/drivers/base/power/opp.c +++ b/drivers/base/power/opp.c @@ -889,13 +889,22 @@ static int _opp_add_dynamic(struct device *dev, unsigned long freq, /* TODO: Support multiple regulators */ static int opp_get_microvolt(struct dev_pm_opp *opp, struct device *dev) { + struct property *prop; u32 microvolt[3] = {0}; int count, ret; - count = of_property_count_u32_elems(opp->np, "opp-microvolt"); - if (!count) + /* Missing property isn't a problem, but an invalid entry is */ + prop = of_find_property(opp->np, "opp-microvolt", NULL); + if (!prop) return 0; + count = of_property_count_u32_elems(opp->np, "opp-microvolt"); + if (count < 0) { + dev_err(dev, "%s: Invalid opp-microvolt property (%d)\n", + __func__, count); + return count; + } + /* There can be one or three elements here */ if (count != 1 && count != 3) { dev_err(dev, "%s: Invalid number of elements in opp-microvolt property (%d)\n",