Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3489309imu; Sun, 11 Nov 2018 16:15:23 -0800 (PST) X-Google-Smtp-Source: AJdET5fcbnp5bs5XVhd17qk93AMagwkiNMdVjke1pwtB90M0PeI9gKNQBC8+dOBvmHA5SSpuqF3p X-Received: by 2002:a62:6383:: with SMTP id x125-v6mr17803057pfb.13.1541981723597; Sun, 11 Nov 2018 16:15:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541981723; cv=none; d=google.com; s=arc-20160816; b=ePcKj9rUo66R3FFHoTrxg9fp14P45TwFU30hMCwQdcQN60KXs9uC7T8vfRSlibFt8k F/K4DZWa7N7DMaOeoyqq3g/PWKBnZMFpsxEDmW9x5PG72zOmkXaurZwp8tP3IJ5PgkXp zw/VwTOWPpJScv6JTgQj2w2LtmV2tF8cP8u06T+aio5R8MStd/GI8a1SUz5jWRebzOZe YVrhmohuaefAG6XLr2UAgAHDdO4+oHTZQSbKa8yy8UrSCTNP0DQ0lSiIGBx9tgmg6IsK 9HmiqMFa4QHDLbaai+55PFzGnWnThGqzGC8PSJ0tSn912QyLHFpUuTPBURawYnbVcyrH w9+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=s5AUbyMdeGIH+re3reM29jcxFakxHCWMNv2BTaSgAfU=; b=UfQMNZugx4GyXa3/s07dqi9eiyZZV6TWJvgM94bmmWM2f9Hf/wkKX5HZIIVCO8aBsz 8h2xxBopFbVSOmx0IXUqNVCI+Gq7ivpb8IuZjTc2a+apaXqBeQJN7zx9Xsr5NUG7zCAd 3CvqTs8hlfM5qogexYB37V/tYZESecOr5ykUXJI3bkbt1eTuneFZHqT0BzkbOjKHDM4F SfG/UPgj/DbrQlCB0jE5EsAYe0fpF5VZ+yQuIhf6cLHkPjWzD/Fl8LKDigCKrb9nWo8x HBo9G/3c8i+q5oOzII+N3qbMrvggLIqbLwJmsoigmyLSJajMPineW7cSVvK76YPnGP9W vg2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BJHirIh4; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w13-v6si13527752pgj.229.2018.11.11.16.15.08; Sun, 11 Nov 2018 16:15:23 -0800 (PST) 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=BJHirIh4; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730876AbeKLKEB (ORCPT + 99 others); Mon, 12 Nov 2018 05:04:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:59922 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730472AbeKLIRP (ORCPT ); Mon, 12 Nov 2018 03:17:15 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EB61A22360; Sun, 11 Nov 2018 22:27:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975240; bh=ToYSEaNLrF1nh8CdqspjWx57CRwfv+aShSVOd66QUkQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BJHirIh4AKeTXCgYVa6yGbS7rX3VBHCS3Y2ZvHtuZ80UZukiuFu7p3CYUyhFM65xe 5nw4LkqNS51ospxO5SJntpKe/YVE5gJPRgtsJtJ+3CFPhINebj4INpOknbvj0oKX67 noB1mCf4yVEwD/lLcEbNRnFNaebiMrKD0xB3pF7Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Niklas Cassel , Viresh Kumar , Sasha Levin Subject: [PATCH 4.19 082/361] cpufreq: dt: Try freeing static OPPs only if we have added them Date: Sun, 11 Nov 2018 14:17:09 -0800 Message-Id: <20181111221631.455138403@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Greg Kroah-Hartman --- drivers/cpufreq/cpufreq-dt.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) --- 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_p } } + 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_p * * 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_p __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_p 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_p 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);