Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp29124imm; Fri, 25 May 2018 13:34:22 -0700 (PDT) X-Google-Smtp-Source: AB8JxZplZtrzGO/EIFEEzvR88zG947pK3f7KrdGEGFtPZ66xl92oeZBNzAa8VdGg3J9BZwVF+b30 X-Received: by 2002:a17:902:7009:: with SMTP id y9-v6mr2892505plk.217.1527280462742; Fri, 25 May 2018 13:34:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527280462; cv=none; d=google.com; s=arc-20160816; b=PLAJpr0KhmUGbiCpc2deg36RPbMR8XkHAPeNC4C/cynLlxj/EIVXJL/0Iza56hJcUZ 37RLLvtWTpJQH2vTTIJLYoc/3N8pnA6wfO2qVspUk7W86gJeE491aXtDMEYpaImJBm3s eNa+/b1qbqcSn4JTlhnvQAo7hAe6o/YpwwaP9OZFlRoNHbyOXt1cDW90DcMbRFen/8+g wZD5FSIyKS2BFvRZRhMPtBDG5iRJtkGvNsTwUlvtamxqX3UMU6V5aJjht89fhsl/1EYK /x++CohBLCPfXi4bUlIOz1CDdzeJw2Iwmlq2TKjKtvJZWjJrvLJFE9whnQ3PXf0GeeXa O8Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=CBLUx4zB7Qk2Os7QIRsa8SH9Cj8caLMadpJQD+fO+lw=; b=zVTt1+8PNGj1qMK617l04AOtCdOAeSO0GHTVCtuyyO6lQ6KcKhlKmGU/VseGSDqzxi Ktpuh3DA1YlGYeeoNzMmEBV1teN22uoYL3V2oyB/fGMQtuuOPXzwc629v/+0zsx9hd3P /9ved/vgEhDrI+iXXe0TDvU47GrqMjzKHo9DfI+iSPymnGcw5StdJiNF9r+4k7VDcaK9 7ZcSbCDeK7tUgnk+HXJAL0FPX+Lc7bo7w5YksjpEAodHD/sMHuBH6bZ07wK28Xmjy9Xm 2vJfFLOZZsPR4oSplbtfffduAy/5EOCTFOYyqbO+FE+F8AAUTPMyQ7RhkT4Ul0DTRRjS kUmA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o3-v6si23445311pls.64.2018.05.25.13.34.08; Fri, 25 May 2018 13:34:22 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030225AbeEYUbV (ORCPT + 99 others); Fri, 25 May 2018 16:31:21 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:44196 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S968391AbeEYUbS (ORCPT ); Fri, 25 May 2018 16:31:18 -0400 Received: by mail-pl0-f65.google.com with SMTP id z9-v6so410558plk.11 for ; Fri, 25 May 2018 13:31:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CBLUx4zB7Qk2Os7QIRsa8SH9Cj8caLMadpJQD+fO+lw=; b=h6U1jb7FS3RAYhJHufp5y/TA1b62+PJpVEX3YFXVAs9fOp7iPA8aPoQbC5awuDdLad eJfqfBWgUh2XX0JaSjSh3g2PDG4r+ULnyzWnG563NfApS2/ZfMQ2eaWY52T0rnZj2rP9 7rdfxKHrRJnyHLvCGZ1QbYpb+hH75iIqCxdBcrXB54BMi1SA9MiNFoe+nGfHXCZQ6kjH OcG4Fw8B/e37lQqzULotCxwtuG2DvsMuSfbx/9hFHGu6BkU+HQA3s6zqZZG/jf2pPGv3 ueLAVljJIUk4grrJuwpu2HMaq61IPyqoPF2X5bY3dnVJD4w5diRL0sGvm7iaaJ4UinXV ODeQ== X-Gm-Message-State: ALKqPwd6hCE6ROan2EnEMEw9IthlqL8oomoSFbkDhwfNaxsZIDbe8wua aW2xrPigVYZomIIvYW88ZtX5NQ== X-Received: by 2002:a17:902:b589:: with SMTP id a9-v6mr3928758pls.161.1527280277627; Fri, 25 May 2018 13:31:17 -0700 (PDT) Received: from mka.mtv.corp.google.com ([2620:0:1000:1501:8e2d:4727:1211:622]) by smtp.gmail.com with ESMTPSA id p1-v6sm42912360pfp.137.2018.05.25.13.31.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 May 2018 13:31:16 -0700 (PDT) From: Matthias Kaehlcke To: MyungJoo Ham Cc: Kyungmin Park , Chanwoo Choi , 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 , Matthias Kaehlcke Subject: [PATCH 02/11] PM / devfreq: Fix handling of min/max_freq == 0 Date: Fri, 25 May 2018 13:30:34 -0700 Message-Id: <20180525203043.249193-3-mka@chromium.org> X-Mailer: git-send-email 2.17.0.921.gf22659ad46-goog In-Reply-To: <20180525203043.249193-1-mka@chromium.org> References: <20180525203043.249193-1-mka@chromium.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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]; } 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]; + } else { + if (value < df->min_freq) { + ret = -EINVAL; + goto unlock; + } } df->max_freq = value; -- 2.17.0.921.gf22659ad46-goog