From patchwork Wed May 30 07:56:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tao Wang X-Patchwork-Id: 10437847 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 87090601E9 for ; Wed, 30 May 2018 08:11:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7AA8428769 for ; Wed, 30 May 2018 08:11:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6EE06288A0; Wed, 30 May 2018 08:11:26 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, 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 A637F28769 for ; Wed, 30 May 2018 08:11:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935863AbeE3ILY (ORCPT ); Wed, 30 May 2018 04:11:24 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:8164 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S935832AbeE3ILV (ORCPT ); Wed, 30 May 2018 04:11:21 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 205BB767EB2C7; Wed, 30 May 2018 16:11:08 +0800 (CST) Received: from HSH1000038028.huawei.com (10.177.161.152) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.382.0; Wed, 30 May 2018 16:10:59 +0800 From: Kevin Wangtao To: , CC: , , , , Kevin Wangtao Subject: [PATCH V3] cpufreq: reinitialize new policy min/max when writing scaling_(max|min)_freq Date: Wed, 30 May 2018 15:56:47 +0800 Message-ID: <1527667007-48226-1-git-send-email-kevin.wangtao@hisilicon.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1527319008-66663-1-git-send-email-kevin.wangtao@hisilicon.com> References: <1527319008-66663-1-git-send-email-kevin.wangtao@hisilicon.com> MIME-Version: 1.0 X-Originating-IP: [10.177.161.152] X-CFilter-Loop: Reflected 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 consider such situation, current user_policy.min is 1000000, current user_policy.max is 1200000, in cpufreq_set_policy, other driver may update policy.min to 1200000, policy.max to 1300000. After that, If we input "echo 1300000 > scaling_min_freq", then user_policy.min will be 1300000, and user_policy.max is still 1200000, because the input value is checked with policy.max not user_policy.max. if we get all related cpus offline and online again, it will cause cpufreq_init_policy fail because user_policy.min is higher than user_policy.max. The solution is when user space tries to write scaling_(max|min)_freq, the min/max of new_policy should be reinitialized with min/max of user_policy, like what cpufreq_update_policy does. Signed-off-by: Kevin Wangtao --- drivers/cpufreq/cpufreq.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index b79c532..a970113 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -697,6 +697,9 @@ static ssize_t store_##file_name \ struct cpufreq_policy new_policy; \ \ memcpy(&new_policy, policy, sizeof(*policy)); \ + /* Initialized with user_policy to keep consistency */ \ + new_policy.min = policy->user_policy.min; \ + new_policy.max = policy->user_policy.max; \ \ ret = sscanf(buf, "%u", &new_policy.object); \ if (ret != 1) \