From patchwork Mon Dec 5 03:23:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 86491 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp1288509qgi; Sun, 4 Dec 2016 19:24:03 -0800 (PST) X-Received: by 10.99.4.213 with SMTP id 204mr98938876pge.77.1480908243040; Sun, 04 Dec 2016 19:24:03 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i6si13010770pgp.114.2016.12.04.19.24.02; Sun, 04 Dec 2016 19:24:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751176AbcLEDYB (ORCPT + 13 others); Sun, 4 Dec 2016 22:24:01 -0500 Received: from mail-pg0-f45.google.com ([74.125.83.45]:33335 "EHLO mail-pg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751120AbcLEDYB (ORCPT ); Sun, 4 Dec 2016 22:24:01 -0500 Received: by mail-pg0-f45.google.com with SMTP id 3so131430843pgd.0 for ; Sun, 04 Dec 2016 19:24:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=pLXaXipsOcVzDOhCQHvcQ3TAjiCUrxvy7rCijy6Z5JI=; b=SdZUcd2YwhranZD8PRNDSkTlhXlcFuDcp1KsBF+24wK39TYaa6SFUCaSJvl1enntNR B+Q6GOTLvVxaEOVJDoFEXEyRHfBN48cpKiejL/Ffc9hs/1YXz0lkT8+YE4DNQUUg7Kn2 8GBAVWCp1UwOUzdwDXaPWLIl3Tkz02Zli6U2E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=pLXaXipsOcVzDOhCQHvcQ3TAjiCUrxvy7rCijy6Z5JI=; b=AeR+HJvvcb3GvmUbew2Aml/GYKd997UfVSRpsFSeLvTDo0YChw6wmBvb6Z9M7V8P/n MB4tmoHGDcTKsgsIj0VxFwMhZ5jevyhffYdFaEyJLveRK8uzE8NNo8KiaD5ouSSPsMxz v0tbjk16g6Ng/trD0xgx28a5RZ1tfkavFp4DpRAkM1N1FsVkzPn3BpmA1yUeKn5y9+qz jDHaHhBpoTtQJwPqtoLuMCJob++rzvMxoyHQZ9ZVXuRy26nq/V19BngtLMxMWPJjpzWw wPReBEl1QN/seUk5VdSr1FyBQ6tzA+SCL4OSDTDWpgGJwSPNqQXwiBiE3+geP+ZaWzBt x/Tw== X-Gm-Message-State: AKaTC00fshFkAiDjuJx1LSqMH9yi5pcqVGEKCSZg+bdg67RFD0miu8juISEiRWL8ZCmAUKUZ X-Received: by 10.98.0.143 with SMTP id 137mr56215620pfa.183.1480908240766; Sun, 04 Dec 2016 19:24:00 -0800 (PST) Received: from localhost ([122.172.43.83]) by smtp.gmail.com with ESMTPSA id o126sm22944861pga.34.2016.12.04.19.23.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Dec 2016 19:24:00 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki , MyungJoo Ham , Kyungmin Park Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, Stephen Boyd , nm@ti.com, Vincent Guittot , Viresh Kumar Subject: [PATCH V2] devfreq: rk3399_dmc: Don't use OPP structures outside of RCU locks Date: Mon, 5 Dec 2016 08:53:52 +0530 Message-Id: X-Mailer: git-send-email 2.7.1.410.g6faf27b Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The OPP structures are abused to the best here, without understanding how the OPP core and RCU locks work. In short, the OPP pointer saved in 'rk3399_dmcfreq' can become invalid under your nose, as the OPP core may free it. Fix various abuses around OPP structures and calls. Compile tested only. Reviewed-by: Chanwoo Choi Signed-off-by: Viresh Kumar --- V1->V2: - Added Reviewed-by from Chanwoo. - Fixed an issue reported by buildbot. drivers/devfreq/rk3399_dmc.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) -- 2.7.1.410.g6faf27b -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/devfreq/rk3399_dmc.c b/drivers/devfreq/rk3399_dmc.c index 5063ac1a5939..75333050cdea 100644 --- a/drivers/devfreq/rk3399_dmc.c +++ b/drivers/devfreq/rk3399_dmc.c @@ -80,7 +80,6 @@ struct rk3399_dmcfreq { struct regulator *vdd_center; unsigned long rate, target_rate; unsigned long volt, target_volt; - struct dev_pm_opp *curr_opp; }; static int rk3399_dmcfreq_target(struct device *dev, unsigned long *freq, @@ -102,9 +101,6 @@ static int rk3399_dmcfreq_target(struct device *dev, unsigned long *freq, target_rate = dev_pm_opp_get_freq(opp); target_volt = dev_pm_opp_get_voltage(opp); - dmcfreq->rate = dev_pm_opp_get_freq(dmcfreq->curr_opp); - dmcfreq->volt = dev_pm_opp_get_voltage(dmcfreq->curr_opp); - rcu_read_unlock(); if (dmcfreq->rate == target_rate) @@ -165,7 +161,9 @@ static int rk3399_dmcfreq_target(struct device *dev, unsigned long *freq, if (err) dev_err(dev, "Cannot to set vol %lu uV\n", target_volt); - dmcfreq->curr_opp = opp; + dmcfreq->rate = target_rate; + dmcfreq->volt = target_volt; + out: mutex_unlock(&dmcfreq->lock); return err; @@ -431,8 +429,9 @@ static int rk3399_dmcfreq_probe(struct platform_device *pdev) rcu_read_unlock(); return PTR_ERR(opp); } + data->rate = dev_pm_opp_get_freq(opp); + data->volt = dev_pm_opp_get_voltage(opp); rcu_read_unlock(); - data->curr_opp = opp; rk3399_devfreq_dmc_profile.initial_freq = data->rate;