From patchwork Thu Oct 4 04:16:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 148088 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp453588lji; Wed, 3 Oct 2018 21:16:59 -0700 (PDT) X-Google-Smtp-Source: ACcGV62Qoz+seOHqwHJ9QAd0Os09dTAtrzBG6yUyDufcwjbKNmS+QC8FzyNb9NtqjZIx6rXS7EuD X-Received: by 2002:a17:902:680e:: with SMTP id h14-v6mr4669750plk.177.1538626619375; Wed, 03 Oct 2018 21:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538626619; cv=none; d=google.com; s=arc-20160816; b=0sFeS8QcKpTO6LlbrIi0UfKFUFmoqFQKsmjzz/AitPglk3ptUfdtJJWjzJT+tf3JEm su1dts82wvNpjAD+XOnWz983Q+/TKwx7rKMIBjqzEQB3Gj781VGATGnjyBETRMUaGmoJ ylJ6xFuW6IevrJXGR6eaCVGFtv7SzJD1qjF8nt+kkcY3kNRuk8dF36Fnq0spP/7kQXDx iIjBnGq9H7M0SdgK9GfCneOg3L7ulFf3i0O/UyCBOmwbi1rezku3iWu/VRWbBe671Jci B/hgKbP6Tg9ZO0fVVruWhacDTnkq0Z6Px/1kw8XbYMt8UdSJXqLU5Jady/NRtnlOarZY rNhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=qmKhPk9+e4QtLT1wSGU4V2sT6TEBWes/IdprVh2Q0io=; b=uExxqU3lv64+wIwDWdslH7B6gQvk7xg1Z5Jgu6IvofP1SVI1ACW0aFba/yqiYImwTk onA45yAV5DrVIm0mwvnDibaQfTIURjS3HI8FC6mJ8dU69N5vAwlqzw2Lcrcco1NV+DK4 ZPoV70dwE71QsN/Efcwa/0CKtRPCYfZUzn4N8mFnvXGBgZYUmkORvDQM3BrPuIERF+fx QnYE1tGN29Fu6wkJycMzfT5xghxWrbOKHVLENzZvURSAQH+B9po3f+fYPqQjKkoI9+AS /6GFt2irQW01TCsH0S7Ky+q+biHrucRwHolG+zG1LBzcraZBKIH/qwRhmZp7mHEkqdak i47A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="I/lWQzhr"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j7-v6si3839822pfk.203.2018.10.03.21.16.59; Wed, 03 Oct 2018 21:16:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="I/lWQzhr"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727204AbeJDLIE (ORCPT + 32 others); Thu, 4 Oct 2018 07:08:04 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:33919 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726813AbeJDLIE (ORCPT ); Thu, 4 Oct 2018 07:08:04 -0400 Received: by mail-pl1-f196.google.com with SMTP id f18-v6so4484780plr.1 for ; Wed, 03 Oct 2018 21:16:45 -0700 (PDT) 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=qmKhPk9+e4QtLT1wSGU4V2sT6TEBWes/IdprVh2Q0io=; b=I/lWQzhr52XigUSMIbKX9KYqS94l1frlMSEWlqWA5e8XWYVzKQzlqWPff2nS/9fSWu dSoKVYSF4kQOfVueA9eI8+98chCNa6RyBd+t4uaCF4+fxoUoNaVg4vHMXuDfV7bYJymS J7fz8sti+e28HxD/J+QjjTp15B/DKPRPAXnuI= 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=qmKhPk9+e4QtLT1wSGU4V2sT6TEBWes/IdprVh2Q0io=; b=GUsztpROklXRCbKLgAm47tDHp5Nt4H9ogwtmSVT+ok7FKU6S4H2L5Kjioy4SBe0LIS FpDxDutcD1TiY9716Z+G/T5uRm93uS1SQCa1jm26m5p87VyWNBow22R2iadvqq2OxPJf iwmuUPMZn3QrXXTDJdmrg9JGj0O/ymSLnzwHerw4Zt9Xo77OTUEHthJJXjtCQnjVnAlf g+j3UeLiMskjrRycQvtd8jy/2SLBZPIWIPx34e0LTTLLrO8u50D8WMt7/jWD491PnUYL jNhl0jwZbi2xT6EllG8HnCoGnZUygA2/CYegPcLrieQZxMTmQ1F/mhilFtJA2ao2mUgu OQ1Q== X-Gm-Message-State: ABuFfogKDzhZR/V7i3W7WC6XsJLI78BLytzuOgiZAMt4VmvUGTKeFaOq pUdSi0E/7irti/ACtND/CyftVw== X-Received: by 2002:a17:902:bb88:: with SMTP id m8-v6mr4097054pls.120.1538626605578; Wed, 03 Oct 2018 21:16:45 -0700 (PDT) Received: from localhost ([122.172.76.11]) by smtp.gmail.com with ESMTPSA id 25-v6sm8577065pfm.36.2018.10.03.21.16.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 21:16:45 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Rafael Wysocki , niklas.cassel@linaro.org, d-gerlach@ti.com, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] OPP: Improve error handling in dev_pm_opp_of_cpumask_add_table() Date: Thu, 4 Oct 2018 09:46:20 +0530 Message-Id: <50b6b87c8484da8bb5dcce00f84ec80aee8fc2bd.1538625101.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The error handling wasn't appropriate in dev_pm_opp_of_cpumask_add_table(). For example it returns 0 on success and also for the case where cpumask is empty or cpu_device wasn't found for any of the CPUs. It should really return error on such cases, so that the callers can be aware of the outcome. Fix it. Signed-off-by: Viresh Kumar --- drivers/opp/of.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) -- 2.18.0.rc1.242.g61856ae69a2c diff --git a/drivers/opp/of.c b/drivers/opp/of.c index a71ff3acca0f..67a384c8ead2 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -614,16 +614,18 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_of_cpumask_remove_table); int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask) { struct device *cpu_dev; - int cpu, ret = 0; + int cpu, ret; - WARN_ON(cpumask_empty(cpumask)); + if (WARN_ON(cpumask_empty(cpumask))) + return -ENODEV; for_each_cpu(cpu, cpumask) { cpu_dev = get_cpu_device(cpu); if (!cpu_dev) { pr_err("%s: failed to get cpu%d device\n", __func__, cpu); - continue; + ret = -ENODEV; + goto remove_table; } ret = dev_pm_opp_of_add_table(cpu_dev); @@ -635,12 +637,16 @@ int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask) pr_debug("%s: couldn't find opp table for cpu:%d, %d\n", __func__, cpu, ret); - /* Free all other OPPs */ - _dev_pm_opp_cpumask_remove_table(cpumask, cpu); - break; + goto remove_table; } } + return 0; + +remove_table: + /* Free all other OPPs */ + _dev_pm_opp_cpumask_remove_table(cpumask, cpu); + return ret; } EXPORT_SYMBOL_GPL(dev_pm_opp_of_cpumask_add_table); From patchwork Thu Oct 4 04:16:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 148089 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp453598lji; Wed, 3 Oct 2018 21:16:59 -0700 (PDT) X-Google-Smtp-Source: ACcGV62VaBYaFq0RxoPsqG1X63vXEMUozXiBvftuREpyN3i4a38SfOEjFXHPulzpO7+Gz5gs9HSF X-Received: by 2002:a17:902:694a:: with SMTP id k10-v6mr4613739plt.166.1538626619741; Wed, 03 Oct 2018 21:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538626619; cv=none; d=google.com; s=arc-20160816; b=U2/4KN/EsPvTJ8xttwgqCkClNJyr63c7XKv3Xas7hTK6y/nKVqDjaifi7rdUQH8CbX BLMec5gRFJuhar/8GmfB2aAZ6ZVqBTiQTsHQo674j6NX8I1Z9r6oe++dN4Zxr1i0U0Xn g6r9ivJEodHZbpv9BnxgJhk3AqrNSG9t0ZZztYUCD1D4Ufk+vhZ0MWLZOcELQLAhaFX3 lPootzc0Yarh/2tN3O+FCecRq2NaVGVIXzNMO1tuwzFJc+vX10cppUp/tmZH/MnMo6tL CS89oEeGgSG/b73zo7jjaoV7q2+jZzjIVfJh+npkl577r6/zVxw302bvleTzVimuQi4B u/JA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=3QJUvhl8nGSVXoryOyi2C2kj4Aa4ByPO+MXzdk10tAg=; b=YaKXepNeWC+Om99GS9AOXrnhzKbsiMzuQOoq1krtBfYxgC5BogbKeu7Dn+r6FxmMem JZmodkzcbVKZdoxQkyePRUWAw1TkUDtJ+1pLaXCEgamyxqtpgYwbsZP7lLQUMnSlBuom 5LVvMEJBiDCAT46hEKSMQLkRXw1nkrqlx3+KipM1RQdOJmNesrJ+Zh+Za//i8Rucpr14 r3wBbjlqlZyaNAWTj9+kRMOy9SY2Yc5mlQ/5gwx21t3dyrBQFa/803ceQBoykg8Tx0Ae W8T1xZtp/8CTFHY6iLNW/H2YNDaDjbjYFHuB8PULeZSQ5mkGeakFFBwWDg40lh7aMmLL 3vWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aO9aKLH2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j7-v6si3839822pfk.203.2018.10.03.21.16.59; Wed, 03 Oct 2018 21:16:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aO9aKLH2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727273AbeJDLII (ORCPT + 32 others); Thu, 4 Oct 2018 07:08:08 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:46064 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726813AbeJDLIH (ORCPT ); Thu, 4 Oct 2018 07:08:07 -0400 Received: by mail-pf1-f194.google.com with SMTP id a23-v6so2689797pfi.12 for ; Wed, 03 Oct 2018 21:16:48 -0700 (PDT) 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=3QJUvhl8nGSVXoryOyi2C2kj4Aa4ByPO+MXzdk10tAg=; b=aO9aKLH2SfmEOHKra6+bLGLaNm9o7XO34U2tZaF3phoKTqJa7DuOY5Cr0zV0Fsa+yx 2gkJL2LgOog5CJXmQ0TbbJDP6C2tQMsZajIPaR4O/53PKLArqSam6X4WTD715Ojs4zpT K2WV/NA3s2Xs+3h9OxbSbX6zWSlxczsMLd0+g= 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=3QJUvhl8nGSVXoryOyi2C2kj4Aa4ByPO+MXzdk10tAg=; b=GCM/Vi2bzgce8xO5+mCj4IFP5cVrAPSHyNCqUzk/vE1ThknZBiyXl5naIZu+iqPrsu z9vqpD2XA7YN3GA1EbX4M/k26ltCdpLfi/H3YdA1YTjHTPblojAjvxkcjXAOrikLi4qQ vJjIt6jNtywfTt0qL0gIMf3twQdLnO5Uev797FLfzwp5I5eGztpB4C/+TIKsugRFy7Hb uN57RblJFHfrXOb1CKYSyzas8MwEygeDwE7ouWFU4LahTXMZmueCmnugn5WK0BmirQZ1 RtuXERKSVXZOzJoe36uz4FCLnMwqZloiFKFDPiJPyYetVPZZnFWrQhe/PWzsdD+9QXeU c7Hg== X-Gm-Message-State: ABuFfognmaZEf3y/PNo4M+3dpqBe7J9znzxoNjuCBZ0iwa6MyG2/7CmZ m0uLl6P0DDUakrDjQ6PPCaDyPQ== X-Received: by 2002:a63:f80a:: with SMTP id n10-v6mr4069559pgh.57.1538626608560; Wed, 03 Oct 2018 21:16:48 -0700 (PDT) Received: from localhost ([122.172.76.11]) by smtp.gmail.com with ESMTPSA id k86-v6sm446236pfb.167.2018.10.03.21.16.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 21:16:48 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Rafael Wysocki , niklas.cassel@linaro.org, d-gerlach@ti.com, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] OPP: Return error on error from dev_pm_opp_get_opp_count() Date: Thu, 4 Oct 2018 09:46:21 +0530 Message-Id: <09f662f95306f3e3d47ab6842bc4b0bb868a80ad.1538625101.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return error number instead of 0 on failures. Fixes: a1e8c13600bf ("PM / OPP: "opp-hz" is optional for power domains") Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.18.0.rc1.242.g61856ae69a2c diff --git a/drivers/opp/core.c b/drivers/opp/core.c index cdf918aaac34..2c2df4e4fc14 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -318,7 +318,7 @@ int dev_pm_opp_get_opp_count(struct device *dev) count = PTR_ERR(opp_table); dev_dbg(dev, "%s: OPP table not found (%d)\n", __func__, count); - return 0; + return count; } count = _get_opp_count(opp_table); From patchwork Thu Oct 4 04:16:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 148090 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp453605lji; Wed, 3 Oct 2018 21:17:00 -0700 (PDT) X-Google-Smtp-Source: ACcGV60S2QokIyTgehlHzkRDvAw7BGHOmge8pkODXKPPRqOosjTNcer76JdN9mIIu6k3yX9gUQZZ X-Received: by 2002:a63:e141:: with SMTP id h1-v6mr4038996pgk.47.1538626620088; Wed, 03 Oct 2018 21:17:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538626620; cv=none; d=google.com; s=arc-20160816; b=WYFptTUPfnyZsrdjw/WBKuIzuK8Kjj+bRBhwhQhCq6D5hJ014Y6zNBo66Sap6gkACs wFMDUVgpDZ2oXehuI5UQQQRCHQDUe2yrbSXpu1rqpxvRAMzmmptqkEhyAI8e4matEJL8 A6GIKnM/hKEmSAyNxP3bm8i8sgO5hgY6Eb5KQ9EbahmFdJdrQSGhguftgB7ZcFz99CAd eJoL+zCvzpt/CuvKeD4YwD+Mwu0x7ZVsindZGGytcEd9FWOOzwH3Cymm+57zijedqtzT 0yxBDuCaWpIAWk4ixX4nLq66Zk15WxOT/+oC9PjuO4zBgw17VJN32VIYl0y3Lq/DDVbB RvhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=+O/nJKlKvJKvAgRGQDY3iXasacOdOlADyrAzR7qH0as=; b=iGJsydeJ3DlB5i0S5Pe/Eyq8FnRWnuJ9ui9lefKFKQUcQS85jl0hnmZYSVPnFiL0pg JzY3WNgXllcSsOLJjqllCh3Sz5fxjsdDCoCwE42UMFTyftGpgSxRBpRLMnqXcl/6QYjF 6VKZy6I4OP0JV63hdi7BihLc4KC+qBYiypC72hWeOSl6vpfX6ctx9Wk2E9OvjRjuQVgH n0hsobQIBsr/E9UFMXDdAo49f7BW9EjChRPUPuF96sfFJ+Ho2yRsvuOe+V/RH29SXCxh h0QWObyBYQu7kEiDDICGeFqFgLUboixKnlQG0JyElOEpsSH1jDmlb6Bq585pNDzoBDOD DYqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gFb74++5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j7-v6si3839822pfk.203.2018.10.03.21.16.59; Wed, 03 Oct 2018 21:17:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gFb74++5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727319AbeJDLIL (ORCPT + 32 others); Thu, 4 Oct 2018 07:08:11 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:34868 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726813AbeJDLIK (ORCPT ); Thu, 4 Oct 2018 07:08:10 -0400 Received: by mail-pf1-f195.google.com with SMTP id p12-v6so2721311pfh.2 for ; Wed, 03 Oct 2018 21:16:52 -0700 (PDT) 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=+O/nJKlKvJKvAgRGQDY3iXasacOdOlADyrAzR7qH0as=; b=gFb74++5sBSXBRKyRh9zoskCFGBN0c5YX2PiIweIlXc2TjGMH/aoj3Zq2ALHwLEN4P GypB9imQMIOXMANH/NQNTTVSW5n+Ht9OUqCviu1QCl2IBYjRSR5hyMc/rGCRChly8OVX tg5KcI9qNsaAHsoKMhlR+1gM2aq1ONfI2SmPI= 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=+O/nJKlKvJKvAgRGQDY3iXasacOdOlADyrAzR7qH0as=; b=J2uwyLTL/wj8s/jaKjkiQZ9FXXDQBJYLwi1c+TdQwoRjFBwugSuHuF8gwllfkQ876u atZsnRq1o2WXJjIGVIiFwBMSE2WXE7+sRUdc4u8OvStHjn2T27aP4WTGTyUQrOB7UaWi eQOGxAV/dP69O3JNe8Wmjy0Niw/0kUYGyb/WKyKQh6OB7QD1PNqiSPPO72nef8w/L9ID 34DbUvmDBHdYx/upj5XeCiLtwleYJxdPsxg/g0jjaT+W90fV2o0OJglMa5Lb+VGuy/Pa MDDueoC5vhnAOqji3FNRtF9Y3a3eJgOWqhGvZS3acfzbSm3Vl/PwKpknuBQaf1JgD4C1 udtA== X-Gm-Message-State: ABuFfojzVnvU/NbjuvjHbdbt4mvuEohFodU7GPcXF4eYTex3yTY/a/Qw L8vVkixTBMzB7a2mqhTmb/KV/+8f7Oc= X-Received: by 2002:a63:65c7:: with SMTP id z190-v6mr4054400pgb.146.1538626611807; Wed, 03 Oct 2018 21:16:51 -0700 (PDT) Received: from localhost ([122.172.76.11]) by smtp.gmail.com with ESMTPSA id c79-v6sm5304901pfc.92.2018.10.03.21.16.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 21:16:51 -0700 (PDT) From: Viresh Kumar To: "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Stephen Boyd , Nishanth Menon , niklas.cassel@linaro.org, d-gerlach@ti.com, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] cpufreq: dt: Try freeing static OPPs only if we have added them Date: Thu, 4 Oct 2018 09:46:22 +0530 Message-Id: <51c99dd2c06b234575661fa1e0a1dea6c3ef566f.1538625101.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We can not call dev_pm_opp_of_cpumask_remove_table() freely anymore since the latest OPP core updates as that uses reference counting to free resources. There are cases where no static OPPs are added (using DT) for a platform and trying to remove the OPP table may end up decrementing refcount which is already zero and hence generating warnings. Lets track if we were able to add static OPPs or not and then only remove the table based on that. Some reshuffling of code is also done to do that. Reported-by: Niklas Cassel Tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq-dt.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) -- 2.18.0.rc1.242.g61856ae69a2c diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c index 0a9ebf00be46..e58bfcb1169e 100644 --- a/drivers/cpufreq/cpufreq-dt.c +++ b/drivers/cpufreq/cpufreq-dt.c @@ -32,6 +32,7 @@ struct private_data { struct device *cpu_dev; struct thermal_cooling_device *cdev; const char *reg_name; + bool have_static_opps; }; static struct freq_attr *cpufreq_dt_attr[] = { @@ -204,6 +205,15 @@ static int cpufreq_init(struct cpufreq_policy *policy) } } + priv = kzalloc(sizeof(*priv), GFP_KERNEL); + if (!priv) { + ret = -ENOMEM; + goto out_put_regulator; + } + + priv->reg_name = name; + priv->opp_table = opp_table; + /* * Initialize OPP tables for all policy->cpus. They will be shared by * all CPUs which have marked their CPUs shared with OPP bindings. @@ -214,7 +224,8 @@ static int cpufreq_init(struct cpufreq_policy *policy) * * OPPs might be populated at runtime, don't check for error here */ - dev_pm_opp_of_cpumask_add_table(policy->cpus); + if (!dev_pm_opp_of_cpumask_add_table(policy->cpus)) + priv->have_static_opps = true; /* * But we need OPP table to function so if it is not there let's @@ -240,19 +251,10 @@ static int cpufreq_init(struct cpufreq_policy *policy) __func__, ret); } - priv = kzalloc(sizeof(*priv), GFP_KERNEL); - if (!priv) { - ret = -ENOMEM; - goto out_free_opp; - } - - priv->reg_name = name; - priv->opp_table = opp_table; - ret = dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table); if (ret) { dev_err(cpu_dev, "failed to init cpufreq table: %d\n", ret); - goto out_free_priv; + goto out_free_opp; } priv->cpu_dev = cpu_dev; @@ -282,10 +284,11 @@ static int cpufreq_init(struct cpufreq_policy *policy) out_free_cpufreq_table: dev_pm_opp_free_cpufreq_table(cpu_dev, &freq_table); -out_free_priv: - kfree(priv); out_free_opp: - dev_pm_opp_of_cpumask_remove_table(policy->cpus); + if (priv->have_static_opps) + dev_pm_opp_of_cpumask_remove_table(policy->cpus); + kfree(priv); +out_put_regulator: if (name) dev_pm_opp_put_regulators(opp_table); out_put_clk: @@ -300,7 +303,8 @@ static int cpufreq_exit(struct cpufreq_policy *policy) cpufreq_cooling_unregister(priv->cdev); dev_pm_opp_free_cpufreq_table(priv->cpu_dev, &policy->freq_table); - dev_pm_opp_of_cpumask_remove_table(policy->related_cpus); + if (priv->have_static_opps) + dev_pm_opp_of_cpumask_remove_table(policy->related_cpus); if (priv->reg_name) dev_pm_opp_put_regulators(priv->opp_table); From patchwork Thu Oct 4 04:16:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 148091 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp453610lji; Wed, 3 Oct 2018 21:17:00 -0700 (PDT) X-Google-Smtp-Source: ACcGV61ahVKskz7nehXchyxEgPmrYZRkGPhfzE37owm1RW333wvKZbv4CystyQ/RFRlAYSszOM2o X-Received: by 2002:a17:902:1566:: with SMTP id b35-v6mr4629186plh.135.1538626620482; Wed, 03 Oct 2018 21:17:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538626620; cv=none; d=google.com; s=arc-20160816; b=WjZXJ0E9l77YUfeI3/qWqlnz6Ww7zcoln4v7vQstt0MyBxfel5B+p4KDBbxw7zzt5L /Szy3V3IrlJQV3IsYDhmlpphV2N/1IK9BeCTkaxPr0r1GBy45TJQApAS69qFX+OVIIfF vBUMHWPi7XpFxnGEer0AAdMwudNcp14a33BVnYLm3WFtLl0bER5hHdoeg1zwQy1xhtEu UETOXuAuYr39PwVguLLy5fk8qLpNKO4xd3UuHtabPLj8WQtVhMYjPTevOco6C2Xz4DjG 5lDLq9ewpeHt3iV72YINwxplLRjG0sSvRltmsL0J2P9Q22QgaWp+asVXmEx4A4S8rYt/ VRqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=osHUwuiO0Yt9WNQtlpO1yAjh4ObC+ZQbro/V9Mp9LXI=; b=EXtwN+fp/mcSP7Cr7//zxrto/dSgZaq+sBsRMuVBd1NE/Vj4+CnSvDYOOK+/TaQTYK IIOMselHqL8bQzykKvEkIzmARgc8X48/XYYZxchT54UlgpLLlxt05ZlIH0B7xt5I5/2M qi7SwnV5LVKoHpFotaWas6e2YzmlBYLBXNeUda3DYxogn7iORYGHAcKjHzzP3IaAVdOs mjzyGW6v6sL2NBlymVmkuhaxCF75JQZCg9w1VZ14GmCeL4N4Nxjos0R23Mk8O1W+ppWS Mt1DWUigi9OhTX+sqL6XxlD5d1942NJ2aUV0uacvqPjVoC0wXgL6UGkI6VsIVAsehE2K rMZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="A2F/LP2j"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j7-v6si3839822pfk.203.2018.10.03.21.17.00; Wed, 03 Oct 2018 21:17:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="A2F/LP2j"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727368AbeJDLIO (ORCPT + 32 others); Thu, 4 Oct 2018 07:08:14 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:35940 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726813AbeJDLIO (ORCPT ); Thu, 4 Oct 2018 07:08:14 -0400 Received: by mail-pg1-f195.google.com with SMTP id f18-v6so2535135pgv.3 for ; Wed, 03 Oct 2018 21:16:55 -0700 (PDT) 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=osHUwuiO0Yt9WNQtlpO1yAjh4ObC+ZQbro/V9Mp9LXI=; b=A2F/LP2jGLnAGdxdQguLbKk9fjbn+UtRFhwsAdUi42XvqiwNBZGDzefFKJw9QkCBGX rCN4ckiV29lETBHTzwIpDP5PE8zZN0HenREVYIizIRFcQGrXSKHQ+E/RkI5B1u6bCAIo C3D8i5DB2nGBhc9sqqHylUXBwjEO/ovIM9v1k= 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=osHUwuiO0Yt9WNQtlpO1yAjh4ObC+ZQbro/V9Mp9LXI=; b=YbaoO/371tCGnzIL0BExZBcxvHE0Ioib7uAwaa1SEX4O2heW9RCi41SVK/T1yD/fWw Es83cHNjZY1m52clv9AUuYFuYjc5f+bssPPd40bWEH+sAms5TfB7ha5frnoVcKI2+H6Q +XxAbFqfoyoVNz6Jg2W3KEGLUT1X7EB2OCO3uT7d+861YHG8tQ+2ZJlvWtpSwqOeVj7A eb1RsezLa8AUYYXZMkln9pi3i/XJIBJhVKGAuphrWr4EbT+szztQjlSO0RrPzycD+Vlr pUqKSOQvsvLFyj62o8L682cR3BgYXYNEOLOaah3Mlc/nnuK8T8Kuc7kEdpZ418IendDD yXPg== X-Gm-Message-State: ABuFfoic8ybhVOEaiA4r2YxLBC+fADq87YQJiyCzEKLCzk6/ke9fpxIg IOXIe6PH76z25MzK6xa5KkAYgg== X-Received: by 2002:a65:40cd:: with SMTP id u13-v6mr4055386pgp.334.1538626614909; Wed, 03 Oct 2018 21:16:54 -0700 (PDT) Received: from localhost ([122.172.76.11]) by smtp.gmail.com with ESMTPSA id w13-v6sm2882577pgs.89.2018.10.03.21.16.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 21:16:54 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Rafael Wysocki , niklas.cassel@linaro.org, d-gerlach@ti.com, linux-kernel@vger.kernel.org Subject: [PATCH V2 4/4] PM / OPP: _of_add_opp_table_v2(): increment count only if OPP is added Date: Thu, 4 Oct 2018 09:46:23 +0530 Message-Id: X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dave Gerlach Currently the _of_add_opp_table_v2 call loops through the OPP nodes in the operating-points-v2 table in the device tree and calls _opp_add_static_v2 for each to add them to the table. It counts each iteration through this loop as an added OPP, however there are cases where _opp_add_static_v2() returns 0 but no new OPP is added to the list. This can happen while adding duplicate OPP or if the OPP isn't supported by hardware. Because of this the count variable will contain the number of OPP nodes in the table in device tree but not necessarily the ones that are actually added. As this count value is what is checked to determine if there are any valid OPPs, if a platform has an operating-points-v2 table with all OPP nodes containing opp-supported-hw values that are not currently supported, then _of_add_opp_table_v2 will fail to abort as it should due to an empty table. Additionally, since commit 3ba98324e81a ("PM / OPP: Get performance state using genpd helper"), the same count variable is compared against the number of OPPs containing performance states and requires that either all or none have pstates set, however in the case of any opp table that has any entries that do not get added by _opp_add_static_v2 due to incompatible opp-supported-hw fields, these numbers will not match and _of_add_opp_table_v2 will incorrectly fail. We need to clearly identify all the three cases (success, failure, unsupported/duplicate OPPs) and then increment count only on success case. Change return type of _opp_add_static_v2() to return the pointer to the newly added OPP instead of an integer. This routine now returns a valid pointer if the OPP is really added, NULL for unsupported or duplicate OPPs, and error value cased as a pointer on errors. Ideally the fixes tag in this commit should point back to the commit that introduced OPP v2 initially, as that's where we started incorrectly accounting for duplicate OPPs: commit 274659029c9d ("PM / OPP: Add support to parse "operating-points-v2" bindings") But it wasn't a real problem until recently as the count was only used to check if any OPPs are added or not. And so this commit points to a rather recent commit where we added more code that depends on the value of "count". Fixes: 3ba98324e81a ("PM / OPP: Get performance state using genpd helper") Reported-by: Dave Gerlach Reported-by: Niklas Cassel Tested-by: Niklas Cassel Signed-off-by: Dave Gerlach Signed-off-by: Viresh Kumar --- V2: - Dave already sent V1 for this sometime back and I am sending the updated patch now as he isn't around and other folks are facing these issues as well. - Update _opp_add_static_v2() to return the OPP pointer which can now be used to distinguish all the cases properly. drivers/opp/of.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) -- 2.18.0.rc1.242.g61856ae69a2c diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 67a384c8ead2..5a4b47958073 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -297,15 +297,21 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_of_remove_table); * removed by dev_pm_opp_remove. * * Return: - * 0 On success OR + * Valid OPP pointer: + * On success + * NULL: * Duplicate OPPs (both freq and volt are same) and opp->available - * -EEXIST Freq are same and volt are different OR + * OR if the OPP is not supported by hardware. + * ERR_PTR(-EEXIST): + * Freq are same and volt are different OR * Duplicate OPPs (both freq and volt are same) and !opp->available - * -ENOMEM Memory allocation failure - * -EINVAL Failed parsing the OPP node + * ERR_PTR(-ENOMEM): + * Memory allocation failure + * ERR_PTR(-EINVAL): + * Failed parsing the OPP node */ -static int _opp_add_static_v2(struct opp_table *opp_table, struct device *dev, - struct device_node *np) +static struct dev_pm_opp *_opp_add_static_v2(struct opp_table *opp_table, + struct device *dev, struct device_node *np) { struct dev_pm_opp *new_opp; u64 rate = 0; @@ -315,7 +321,7 @@ static int _opp_add_static_v2(struct opp_table *opp_table, struct device *dev, new_opp = _opp_allocate(opp_table); if (!new_opp) - return -ENOMEM; + return ERR_PTR(-ENOMEM); ret = of_property_read_u64(np, "opp-hz", &rate); if (ret < 0) { @@ -390,12 +396,12 @@ static int _opp_add_static_v2(struct opp_table *opp_table, struct device *dev, * frequency/voltage list. */ blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ADD, new_opp); - return 0; + return new_opp; free_opp: _opp_free(new_opp); - return ret; + return ERR_PTR(ret); } /* Initializes OPP tables based on new bindings */ @@ -415,14 +421,15 @@ static int _of_add_opp_table_v2(struct device *dev, struct opp_table *opp_table) /* We have opp-table node now, iterate over it and add OPPs */ for_each_available_child_of_node(opp_table->np, np) { - count++; - - ret = _opp_add_static_v2(opp_table, dev, np); - if (ret) { + opp = _opp_add_static_v2(opp_table, dev, np); + if (IS_ERR(opp)) { + ret = PTR_ERR(opp); dev_err(dev, "%s: Failed to add OPP, %d\n", __func__, ret); of_node_put(np); goto put_list_kref; + } else if (opp) { + count++; } }