From patchwork Wed Oct 31 23:03:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 149887 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp97171ljp; Wed, 31 Oct 2018 16:06:19 -0700 (PDT) X-Google-Smtp-Source: AJdET5dPDez5nAHZRQ6h05R6Rwe+rISXIhkiEz0zEd4JcQuPZ3SdhSYM+unaNvJ3UZPnQzwrgqbY X-Received: by 2002:a17:902:64:: with SMTP id 91-v6mr5258488pla.161.1541027178981; Wed, 31 Oct 2018 16:06:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541027178; cv=none; d=google.com; s=arc-20160816; b=m4C115WFMuI412+Mvmmo7y7OZPKYmdZ2iAdFbMPXUG+z3tiI6fpKrJsF6FTmAJRkIF DaMaCI4HPeYATG64ynQXRDCTUpqXaStRnr4nmub9CAkvznwACyzqlq84VG35YbJRLcV6 tlnUrZ7ENkKibkmv7k4Kp8f9lNDY9Iu74RiRLnVzdG7e9QmM7Zij31XmzjNIYhS+o/9r nzTujGx+roA123EN2PdX+9uB0Xy/MKL1K7vShW2M/Ns/OZd45BY+BK2cWo+Wa65F7mY8 D8VsddF0Sr1eILeM5bQpMlbtWtjDzLFX+CrCNbaof9WJpoNwGHahdyUNeurIsFlRf6a8 CeZg== 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=I6I/+c4SD5rsUDUlMREsnggf5fF5Gg9VBpT0/rp9Ppk=; b=A0YrZ5zouHE5nAxg09tX5tq5bN0Kxt5KZaCpAo2NNJrdppUxs8INOxfZJEq7PoY7o/ zuT9DYXkHP+Xt5lR+UuolYjiKXt1/CLOovmnTbQr3dK5aX3+MImKL92r2wksJsmfRVOj ixeum0hUSd66qYXQZFkfN3zignRlMeXlNReykXGVL46QRu+3Dd+yUixqQ+zHBr8UIzrv T8I8RJcdKBndyWaImp6N+acbIrEbSvRRp7uxjC7Y/N/NWEyU91UNfB//2tCSxNZa9Ght pnT4MKjGq8c/nzDtaeuVZm6tPE6Ea6iE2Zt7ih+9A+EZuNHFSB9Gzn+HdiL2uaExmkx0 YD2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zIuYon3z; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n67-v6si28439631pga.290.2018.10.31.16.06.18; Wed, 31 Oct 2018 16:06:18 -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=@kernel.org header.s=default header.b=zIuYon3z; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728003AbeKAIG0 (ORCPT + 32 others); Thu, 1 Nov 2018 04:06:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:53318 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727945AbeKAIGZ (ORCPT ); Thu, 1 Nov 2018 04:06:25 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7466120838; Wed, 31 Oct 2018 23:06:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027174; bh=VBXsMqhmxXoiCeVeo9pOALxeXQzW0h+eRtgfqb5gFCs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zIuYon3zBfU3Zb2lNPOZsgia5ZVPO26/tVVOBa2YUWrXF0v25WZ5MlO62bQsRRSlY pA9J8rKQcr+23V8twL9pS4c5+cqpeWigiP1oywuXBWMGse+c5Zc5EORcZ7ZcdvIdvM fseenFEXfKJiHQS2cr7lGUegvLPpUDQjyiQ/K/1A= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Viresh Kumar , Sasha Levin Subject: [PATCH AUTOSEL 4.19 036/146] cpufreq: dt: Try freeing static OPPs only if we have added them Date: Wed, 31 Oct 2018 19:03:51 -0400 Message-Id: <20181031230541.28822-36-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Viresh Kumar [ Upstream commit 51c99dd2c06b234575661fa1e0a1dea6c3ef566f ] 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 Signed-off-by: Sasha Levin --- drivers/cpufreq/cpufreq-dt.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) -- 2.17.1 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);