From patchwork Thu Dec 1 10:38:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 86004 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp626928qgi; Thu, 1 Dec 2016 02:38:08 -0800 (PST) X-Received: by 10.84.178.7 with SMTP id y7mr83892480plb.147.1480588688387; Thu, 01 Dec 2016 02:38:08 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m127si64963476pfb.123.2016.12.01.02.38.08; Thu, 01 Dec 2016 02:38:08 -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 S1751601AbcLAKiH (ORCPT + 13 others); Thu, 1 Dec 2016 05:38:07 -0500 Received: from mail-pf0-f181.google.com ([209.85.192.181]:35503 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751503AbcLAKiG (ORCPT ); Thu, 1 Dec 2016 05:38:06 -0500 Received: by mail-pf0-f181.google.com with SMTP id i88so45562620pfk.2 for ; Thu, 01 Dec 2016 02:38:06 -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=s1iYof+h6FBKNZsN37XUPn75W5ENiHJcUGpJvchWZmg=; b=C6B5Dge2aKN7P4lWxIZVqXbM/TrxasmF6/BvM1TvftAiLKSUQWpwC1noqODjyWzYyy qwK+ecyvI/9l9cLPNvCVuE0Jt2GBFbxCGvM2tQ9Q+AKV1idhlembQQXJ7ymXOk5q50dp awifHIubaBVVblQQzKXyL3Zrrxf22TwMn6h30= 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=s1iYof+h6FBKNZsN37XUPn75W5ENiHJcUGpJvchWZmg=; b=hmwqqcqpfvEITxFh1Btn8jy7zGVeI37IiQeEc0FktfbNERog+1oTil855OAB53vZKd F8ih1gBeBOrU4ThoS/bd1akUHXiTYkkt72EVAKUgbCxYPnFAYrMjUMOWTf4bgP7KwyAD J0gnntleUKlDydh1muRLdAPQHrFHwbcB7kOhxciI8q+Fmwex8OBmYVpsSBRXIyXxu2oC vZiXApNqpqxVFnvTuKmLZnHidiLyE/u8+fDuqmEjA9xjayslfTbPWKMoVMaySD8jwsXa f3/hf0+1ollDcwoUysttqV06JKAd6UuzFI/B/OarMKz7eKuOIAZxJiozcBMvcS8w1KUR Hl8w== X-Gm-Message-State: AKaTC021Bq3nTK48e1V62NRn4btyZLGfRywxj6WKMWh8aHL0XSrLnbZ4wnT7VBsEDmFFU269 X-Received: by 10.98.150.206 with SMTP id s75mr38738252pfk.155.1480588685828; Thu, 01 Dec 2016 02:38:05 -0800 (PST) Received: from localhost ([122.172.143.30]) by smtp.gmail.com with ESMTPSA id s197sm91896619pgc.38.2016.12.01.02.38.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Dec 2016 02:38:05 -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] devfreq: rk3399_dmc: Don't use OPP structures outside of RCU locks Date: Thu, 1 Dec 2016 16:08:01 +0530 Message-Id: <22bf6dfc155a6a241c2ee4e2b44a615d0e82064d.1480588658.git.viresh.kumar@linaro.org> 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. Signed-off-by: Viresh Kumar --- I would like it to go via the PM tree. Perhaps that's already the default tree for this. 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 Reviewed-by: Chanwoo Choi diff --git a/drivers/devfreq/rk3399_dmc.c b/drivers/devfreq/rk3399_dmc.c index 5063ac1a5939..cf14631b1945 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); } + dmcfreq->rate = dev_pm_opp_get_freq(opp); + dmcfreq->volt = dev_pm_opp_get_voltage(opp); rcu_read_unlock(); - data->curr_opp = opp; rk3399_devfreq_dmc_profile.initial_freq = data->rate;