Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3072533imm; Sun, 1 Jul 2018 11:36:21 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ1y6vp2jfwVoM41RWenBzvJFzLAzafxTrBWmgADHtb97I3lETfabXc7Sy7BGXR7A3NQ3li X-Received: by 2002:a17:902:6f02:: with SMTP id w2-v6mr22514408plk.216.1530470181704; Sun, 01 Jul 2018 11:36:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530470181; cv=none; d=google.com; s=arc-20160816; b=wSvgMLlhXNxRrOTwFRM34dPr8OQq93NuVrEbO720K37hSeORBbRHc+59ZWoQj8yjkE uUzxmKqD57fN9Ii3imB+bTYTm0e7T/BiU/ajOvITmfWvl8awo4ofz3p20WRLxwcAM2MT 4fd3uf3KtjBgouBDcD/ouOuX+Ntv/lHl5xBtzlFwEuIb5AvCcXMyo4Fwja5Kkx8/zhia ywG+r6c4a5oI584gJ7edfHRadQ1qocz1mLMzK0bGQJM68hLQOYfAY3fSYYSgWjpzFbtV SP4669Sw/N72+5px91OTrqVhH4e0l7O3D96qflu8mxNzCPBQzLnZgtiQe2l4XxgTJZwI 95sA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=jd4sbvLUHVlqXiLp+uZwtHvs49sQ2b5LiI/rNNL8ips=; b=saP4Kh8Vqu+IM3+hWT8wKDTuduP1qN/mk92dUeLIVJeSwCHrWKeAelKrixpG6RGEzA rOkNaAJnFH9Q/lzzWjdqjmRFNcDYxf12riCt6HuHjyIGfaLy1Z/+R0jU3jLRWY5CDBnT aP1DuohOGwm6JTlTG8x5jPLRsnjhH1DNsOehtS82/w/2Z6CRkWV5wh+1p0atWm25V3cY ZhNPaySazAWZKJYomOXUZIRPw+llXH+rlSwN+XeGtKztAHxQ4tutYyKaCj3fTH49DtOZ zsljAK4lajZtctHN/Qw2oEjnexqB1Klbfw2onuxElsSqM9+iVmRufKfYuupwWsMKDVWs HyOg== ARC-Authentication-Results: i=1; mx.google.com; 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 u10-v6si12186241pgc.261.2018.07.01.11.36.07; Sun, 01 Jul 2018 11:36:21 -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; 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 S933358AbeGASfb (ORCPT + 99 others); Sun, 1 Jul 2018 14:35:31 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:60626 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933120AbeGAQPo (ORCPT ); Sun, 1 Jul 2018 12:15:44 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id CE91986D; Sun, 1 Jul 2018 16:15:43 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kevin Wangtao , Viresh Kumar , "Rafael J. Wysocki" Subject: [PATCH 4.4 020/105] cpufreq: Fix new policy initialization during limits updates via sysfs Date: Sun, 1 Jul 2018 18:01:30 +0200 Message-Id: <20180701153150.870493235@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701153149.382300170@linuxfoundation.org> References: <20180701153149.382300170@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tao Wang commit c7d1f119c48f64bebf0fa1e326af577c6152fe30 upstream. If the policy limits are updated via cpufreq_update_policy() and subsequently via sysfs, the limits stored in user_policy may be set incorrectly. For example, if both min and max are set via sysfs to the maximum available frequency, user_policy.min and user_policy.max will also be the maximum. If a policy notifier triggered by cpufreq_update_policy() lowers both the min and the max at this point, that change is not reflected by the user_policy limits, so if the max is updated again via sysfs to the same lower value, then user_policy.max will be lower than user_policy.min which shouldn't happen. In particular, if one of the policy CPUs is then taken offline and back online, cpufreq_set_policy() will fail for it due to a failing limits check. To prevent that from happening, initialize the min and max fields of the new_policy object to the ones stored in user_policy that were previously set via sysfs. Signed-off-by: Kevin Wangtao Acked-by: Viresh Kumar [ rjw: Subject & changelog ] Cc: All applicable Signed-off-by: Rafael J. Wysocki Signed-off-by: Greg Kroah-Hartman --- drivers/cpufreq/cpufreq.c | 2 ++ 1 file changed, 2 insertions(+) --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -603,6 +603,8 @@ static ssize_t store_##file_name \ struct cpufreq_policy new_policy; \ \ memcpy(&new_policy, policy, sizeof(*policy)); \ + new_policy.min = policy->user_policy.min; \ + new_policy.max = policy->user_policy.max; \ \ ret = sscanf(buf, "%u", &new_policy.object); \ if (ret != 1) \