From patchwork Wed Dec 11 15:43:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 181270 Delivered-To: patches@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp701740ile; Wed, 11 Dec 2019 07:44:02 -0800 (PST) X-Received: by 2002:a19:f514:: with SMTP id j20mr2467123lfb.31.1576079042249; Wed, 11 Dec 2019 07:44:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576079042; cv=none; d=google.com; s=arc-20160816; b=MuEmZmvplXMRYzqtMy0XQyeLW9oI8lUTLu2G0uCsfr891vgmhegSRhzxMDfBEKC0rA bAgZg4Bp4P5ThuOWvp+7Hqg3RUn8Qx9UejKdfm91OGu7pHjgSlEo73/p8J76Ho+k+Qtg iYRZdWPcX+35psX8grsAMtoe16SWQn0mPbwvGlw8+UTp0sksGzl1wTVQL7AdO15xQtl5 QuE6A51puXcXAf0MOPTr7r7Mb1TTN1dlv8WyNHQsXPM0m48x0OGi/5N42H8zS6CeKpoH 9fJvY/0sIQ2QxktRY4nFX7C+Zn8E7MTTwMbHwI7ylzOj9C6uSQ4AyvmCbd7AJ+ddM7Ju Ofog== 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=S2XemtX4hMYuEUmPXCsFCarqlwpwIjzNfad7a4a1Y1I=; b=f7EM7ApSB4nJB6I2jfnJOXJQzB8jIlcD1tmGZCrjp2rVQoZUxb4MdmfejDYaBdGKUc 7YJ4VH5CoejQNbPJuRAVRj4Ww2zbZWYKpmSfO4GQt4R+xiBjT5RGEAps+IIzNPgEv1Z/ ax88XpGrqnPVoXri+GohDCuhb3+OVV6fLecYHjecDpv4EV9OrZwWX0iG9JF5ku/UdlLF QGJoP7B5FGrKVasadXNNg5xZtz+1S2s+0QZla8f9LVaiOYTNp4lJC4cvdarMO2nZQqen iSmA5aaQGzuaQJllyn2KHWpwYbasd+wmRq/dcSoQy2m/dSjQNWxPQPC1PPw89/ObXIpo p+2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zJsktAeJ; 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 28sor871156lfr.24.2019.12.11.07.44.02 for (Google Transport Security); Wed, 11 Dec 2019 07:44:02 -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=zJsktAeJ; 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=S2XemtX4hMYuEUmPXCsFCarqlwpwIjzNfad7a4a1Y1I=; b=zJsktAeJPVQv9poyv+aQY1Kiea0KoaXHBS/enAVvKiWoIkm3Qj8bFFC5H5xBZaGDnb EqSZcEdehRJsS0IhuBVQ/TKu4hVHgkJXnlnFrhNrhdZkVH9FerJrdG1mB+HU05AmTaR1 MJbLfJC4ikUYact0RaEanF53QtjHKyT8x7zOD56Yo60xroNsezkUGPM6ZHPEgHK4Ysn0 HU2yKAsyxVzmNNmgjRM41m9AscNNW6t7fq/8hYlNOTDpl3xReNh1KvM6A5z1JG4PiQUF 2j/C3zVIivL0hiUM84TUxwCENGf0SLmV2eEGq1zXvoXA9W2+mFofRicESuLNkkNpINyL ZHaQ== 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=S2XemtX4hMYuEUmPXCsFCarqlwpwIjzNfad7a4a1Y1I=; b=ioJlDOkava7/wD+Ey5rLetdO6spy7AV3GqoK3Ah7XBmfAfs87ThaGAkP+Qcv6UGCSS JXU62yGCk/Ok2DHAsdRIgIuga33UMGduO8Eiq1tNP3J8a8J19xauJ9DOKdBZSXiLtRZ4 inDQLh1KhXQefSsXlv0I1y5PzDj0eZA5in9d143TPivz7X8JewWPVSOk/bXAGuEQYm4a g6a2p8XzK1I3w3O+5+gK4O1X3hVejxKeoQWi9m2Yo2HR9nSZnTZ4st15Ed6jSSAPDkIR Et3lL/kWnhjdvboMmPp6ydEdUa4eeMus5i11czgCe2sX1bJgg8KmFy+fLM/gW0aO9/Ti cFng== X-Gm-Message-State: APjAAAVsAu4O1X0CbNUEnJzyi1CkJVJ6YdO8Pjkkiwy5INlEcVPRlE0r 8Xk0WGgs3vmawR4BaqM0a19x2xFTs/xQZg== X-Google-Smtp-Source: APXvYqxqYN5IMFGsrJLgOcWZ7/rfrvTcU1Mt/hLAaC2UQmkeUZesn74SHY0YLNwolOTv/jADHPA8hg== X-Received: by 2002:a19:ec14:: with SMTP id b20mr2691734lfa.63.1576079041735; Wed, 11 Dec 2019 07:44:01 -0800 (PST) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id b14sm1389608lff.68.2019.12.11.07.44.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 07:44:00 -0800 (PST) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Rob Herring , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Mark Rutland , Lina Iyer , Vincent Guittot , Stephen Boyd , Andy Gross , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v4 06/14] cpuidle: psci: Simplify OF parsing of CPU idle state nodes Date: Wed, 11 Dec 2019 16:43:35 +0100 Message-Id: <20191211154343.29765-7-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191211154343.29765-1-ulf.hansson@linaro.org> References: <20191211154343.29765-1-ulf.hansson@linaro.org> Iterating through the idle state nodes in DT, to find out the number of states that needs to be allocated is unnecessary, as it has already been done from dt_init_idle_driver(). Therefore, drop the iteration and use the number we already have at hand. Signed-off-by: Ulf Hansson Reviewed-by: Sudeep Holla --- Changes in v4: - None. --- drivers/cpuidle/cpuidle-psci.c | 35 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 18 deletions(-) -- 2.17.1 diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 361985f52ddd..761359be50f2 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -73,30 +73,24 @@ static int __init psci_dt_parse_state_node(struct device_node *np, u32 *state) return 0; } -static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) +static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, + unsigned int state_count, int cpu) { - int i, ret = 0, count = 0; + int i, ret = 0; 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; - - count++; /* Add WFI state too */ - psci_states = kcalloc(count, sizeof(*psci_states), GFP_KERNEL); + state_count++; /* Add WFI state too */ + psci_states = kcalloc(state_count, sizeof(*psci_states), GFP_KERNEL); if (!psci_states) return -ENOMEM; - for (i = 1; i < count; i++) { + for (i = 1; i < state_count; i++) { state_node = of_parse_phandle(cpu_node, "cpu-idle-states", i - 1); + if (!state_node) + break; + ret = psci_dt_parse_state_node(state_node, &psci_states[i]); of_node_put(state_node); @@ -106,6 +100,11 @@ static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) pr_debug("psci-power-state %#x index %d\n", psci_states[i], i); } + if (i != state_count) { + ret = -ENODEV; + goto free_mem; + } + /* Idle states parsed correctly, initialize per-cpu pointer */ per_cpu(psci_power_state, cpu) = psci_states; return 0; @@ -115,7 +114,7 @@ static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) return ret; } -static __init int psci_cpu_init_idle(unsigned int cpu) +static __init int psci_cpu_init_idle(unsigned int cpu, unsigned int state_count) { struct device_node *cpu_node; int ret; @@ -131,7 +130,7 @@ static __init int psci_cpu_init_idle(unsigned int cpu) if (!cpu_node) return -ENODEV; - ret = psci_dt_cpu_init_idle(cpu_node, cpu); + ret = psci_dt_cpu_init_idle(cpu_node, state_count, cpu); of_node_put(cpu_node); @@ -187,7 +186,7 @@ static int __init psci_idle_init_cpu(int cpu) /* * Initialize PSCI idle states. */ - ret = psci_cpu_init_idle(cpu); + ret = psci_cpu_init_idle(cpu, ret); if (ret) { pr_err("CPU %d failed to PSCI idle\n", cpu); goto out_kfree_drv;