From patchwork Thu Feb 28 13:59:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 159374 Delivered-To: patches@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp671371jad; Thu, 28 Feb 2019 05:59:33 -0800 (PST) X-Received: by 2002:a2e:9f49:: with SMTP id v9mr4712103ljk.77.1551362373120; Thu, 28 Feb 2019 05:59:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551362373; cv=none; d=google.com; s=arc-20160816; b=xRx+dD9oAqh5kwePZQfGS88senQnLSCM+wnAkvZsGX+zsgeLpo2HFIO+nfdv0Bbgxn IQAtuZv+96zURUM/hh9CjPksGM65ugfdNeRz/qJFsRNTGBBY9xBdQo54VnCqfSd9+6Wp +Z1I8oPDg3dof9PXtpDgwURgKM2wUHOhJh1XDgB2AE+0Trg2VHms/h2fZBRz3XZqa7+A 5Xy8mkLZNE0aS3yX0elZcO4lPtQ0UZLxvNqacZ7j8HUe/siw2jvppcBBQvzdFu/9+V4N iPBjLwhJpvewPQaV9HDpzwH52bQxFVBZlfd5JYFdZc6iOTo5DccNkU6Bm48B+ad7aueE MFTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tetivCWSellxrqLjg5oJkokMZQX4qsIXobIakEVk0Q0=; b=altputKFkcfUP6PVMjU6+hrnXfgEkTuVZ7qnKBdIdV12cHBLy02xQfy70/xzhVq6xg TNMLp1WexMJwcXmTd1dgvGHCXndRR9pWLITtGlWub1M5L6ZrztVhS6671KiwsqgeylEy kk//M6jxTAC51v9OLtudPeAuR6RDPTqbKs7jx2enRcWNUmDnzP4rhKVDXkUfSWo3tpE7 nJtNm8DtWkE2CyXSOWB9ppIhJz6zs7HJJ7hKqEkSkGxKTlJHoyJn+yWwl9P2VOGVBdSq zJBwleDyuycS94S+cDXZ+m5q6E7SG4UBUDNIJ8MkSDjfvPGzIJ+7vmvKGUCvaxiNB36v EQ+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VNKVdDKp; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id y89sor3610463lje.18.2019.02.28.05.59.32 for (Google Transport Security); Thu, 28 Feb 2019 05:59:33 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VNKVdDKp; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=tetivCWSellxrqLjg5oJkokMZQX4qsIXobIakEVk0Q0=; b=VNKVdDKp77nYxziG1tXDB+1+YC00/86ektZ137JuDXUybb+p7BQWP/4Nds+yqaWlib rDjw3j1RqlhfUzBaH0AhhEP3Oal0r0XwMCa89QOTJGA8qt68/R7WnvbQg23bXvoPHmA1 /+bIe0i+NlwTCQ1sv6umubGa15+P+2rAGbGXpMzM50QabTblZh6vh0GLMy2yhKPIinTK gvv1liY4PiqHQoOL24Lc50pUtriYV8B+8xRnBMe9TWpLa8IR32lR+o4JoTVyrb+DLU6P 45yDEaBHUzdwLkw7YMe5csbeq8sqZ1TXrTHoviYLSuzSWdtpnTLoVac9lYSgmfg65C0L p1lw== 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=tetivCWSellxrqLjg5oJkokMZQX4qsIXobIakEVk0Q0=; b=ht7p3JnTVVR0Q1fNII+EOxFO8Bx+186BQCMrCLrQ1MOprTkDmPG8cZxvyUuf3q2qaV MbkftpTugm9KxCe3aKszFwR5ljwi7Y4s7Dp7bVxfn2HL9SB+J2UaM4Om0uwZTB572K5Y d/EL7Yg0q413m/kcx9QUBlX1BzHkTSO8bwKJoUiLKhL3k4fNKiMdTrFWxSFYib7XPNnA yJ6asLAtxc57LP+wXNkjifE9lc3ZLFEI46EOpNznSeV8O6bEIyteOVc/JpHM8cn2SRBX dMjsFFyh6xpHRpH+VIoSqCd2DjEEKqeYHg1jTGeKE5S+ErU8jifZsi0dNf1S2E1LzkUB 3p+A== X-Gm-Message-State: APjAAAU0DQT+uZqEwTYuU1F7YjxCWIrzGVy9sZbWxC4gP0uFBx9jj8Hd 9V4lW8ZkvmaAWEkyrBuZmVo1OhtL X-Google-Smtp-Source: APXvYqx5P/Vqp+ogLd3hKLL4ats904OggXBtyJF+UQCD1hAYH52E0UWO5ytjMCr4hSE78iI1sOvulQ== X-Received: by 2002:a2e:2c0d:: with SMTP id s13mr5097543ljs.96.1551362372749; Thu, 28 Feb 2019 05:59:32 -0800 (PST) Return-Path: Received: from uffe-XPS-13-9360.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id v20sm4090265ljv.83.2019.02.28.05.59.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Feb 2019 05:59:32 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland Cc: Daniel Lezcano , Lina Iyer , Ulf Hansson , linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/7] drivers: firmware: psci: Simplify state node parsing Date: Thu, 28 Feb 2019 14:59:17 +0100 Message-Id: <20190228135919.3747-6-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190228135919.3747-1-ulf.hansson@linaro.org> References: <20190228135919.3747-1-ulf.hansson@linaro.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 --- drivers/firmware/psci/psci.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) -- 2.17.1 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;