From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 986FEC43610 for ; Thu, 29 Nov 2018 17:55:28 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6E91E2145D for ; Thu, 29 Nov 2018 17:55:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="U93q5sDf"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=linaro.org header.i=@linaro.org header.b="gc/mEof6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E91E2145D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=u37J6G19OZdQVVGd1g5fYGVYRHgwDZC3qsRprDM74+8=; b=U93q5sDfngGg8GqtQPS92ghBkU ST2mTWEjVNFEmH/ik6Z+GhcKAJFdAEq3r/vqamxwqojwveRHLHWqqMEGbJ/kJ1Y6QVMWGgSGsUuWL 7rEw/xfWVgLDB/G52oRy1nSNRh/4FJPx3dkZkf80F6VrqOqSZcNSo3P5l7mzqSEoKtcjxh1C5hj6m vTa14rbl3FoIS3iRsuH4fev9E8LkcbA4usnUHYAOh5gtd4hYjuDLQBkNal+p+ZFUNdcB+xiTGbGOv lzSOdux2BV/wwLEDJ15FAQH9ExpNJhP+JymtKdZj8ZYFGUaURkN/o0KJoUNa4SPOIgbBOSWID2nv1 A5t+uRoQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gSQX1-0001Fb-Qo; Thu, 29 Nov 2018 17:55:19 +0000 Received: from mail-lf1-x142.google.com ([2a00:1450:4864:20::142]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gSQPY-0001Bz-1i for linux-arm-kernel@lists.infradead.org; Thu, 29 Nov 2018 17:47:41 +0000 Received: by mail-lf1-x142.google.com with SMTP id n18so2101083lfh.6 for ; Thu, 29 Nov 2018 09:47:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZnU2zg5+wIbWo5O0mmqI6742JstHQYNw0KGOcLMkauw=; b=gc/mEof6FAHJILmhbUnZDwxeH3clqii9e4boH+PzYfTjHTpHvntzwcHeA4X/TZUQCO nEaYBT3n60JTTzq82pT8Jx8y3Ni2mBBoG8mGM8FR0XlTfs3oYJZ8Icwa0KV7QnJ8zC0z 1x2yIJkBRlAHnoX+Xfz8x50/nIvF5nR+udY6k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ZnU2zg5+wIbWo5O0mmqI6742JstHQYNw0KGOcLMkauw=; b=M8Tu/6/5ac+d3KHscTYHzCsqUtGsrnqvSg/5FfhtxlTI1FbZ/SymX8HHxeUj6G2ph4 OOxWTqOv4UQLJ+o8ZGghUNXeivVLEhuB37HipmzrEIahV6B/D/eVnH/ct6DECNd/v6TD rx+HQ4bRarW1xrAcFvcNniR4Xtjx2eEt8Ol5AVpkVz6fsS4gbchyZD3Yfmn/iroPXIre JxEdr88WilZ/Grkg2o9/LF6BktlOYswKA8Fm4qPh+KmscLYe1ocgyU1Ml5QrsaMKPrT+ oLAiG5AtdaSx3ki7mtV1sjviib/sqWXsLDgXK0fHhSHM+q8jQ4Z87+o/aFRJij51n9f/ HDig== X-Gm-Message-State: AA+aEWYz7l8yjlV0E2gb+VsELVJp8jY3qrMIURf3tPLADdK8KxhKXkcj Aphn/g0D8yxWCFUKErk9Im6d7Q== X-Google-Smtp-Source: AFSGD/UfhHk4UsCzPn/eAc1UCLzaQXf6ETh/uaMawQcc+6G7rBPGahcf/FhFDVQ7YPe4Sfkg3pEBVQ== X-Received: by 2002:a19:a84e:: with SMTP id r75mr1697958lfe.45.1543513649619; Thu, 29 Nov 2018 09:47:29 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id j76-v6sm393983ljb.12.2018.11.29.09.47.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Nov 2018 09:47:29 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Daniel Lezcano , linux-pm@vger.kernel.org Subject: [PATCH v10 12/27] drivers: firmware: psci: Simplify state node parsing Date: Thu, 29 Nov 2018 18:46:45 +0100 Message-Id: <20181129174700.16585-13-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181129174700.16585-1-ulf.hansson@linaro.org> References: <20181129174700.16585-1-ulf.hansson@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181129_094736_355097_F0B27F82 X-CRM114-Status: GOOD ( 17.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ulf Hansson , Vincent Guittot , Geert Uytterhoeven , Kevin Hilman , Stephen Boyd , Viresh Kumar , linux-kernel@vger.kernel.org, Lina Iyer , Tony Lindgren , linux-arm-msm@vger.kernel.org, "Raju P . L . S . S . S . N" , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org Instead of iterating through all the state nodes in DT, to find out how many states that needs to be allocated, let's use the number already known by the cpuidle driver. In this way we can drop the iteration altogether. Signed-off-by: Ulf Hansson --- Changes in v10: - New patch. --- drivers/firmware/psci/psci.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index d50b46a0528f..cbfc936d251c 100644 --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -290,26 +290,20 @@ static int psci_dt_parse_state_node(struct device_node *np, u32 *state) static int psci_dt_cpu_init_idle(struct cpuidle_driver *drv, struct device_node *cpu_node, int cpu) { - int i, ret = 0, count = 0; + int i, ret = 0, num_state_nodes = drv->state_count - 1; u32 *psci_states; struct device_node *state_node; - /* Count idle states */ - while ((state_node = of_parse_phandle(cpu_node, "cpu-idle-states", - count))) { - count++; - of_node_put(state_node); - } - - if (!count) - return -ENODEV; - - psci_states = kcalloc(count, sizeof(*psci_states), GFP_KERNEL); + psci_states = kcalloc(num_state_nodes, sizeof(*psci_states), + GFP_KERNEL); if (!psci_states) return -ENOMEM; - for (i = 0; i < count; i++) { + for (i = 0; i < num_state_nodes; i++) { state_node = of_parse_phandle(cpu_node, "cpu-idle-states", i); + if (!state_node) + break; + ret = psci_dt_parse_state_node(state_node, &psci_states[i]); of_node_put(state_node); @@ -319,6 +313,11 @@ static int psci_dt_cpu_init_idle(struct cpuidle_driver *drv, pr_debug("psci-power-state %#x index %d\n", psci_states[i], i); } + if (i != num_state_nodes) { + ret = -ENODEV; + goto free_mem; + } + /* Idle states parsed correctly, initialize per-cpu pointer */ per_cpu(psci_power_state, cpu) = psci_states; return 0; -- 2.17.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel