From patchwork Tue Dec 16 23:09:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 5504171 X-Patchwork-Delegate: rjw@sisk.pl Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5CD79BEEA8 for ; Tue, 16 Dec 2014 23:11:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9166220A1B for ; Tue, 16 Dec 2014 23:11:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B2DF7209E5 for ; Tue, 16 Dec 2014 23:11:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751520AbaLPXKy (ORCPT ); Tue, 16 Dec 2014 18:10:54 -0500 Received: from mail-ie0-f169.google.com ([209.85.223.169]:59910 "EHLO mail-ie0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751711AbaLPXJz (ORCPT ); Tue, 16 Dec 2014 18:09:55 -0500 Received: by mail-ie0-f169.google.com with SMTP id y20so14024582ier.0 for ; Tue, 16 Dec 2014 15:09:54 -0800 (PST) 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:in-reply-to :references; bh=ngdRGTBgT9Vr/IfiE224QHtLS7cFnWKT2dOgqNGeqs4=; b=J0fDhjmogHKdGTfWaul5uYaU2QIbYuNCFzIx5GxovZF6TLCCrXKFh8sou4GgrH70Xf LP34/LHjdrwDYXBwFqZIn618E7DaaVez5VGcA5R2kESNpkunoOoQ/slh9JQOV9f22KQX h/AyA+8c7gNItnpOYDJcr1bup5tfttmtIyoxJym+I2vXaskUuDhzRPPqe6bbZWQlr9HD sGgCsAIhIEsa94jOLwda9Jp17plLcMa0NPFkvPECmqKpC3uLgZXTUlWGfNI1KltXsOSh Mc8pYftzZskGIryQODiVQh7t7BINSQjEv2dNLk2q1/zV1HudTMv6jr8Cx0TmOzuihFT+ MZqQ== X-Gm-Message-State: ALoCoQk34bTly7fcpNcu0cBQmjxtRm6fRXXVlr56sx294mN4bg5VflYvGE6o+BZq1xaR2WJhLtdK X-Received: by 10.42.96.195 with SMTP id k3mr21576839icn.7.1418771394758; Tue, 16 Dec 2014 15:09:54 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([172.22.64.149]) by mx.google.com with ESMTPSA id s10sm1424817igr.2.2014.12.16.15.09.53 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Dec 2014 15:09:54 -0800 (PST) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Viresh Kumar Cc: Thomas Petazzoni , Geert Uytterhoeven , Stefan Wahren , Paul Gortmaker , Nishanth Menon , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] PM / OPP: take RCU lock in dev_pm_opp_get_opp_count Date: Tue, 16 Dec 2014 15:09:38 -0800 Message-Id: <1418771379-24369-4-git-send-email-dtor@chromium.org> X-Mailer: git-send-email 2.2.0.rc0.207.ga3a616c In-Reply-To: <1418771379-24369-1-git-send-email-dtor@chromium.org> References: <1418771379-24369-1-git-send-email-dtor@chromium.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A lot of callers are missing the fact that dev_pm_opp_get_opp_count needs to be called under RCU lock. Given that RCU locks can safely be nested, instead of providing *_locked() API, let's take RCU lock inside dev_pm_opp_get_opp_count() and leave callers as is. Signed-off-by: Dmitry Torokhov Acked-by: Viresh Kumar --- drivers/base/power/opp.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c index 413c7fe..ee5eca2 100644 --- a/drivers/base/power/opp.c +++ b/drivers/base/power/opp.c @@ -216,9 +216,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_get_freq); * This function returns the number of available opps if there are any, * else returns 0 if none or the corresponding error value. * - * Locking: This function must be called under rcu_read_lock(). This function - * internally references two RCU protected structures: device_opp and opp which - * are safe as long as we are under a common RCU locked section. + * Locking: This function takes rcu_read_lock(). */ int dev_pm_opp_get_opp_count(struct device *dev) { @@ -226,13 +224,14 @@ int dev_pm_opp_get_opp_count(struct device *dev) struct dev_pm_opp *temp_opp; int count = 0; - opp_rcu_lockdep_assert(); + rcu_read_lock(); dev_opp = find_device_opp(dev); if (IS_ERR(dev_opp)) { - int r = PTR_ERR(dev_opp); - dev_err(dev, "%s: device OPP not found (%d)\n", __func__, r); - return r; + count = PTR_ERR(dev_opp); + dev_err(dev, "%s: device OPP not found (%d)\n", + __func__, count); + goto out_unlock; } list_for_each_entry_rcu(temp_opp, &dev_opp->opp_list, node) { @@ -240,6 +239,8 @@ int dev_pm_opp_get_opp_count(struct device *dev) count++; } +out_unlock: + rcu_read_unlock(); return count; } EXPORT_SYMBOL_GPL(dev_pm_opp_get_opp_count);