Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2028919imm; Sun, 27 May 2018 23:38:24 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpwRwhsw/1NVo1dkOuexf9ZxbkHwARpjHF0wTQOj6BujdMxqYyiEVXq7tYMpCds3dSHjwDk X-Received: by 2002:a65:6285:: with SMTP id f5-v6mr9781539pgv.252.1527489504766; Sun, 27 May 2018 23:38:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527489504; cv=none; d=google.com; s=arc-20160816; b=mPy8KF/UwZd0TWyIZCdZDxIfI2gXAnsd2MajvGHCqLxyqBn5z02WzbgGdhR42waabN 7Y8cPCNK8EuCFV7pYQytPTw9iCUmAj0+p3EnP5XmfHr14dHdVDyjHFZ2513nRPjn7LQX Ox0klHATT2OeLUYQzcoq4IV6w+juTuOF3GKDYjnlPnS0RVxdJFQKvcVR6czxHjssYxj8 7+q4PYMrMGcjqNyZeCh3Ai7z+Ylk8q82duVfgtF4oWrFWMzvnKJ/bhu/KEbFKsfEXrg0 516ORXorq14/3BMl+feD5sfsSm0fC3Zv/CzBfHwBoNvpuWFiMAXuwPLOK1iXQfTJt8Mj tC9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:dlp-filter:cms-type :in-reply-to:subject:cc:to:user-agent:organization:from:date :message-id:content-transfer-encoding:mime-version:dkim-signature :dkim-filter:arc-authentication-results; bh=KnLDaEwX2FSxZZAAuD0nTFvhtDjBfIY2HrVugGE1ATQ=; b=TKLA/uiEc2FcWqmaK3ZBqJt8XzMY8ybxl86woMdPMmC+044LjILKR3DrCE/muPzDvD Bt8BtejgeoGrxwIdhfYiXn8VtmV8B5ZcjemHkjptfIfxcizNXn+zHB8n+dZ4oy8YI+0B smQTt/0H1+oRZ1hLySlQCzbq5jH9SyKZz1hq9RUVThnS4JO7kNhZOwOaz7SyZu6kAFbL idj9HFbEYBKTzBhNtufQbKnkNhKdNR8TpS2b8P2OnUYrSgSf7fTtkSSAO/uiGOXL+XmM K4ee5ltsVZCfp+LpnaR+oqfQrTxJgJ9yVVL9hPSNHsfX61G0NM1fVH3hTHyJAW0S7fV5 h/0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=oQYQf/vb; 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=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bj1-v6si28758592plb.395.2018.05.27.23.38.09; Sun, 27 May 2018 23:38:24 -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=@samsung.com header.s=mail20170921 header.b=oQYQf/vb; 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=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753418AbeE1Gh5 (ORCPT + 99 others); Mon, 28 May 2018 02:37:57 -0400 Received: from mailout2.samsung.com ([203.254.224.25]:29737 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751085AbeE1Ghx (ORCPT ); Mon, 28 May 2018 02:37:53 -0400 Received: from epcas1p3.samsung.com (unknown [182.195.41.47]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20180528063751epoutp02c66eef5c46589faa05271e5ace8792c1~yu5TmhaOJ1394513945epoutp02s; Mon, 28 May 2018 06:37:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20180528063751epoutp02c66eef5c46589faa05271e5ace8792c1~yu5TmhaOJ1394513945epoutp02s DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1527489471; bh=KnLDaEwX2FSxZZAAuD0nTFvhtDjBfIY2HrVugGE1ATQ=; h=Date:From:To:Cc:Subject:In-reply-to:References:From; b=oQYQf/vbq/rop9P3vX6cEx8cLXDAWK4L+VIfkl+RS3ZGqQlEVlAluaXn/O+/f8hBt o5b+97L1dvG0ECrGEpBVgwgxN9MrOuvqKKHzQGPppL+N0M7Ff1fJnDtbfI1Rm2ltoW F0mFfzPoq61Orj5TumFe/D0RU7tvZ1X08amN3JII= Received: from epsmges1p1.samsung.com (unknown [182.195.40.157]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20180528063747epcas1p4526bf400b07cef60a23d513b58fcbcef~yu5P62U6J1675816758epcas1p4N; Mon, 28 May 2018 06:37:47 +0000 (GMT) Received: from epcas1p2.samsung.com ( [182.195.41.46]) by epsmges1p1.samsung.com (Symantec Messaging Gateway) with SMTP id 10.2B.04066.BB3AB0B5; Mon, 28 May 2018 15:37:47 +0900 (KST) Received: from epsmgms2p1new.samsung.com (unknown [182.195.42.142]) by epcas1p2.samsung.com (KnoxPortal) with ESMTP id 20180528063747epcas1p28a9d477c132a23dc4cd0a5306e9a711e~yu5Pgr0AP2490224902epcas1p2f; Mon, 28 May 2018 06:37:47 +0000 (GMT) X-AuditID: b6c32a35-b89ff70000000fe2-d4-5b0ba3bb98b6 Received: from epmmp2 ( [203.254.227.17]) by epsmgms2p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 6E.9B.03915.BB3AB0B5; Mon, 28 May 2018 15:37:47 +0900 (KST) MIME-version: 1.0 Content-transfer-encoding: 8BIT Content-type: text/plain; charset="UTF-8" Received: from [10.113.63.77] by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0P9F007ZAEEZ2Z20@mmp2.samsung.com>; Mon, 28 May 2018 15:37:47 +0900 (KST) Message-id: <5B0BA3BB.8060505@samsung.com> Date: Mon, 28 May 2018 15:37:47 +0900 From: Chanwoo Choi Organization: Samsung Electronics User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 To: Matthias Kaehlcke , MyungJoo Ham Cc: Kyungmin Park , Arnd Bergmann , Greg Kroah-Hartman , Rob Herring , Mark Rutland , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Brian Norris , Douglas Anderson Subject: Re: [PATCH 02/11] PM / devfreq: Fix handling of min/max_freq == 0 In-reply-to: <20180525203043.249193-3-mka@chromium.org> X-Brightmail-Tracker: H4sIAAAAAAAAA02Sa0gUURTHuTu7M6O1dtteVyuzoSKX3JzdNifLiIoYtA+CFJHEOriDbu7D ZlbpQbGZr8xeFgRmrdqDEMPcXmaapGsPScOtSDT7EqWVqGUP016zO0Z+uv97+P0P5/w5JKYp wcNIi93JC3bOSuHBylstkbqouxemJEc3nIlkfpU8IBjPpyEV4/Z2qJj2y/dx5tCFGpxpzxkg mGf1ZTgzctQLmEsvOxXMyLU3gOk5eAVn8hq9xLqpbPX5asCOj5UA9qyrU8l6qg7jbNO5aoI9 dqMKsCOe8ERiO78mnefMvBDB21MdZos9LY5KSDJtMBlXRtNR9ComhoqwczY+jtq4OTFqk8Uq TUpFZHPWLKmUyIkitXztGsGR5eQj0h2iM45Kpmm9jo6O0en10mvYEas3SkgKn1589Lkis2Lh 7ovN54AL/A4tAkEkgitQd12esggEkxpYB1BH6w8gf74DVNNfqPpHXT/sVfi1Bl4DqLN3tV+r 4XQ0euq15CZJDC5AXl+Gv4zBSHTzbg0h470A5TSYZVyLcttOBdoo4WL06k+L0q9xqd7U34X7 9TS4EL0YfQP8ehbchu64vwX6zIRJqPzH08CgGPyqQPWD7gA0A8ajS13jAXMQjEF9Yy7MDyF4 hEC1n924vMBG9L796cQyM9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qDRUmc93besUghgfTEktTs1NSC1CKYLBMHp1QDo6v1Mv/t 4Z+X98nFsyTMSbm5/wK79bJVt1KiF7/Trdo/+/VjCSb1q78nhAQt6fnfLbTgwLb+lVc8b6pq tWz+emp9ZKPM+sas/ace3BLsOLzuw4bfDz5dKTm3zsfM7XC/k+TENjkOxVzddbtnqrBtdHl6 ZZXkMs9nB67/YPB8PCmFV+NT7E6+UiMlluKMREMt5qLiRABiJeeklAIAAA== X-CMS-MailID: 20180528063747epcas1p28a9d477c132a23dc4cd0a5306e9a711e X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20180525203323epcas4p45ba35c38413e227f76f68fe331011b19 References: <20180525203043.249193-1-mka@chromium.org> <20180525203043.249193-3-mka@chromium.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 2018년 05월 26일 05:30, Matthias Kaehlcke wrote: > Commit ab8f58ad72c4 ("PM / devfreq: Set min/max_freq when adding the > devfreq device") initializes df->min/max_freq with the min/max OPP when > the device is added. Later commit f1d981eaecf8 ("PM / devfreq: Use the > available min/max frequency") adds df->scaling_min/max_freq and the > following to the frequency adjustment code: > > max_freq = MIN(devfreq->scaling_max_freq, devfreq->max_freq); > > With the current handling of min/max_freq this is incorrect: > > Even though df->max_freq is now initialized to a value != 0 user space > can still set it to 0, in this case max_freq would be 0 instead of > df->scaling_max_freq as intended. In consequence the frequency adjustment > is not performed: > > if (max_freq && freq > max_freq) { > freq = max_freq; > > To fix this set df->min/max freq to the min/max OPP in max/max_freq_store, > when the user passes a value of 0. This also prevents df->max_freq from > being set below the min OPP when df->min_freq is 0, and similar for > min_freq. Since it is now guaranteed that df->min/max_freq can't be 0 the > checks for this case can be removed. > > Fixes: f1d981eaecf8 ("PM / devfreq: Use the available min/max frequency") > Signed-off-by: Matthias Kaehlcke > --- > drivers/devfreq/devfreq.c | 30 ++++++++++++++++++------------ > 1 file changed, 18 insertions(+), 12 deletions(-) > > diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c > index 0057ef5b0a98..67da4e7b486b 100644 > --- a/drivers/devfreq/devfreq.c > +++ b/drivers/devfreq/devfreq.c > @@ -283,11 +283,11 @@ int update_devfreq(struct devfreq *devfreq) > max_freq = MIN(devfreq->scaling_max_freq, devfreq->max_freq); > min_freq = MAX(devfreq->scaling_min_freq, devfreq->min_freq); > > - if (min_freq && freq < min_freq) { > + if (freq < min_freq) { > freq = min_freq; > flags &= ~DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use GLB */ > } > - if (max_freq && freq > max_freq) { > + if (freq > max_freq) { > freq = max_freq; > flags |= DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use LUB */ > } > @@ -1123,17 +1123,20 @@ static ssize_t min_freq_store(struct device *dev, struct device_attribute *attr, > struct devfreq *df = to_devfreq(dev); > unsigned long value; > int ret; > - unsigned long max; > > ret = sscanf(buf, "%lu", &value); > if (ret != 1) > return -EINVAL; > > mutex_lock(&df->lock); > - max = df->max_freq; > - if (value && max && value > max) { > - ret = -EINVAL; > - goto unlock; > + > + if (value) { > + if (value > df->max_freq) { > + ret = -EINVAL; > + goto unlock; > + } > + } else { > + value = df->profile->freq_table[df->profile->max_state - 1]; > } If you want to prevent that df->min_freq is zero, you should reinitialize 'value' as following. Because freq_table must be in ascending order. value = df->profile->freq_table[0]; > > df->min_freq = value; > @@ -1158,17 +1161,20 @@ static ssize_t max_freq_store(struct device *dev, struct device_attribute *attr, > struct devfreq *df = to_devfreq(dev); > unsigned long value; > int ret; > - unsigned long min; > > ret = sscanf(buf, "%lu", &value); > if (ret != 1) > return -EINVAL; > > mutex_lock(&df->lock); > - min = df->min_freq; > - if (value && min && value < min) { > - ret = -EINVAL; > - goto unlock; > + > + if (!value) { > + value = df->profile->freq_table[0]; ditto. value = df->profile->freq_table[df->profile->max_state - 1]; > + } else { > + if (value < df->min_freq) { > + ret = -EINVAL; > + goto unlock; > + } > } > > df->max_freq = value; > Actually, min_freq_store() and max_freq_store() are very similar. But, this patch changed the order of conditional statement as following: If there is no special reason, you better to keep the same format for the readability. min_freq_store() if (value) { ... } else { value = df->profile->freq_table[df->profile->max_state - 1]; } max_freq_store() if (!value) { value = df->profile->freq_table[0]; } else { ... -- Best Regards, Chanwoo Choi Samsung Electronics