Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751310AbdHXBnM (ORCPT ); Wed, 23 Aug 2017 21:43:12 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:45174 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751101AbdHXBnB (ORCPT ); Wed, 23 Aug 2017 21:43:01 -0400 X-AuditID: b6c32a48-f79a16d00000362a-3a-599e2f24b45f From: Chanwoo Choi To: myungjoo.ham@samsung.com, kyungmin.park@samsung.com, cw00.choi@samsung.com Cc: rafael.j.wysocki@intel.com, chanwoo@kernel.org, inki.dae@samsung.com, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH 06/12] PM / devfreq: Check the entered min/max_freq is supported or not Date: Thu, 24 Aug 2017 10:42:53 +0900 Message-id: <1503538979-22693-7-git-send-email-cw00.choi@samsung.com> X-Mailer: git-send-email 1.8.0 In-reply-to: <1503538979-22693-1-git-send-email-cw00.choi@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrBKsWRmVeSWpSXmKPExsWy7bCmha6K/rxIg4YVPBYTb1xhsbj+5Tmr xaT7E1gszja9Ybe4vGsOm8Xn3iOMFrcbV7BZPF7xlt2Bw2PxnpdMHptWdbJ59G1ZxejxeZNc AEtUqk1GamJKapFCal5yfkpmXrqtkndwvHO8qZmBoa6hpYW5kkJeYm6qrZKLT4CuW2YO0BlK CmWJOaVAoYDE4mIlfTubovzSklSFjPziElulaENDIz1DA3M9IyMjPRPjWCsjU6CShNSMj+f/ MxWsF6vo/H2HqYHxt2AXIyeHhICJRO+ctYwQtpjEhXvr2boYuTiEBHYwSjx5/BfK+c4oce76 SWaYjp//7zJBJDYwShw79BfK+cEocWLCJrBZbAJaEvtf3GADsUUEAiQ6164CK2IWaGKU2H/v BjtIQlggUuLBvB1gRSwCqhINF1vAVvAKuEr0r9sPtU5O4sOeR2D1nAJuEi1Pu1hABkkITGCT eDT9CD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6uzV7y4fdNG5/Jc1ulA/edr0uUWbU9NTzIMW +p+QmDrX0DjiwUHJp0/v7xdU2Nh/uMU578DnLZuef7YyPJYpXXxyxse1WVW1mbNeVL/sVJe7 EXtPMb9VzFM4iCM0aLb4/mcPZmuXfEv1XbNhe2qcpfLs7TtNeE7YdiuxFGckGmoxFxUnAgCL opw5IAIAAA== X-CMS-MailID: 20170824014259epcas2p1c8618349053a9aab5d8774234e322848 X-Msg-Generator: CA X-Sender-IP: 182.195.42.143 X-Local-Sender: =?UTF-8?B?7LWc7LCs7JqwG1RpemVuIFBsYXRmb3JtIExhYihTL1fshLw=?= =?UTF-8?B?7YSwKRvsgrzshLHsoITsnpAbU2VuaW9yIEVuZ2luZWVy?= X-Global-Sender: =?UTF-8?B?Q2hhbndvbyBDaG9pG1RpemVuIFBsYXRmb3JtIExhYi4bU2Ft?= =?UTF-8?B?c3VuZyBFbGVjdHJvbmljcxtTZW5pb3IgRW5naW5lZXI=?= X-Sender-Code: =?UTF-8?B?QzEwG1RFTEUbQzEwVjgxMTE=?= CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20170824014259epcas2p1c8618349053a9aab5d8774234e322848 X-RootMTR: 20170824014259epcas2p1c8618349053a9aab5d8774234e322848 References: <1503538979-22693-1-git-send-email-cw00.choi@samsung.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2768 Lines: 93 The existing {min|max}_freq_store() only check the range of entered frequency. If the unsupported frequency is entered and the entered frequency is within the ranges, {min|max}_freq_store() will store it to devfreq->{min|max}_freq. And then when some user try to read the {min|max}_freq, the devfreq show the unsupported frequency value. In order to fix this issue, this patch checks whether the entered frequency is supported or not by OPP interface. Signed-off-by: Chanwoo Choi --- drivers/devfreq/devfreq.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 56f8a0473834..f10017fe400f 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -97,6 +97,25 @@ static unsigned long find_available_max_freq(struct devfreq *devfreq) return max_freq; } +static int is_supported_freq(struct devfreq *devfreq, unsigned long freq) +{ + struct device *dev = devfreq->dev.parent; + struct dev_pm_opp *opp; + int ret = 0; + + /* Check whether entered frequency is supported or not */ + opp = dev_pm_opp_find_freq_exact(dev, freq, true); + if (PTR_ERR(opp) == -ERANGE) + opp = dev_pm_opp_find_freq_exact(dev, freq, false); + + if (IS_ERR(opp)) + ret = PTR_ERR(opp); + + dev_pm_opp_put(opp); + + return ret; +} + /** * devfreq_get_freq_level() - Lookup freq_table for the frequency * @devfreq: the devfreq instance @@ -1099,9 +1118,8 @@ static ssize_t min_freq_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct devfreq *df = to_devfreq(dev); - unsigned long value; + unsigned long value, max; int ret; - unsigned long max; ret = sscanf(buf, "%lu", &value); if (ret != 1) @@ -1114,6 +1132,11 @@ static ssize_t min_freq_store(struct device *dev, struct device_attribute *attr, goto unlock; } + /* Check whether entered frequency is supported or not */ + ret = is_supported_freq(df, value); + if (ret < 0) + goto unlock; + df->min_freq = value; update_devfreq(df); ret = count; @@ -1126,9 +1149,8 @@ static ssize_t max_freq_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct devfreq *df = to_devfreq(dev); - unsigned long value; + unsigned long value, min; int ret; - unsigned long min; ret = sscanf(buf, "%lu", &value); if (ret != 1) @@ -1141,6 +1163,11 @@ static ssize_t max_freq_store(struct device *dev, struct device_attribute *attr, goto unlock; } + /* Check whether entered frequency is supported or not */ + ret = is_supported_freq(df, value); + if (ret < 0) + goto unlock; + df->max_freq = value; update_devfreq(df); ret = count; -- 1.9.1