From patchwork Thu Aug 24 01:42:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chanwoo Choi X-Patchwork-Id: 9918847 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 71AE6608A6 for ; Thu, 24 Aug 2017 01:43:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 647F428ADA for ; Thu, 24 Aug 2017 01:43:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51C0028ADB; Thu, 24 Aug 2017 01:43:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D96528ADC for ; Thu, 24 Aug 2017 01:43:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751243AbdHXBnI (ORCPT ); Wed, 23 Aug 2017 21:43:08 -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 Received: from epcas1p2.samsung.com (unknown [182.195.41.46]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20170824014300epoutp042ee96c8a59aec659c4eab9ca0f6c3ed9~dpLyWtyry1376713767epoutp04y; Thu, 24 Aug 2017 01:43:00 +0000 (GMT) Received: from epsmges2p4.samsung.com (unknown [182.195.40.66]) by epcas1p3.samsung.com (KnoxPortal) with ESMTP id 20170824014300epcas1p307390496726825dd7fab6a3ee434de07~dpLyGqgny2884928849epcas1p3g; Thu, 24 Aug 2017 01:43:00 +0000 (GMT) Received: from epcas2p4.samsung.com ( [182.195.41.56]) by epsmges2p4.samsung.com (Symantec Messaging Gateway) with SMTP id 3A.1F.13866.42F2E995; Thu, 24 Aug 2017 10:43:00 +0900 (KST) Received: from epsmgms2p2new.samsung.com (unknown [182.195.42.143]) by epcas2p1.samsung.com (KnoxPortal) with ESMTP id 20170824014259epcas2p1c8618349053a9aab5d8774234e322848~dpLxvw3pI2857528575epcas2p1N; Thu, 24 Aug 2017 01:42:59 +0000 (GMT) X-AuditID: b6c32a48-f79a16d00000362a-3a-599e2f24b45f Received: from epmmp2 ( [203.254.227.17]) by epsmgms2p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 3D.38.10338.32F2E995; Thu, 24 Aug 2017 10:42:59 +0900 (KST) Received: from localhost.localdomain ([10.113.62.212]) by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OV600BON23MQ710@mmp2.samsung.com>; Thu, 24 Aug 2017 10:42:59 +0900 (KST) 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 xaT7E1gszja9Ybe4vGsOm8Xn3iOMFrcbV7BZPF7xlt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c AEsUl01Kak5mWWqRvl0CV8bH8/+ZCtaLVXT+vsPUwPhbsIuRk0NCwETi5/+7TF2MXBxCAusY Ja73t7FBOD8YJXYcX8cOUsUmoCWx/8UNNhBbRMBPYvv89YwgRcwCTYwSy/tvgSWEBSIlHszb AWazCKhKNFxsYQaxeQVcJfrX7WeGWCcn8WHPI7ChnAJuEi1Pu1hAbCGgmj19RxknMPIsYGRY xSiZWlCcm55bbFRglJdarlecmFtcmpeul5yfu4kRGEjbDmv172B8vCT+EKMAB6MSD++FhXMj hVgTy4orcw8xSnAwK4nw7lWfFynEm5JYWZValB9fVJqTWnyIUZqDRUmcN7NvRqSQQHpiSWp2 ampBahFMlomDU6qBkfPynOdzS/dubppnULVq6uzV7y4fdNG5/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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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;