Received: by 2002:a4a:311b:0:0:0:0:0 with SMTP id k27-v6csp4758241ooa; Tue, 14 Aug 2018 10:08:27 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwoLtusOmqrcFxv0R9NhdKqwbMZhwi/4X61Y+/WYQM5fC+/3Y+y1ExFG6d6tIyiEpoTdD5d X-Received: by 2002:a17:902:7b83:: with SMTP id w3-v6mr21004464pll.192.1534266507274; Tue, 14 Aug 2018 10:08:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534266507; cv=none; d=google.com; s=arc-20160816; b=0D422e+72an+sscdgzsVMYr5fm+a7BCrr6JKdgZXqmntctL29/Fl6fuq75GBNTmwkt p1l6TrlM3wCzAvec1JBrR0XADo9iIaGq3MIXhjKeQHdpUCY9Z5LWcG2sBZJQ4Nb1q3Pi 9rPz5olLRjuhBiFVp3aAl63zq6jUzRCJ+LoI3IFxg9trJgq/kyY0jbfTjmolvtPk9IW2 74JgFk99G93IhJQ9nrEVJpzLHjovYAIVj4Mm/2wDjk1Ku46jks63LT22MPmL66OiaD+g TwIbAVVfwZMf87tbzJvzF2lm3ycyIPwVRLiAvSrW5rHjaWTRx5wXE30vnH0m3yFBygvc ykMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=sxQDdG2Di+2iO3ayrNjTUf45BVaOyDbXM7D3wCE/SSA=; b=H4EF1xfP2D7cAgDMRZWtoz3zJtuvUpt9HaHlUouI1yNtsaRTj5E+NQqhwPm6vgzEbV RPPCyxtdA0LCKpOQEGV6JcokkF2pM8nkJRw6lskE47kn7chaoJKU9Jz6yniR9fKnkaQ+ JBsOTN87hrWgy36dX3A5Gj+kbXOyyFoKVyClNtRcAPZKL4Qt0nVhvTEUUEfRkdrqf1Sw G5InyxWR/1Z2B9W2U7F8l4Q5imig152oRxD2bNeFZjNaN8z7kdRtnFUVRUH9iJ72AOr5 8an3t+8FnqmSY/5zdDX8WXXgA3OzaHYbz3qceoIcxudfEUNHTMuH2+SomiM2DkSSfS9V 5RPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dAcdROHg; 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=pass (p=REJECT sp=REJECT 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 v8-v6si19548757pff.248.2018.08.14.10.08.12; Tue, 14 Aug 2018 10:08:27 -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; dkim=pass header.i=@chromium.org header.s=google header.b=dAcdROHg; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387680AbeHNTy6 (ORCPT + 99 others); Tue, 14 Aug 2018 15:54:58 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:41433 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387669AbeHNTy6 (ORCPT ); Tue, 14 Aug 2018 15:54:58 -0400 Received: by mail-pl0-f66.google.com with SMTP id w19-v6so8560253ply.8 for ; Tue, 14 Aug 2018 10:06:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sxQDdG2Di+2iO3ayrNjTUf45BVaOyDbXM7D3wCE/SSA=; b=dAcdROHgkaV2icsrCS6q3rz3ETVNxvPEhT8B2BXyEXqwXWHqgF+HxzsBkY4VrFdnKK YyzJPiLM3sikpfnj1HQ3xIu5030ZZyKAleUvhrRh/bmuLddzO/2/GbpLGHRCEniw/zWx KDbUIpOJTUHcuC5+8jB3ByHS3jwf6j9R5peNg= 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:mime-version:content-transfer-encoding; bh=sxQDdG2Di+2iO3ayrNjTUf45BVaOyDbXM7D3wCE/SSA=; b=oUmBhDGfnI9ycXLY7QzbeZbeczuEB4k7cJGITOIQKrDlXGPUyzIH6vpZc35LXZ+3EV pALQ36xB5VsaGTzrtzqJ8278RPBmkBSsPi+uRyGu5OS8sYo7LllJ53LuUF+Uff7ZjKqd ba3jYTUo9KXlaHOmelC48WHk0uliezayyAImOCcuBZQCX94FCNi/FsZl4FocjC9vmdFJ +/EUn1GMt+/4a55XE5Y+KAkBzsEIDckg4Y0PfKsYrKuLIj9uP64MAmb0iHoBJsqKSVoV ejUYyjyAr4cFiEgnHCUGAcTudi9qVwDuulfeoQp/IfxMwXSpIGKPMhVVqJBzEu0IM+2l qoEw== X-Gm-Message-State: AOUpUlHAp0Y9xgDcCM4HJ80NjPa8Wg2YlBqAtIXSm3rMGnbFJxZsEWwi e8jrSlAsTrInXv/24Dgr3T/64g== X-Received: by 2002:a17:902:8e86:: with SMTP id bg6-v6mr21097403plb.108.1534266417906; Tue, 14 Aug 2018 10:06:57 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:c8e0:70d7:4be7:a36]) by smtp.gmail.com with ESMTPSA id d19-v6sm67940763pfe.42.2018.08.14.10.06.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Aug 2018 10:06:57 -0700 (PDT) From: Douglas Anderson To: broonie@kernel.org Cc: linux-arm-msm@vger.kernel.org, bjorn.andersson@linaro.org, collinsd@codeaurora.org, swboyd@chromium.org, Douglas Anderson , Liam Girdwood , linux-kernel@vger.kernel.org Subject: [PATCH 4/4] regulator: core: Add locking to debugfs regulator_summary Date: Tue, 14 Aug 2018 10:06:17 -0700 Message-Id: <20180814170617.100087-5-dianders@chromium.org> X-Mailer: git-send-email 2.18.0.865.gffc8e1a3cd6-goog In-Reply-To: <20180814170617.100087-1-dianders@chromium.org> References: <20180814170617.100087-1-dianders@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Most functions that access the rdev lock the rdev mutex before looking at data. ...but not the code that implements the debugfs regulator_summary. It probably should though, so let's do it. Signed-off-by: Douglas Anderson --- drivers/regulator/core.c | 51 ++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 23f64faa6961..5950b44c10d5 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -3468,21 +3468,23 @@ int regulator_set_current_limit(struct regulator *regulator, } EXPORT_SYMBOL_GPL(regulator_set_current_limit); +static int _regulator_get_current_limit_unlocked(struct regulator_dev *rdev) +{ + /* sanity check */ + if (!rdev->desc->ops->get_current_limit) + return -EINVAL; + + return rdev->desc->ops->get_current_limit(rdev); +} + static int _regulator_get_current_limit(struct regulator_dev *rdev) { int ret; regulator_lock(rdev); - - /* sanity check */ - if (!rdev->desc->ops->get_current_limit) { - ret = -EINVAL; - goto out; - } - - ret = rdev->desc->ops->get_current_limit(rdev); -out: + ret = _regulator_get_current_limit_unlocked(rdev); regulator_unlock(rdev); + return ret; } @@ -3547,21 +3549,23 @@ int regulator_set_mode(struct regulator *regulator, unsigned int mode) } EXPORT_SYMBOL_GPL(regulator_set_mode); +static unsigned int _regulator_get_mode_unlocked(struct regulator_dev *rdev) +{ + /* sanity check */ + if (!rdev->desc->ops->get_mode) + return -EINVAL; + + return rdev->desc->ops->get_mode(rdev); +} + static unsigned int _regulator_get_mode(struct regulator_dev *rdev) { int ret; regulator_lock(rdev); - - /* sanity check */ - if (!rdev->desc->ops->get_mode) { - ret = -EINVAL; - goto out; - } - - ret = rdev->desc->ops->get_mode(rdev); -out: + ret = _regulator_get_mode_unlocked(rdev); regulator_unlock(rdev); + return ret; } @@ -4669,18 +4673,23 @@ static void regulator_summary_show_subtree(struct seq_file *s, struct regulation_constraints *c; struct regulator *consumer; struct summary_data summary_data; + unsigned int opmode; if (!rdev) return; + regulator_lock_nested(rdev, level); + + opmode = _regulator_get_mode_unlocked(rdev); seq_printf(s, "%*s%-*s %3d %4d %6d %7s ", level * 3 + 1, "", 30 - level * 3, rdev_get_name(rdev), rdev->use_count, rdev->open_count, rdev->bypass_count, - regulator_opmode_to_str(_regulator_get_mode(rdev))); + regulator_opmode_to_str(opmode)); seq_printf(s, "%5dmV ", _regulator_get_voltage(rdev) / 1000); - seq_printf(s, "%5dmA ", _regulator_get_current_limit(rdev) / 1000); + seq_printf(s, "%5dmA ", + _regulator_get_current_limit_unlocked(rdev) / 1000); c = rdev->constraints; if (c) { @@ -4733,6 +4742,8 @@ static void regulator_summary_show_subtree(struct seq_file *s, class_for_each_device(®ulator_class, NULL, &summary_data, regulator_summary_show_children); + + regulator_unlock(rdev); } static int regulator_summary_show_roots(struct device *dev, void *data) -- 2.18.0.865.gffc8e1a3cd6-goog