From patchwork Tue Dec 12 17:13:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 121581 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4388990qgn; Tue, 12 Dec 2017 09:14:05 -0800 (PST) X-Google-Smtp-Source: ACJfBotrG+xhg/qbCgfdsh1WyDirbviJLMXLq+lX0k648rWdEuUokYtV4kybi40xLc5n8GE0PLp8 X-Received: by 10.101.96.138 with SMTP id t10mr2693980pgu.335.1513098845891; Tue, 12 Dec 2017 09:14:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513098845; cv=none; d=google.com; s=arc-20160816; b=NuS16aatEZpdW70tWAL6FBramKAxF+Gg2Q3h5///PkvRRmajMjOy8g3vXkicvrpqgK F7RQ1s8zzUziwxiSVU2qIWh1k1WwlJZwK3AgDq3dt9jG7LQAVOo6J5/Ai4USURFsPmRF eyicDc2V8Y7tCX9rcgr/IIseHvPhiEUdZHWznWis65NeFcvyZ2VXzdUv/H/rsRxAisW4 g7RWj6VqSfJRcvsQd1tyeVzJOmpKo2QxosgPptA2xk47PWjT89ITKZdBID7KLqvQQxQn QIkK1NEozZWw5W11FjHAah+n/XnSsTurkW5HaDLDlMmU0T3bAQaGKVqY5humaSoUVgca 8sxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=X7wS8hJJ9WrlNPMvdegVu4dxtEJBjfFZChAThYzERhM=; b=R3wTTJ2MH+XIORjT2FOnyG3KTC2gvhZISOpPuAggaOMhOKQqhZIwVJNCalBmlAW8W9 u0271B7TouNgFoHKhwbzghNDCXc7H1pmAh9h4pjMDHt6YCSIOz4Au6ToaU1bAJpLaZvF XUwsvlVegD1eGbQ/Bbx/2eYbcb1OKn3m7jRMINBIMe6ZK80e7qpOzxbjcF6kTuv+NiZ5 IGwClnSbt09f8NOWSTRQetx7e4s0MF0ZR+ae2TxthuMvHouHLvppNVto3l+NXrhB3c7I /GXnPw5ycPCDh90rtEY1ztbw6pKRaMil/wjGYV1Gfavjw+vSQEhcwYyNJgaxSAkqq0X/ 7ZLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@sirena.org.uk header.s=20170815-heliosphere header.b=r7kuFyuy; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n1si11922905pld.501.2017.12.12.09.14.05; Tue, 12 Dec 2017 09:14:05 -0800 (PST) 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=fail header.i=@sirena.org.uk header.s=20170815-heliosphere header.b=r7kuFyuy; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752358AbdLLROC (ORCPT + 11 others); Tue, 12 Dec 2017 12:14:02 -0500 Received: from heliosphere.sirena.org.uk ([172.104.155.198]:36454 "EHLO heliosphere.sirena.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751665AbdLLROB (ORCPT ); Tue, 12 Dec 2017 12:14:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sirena.org.uk; s=20170815-heliosphere; h=Message-Id:Date:Subject:Cc:To:From :Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=X7wS8hJJ9WrlNPMvdegVu4dxtEJBjfFZChAThYzERhM=; b=r7kuFyuycO8kMdXjrFx4eNGIs ngr/NT9qKuW5CILDYeRbW93VgfybS4LVlNDVa2++VN1JgDJ82RZUWZe3HiP5i5ejARKnAkuM2qcgs vDwbMBumEvXrTJX5a15QWGf+H/Zayaqn9cDOCoTWQxjzrTz57GvqrwmiWb9dP/3RvOzTc=; Received: from debutante.sirena.org.uk ([2001:470:1f1d:6b5::3] helo=debutante) by heliosphere.sirena.org.uk with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1eOo7z-0007Qb-UF; Tue, 12 Dec 2017 17:13:59 +0000 Received: from broonie by debutante with local (Exim 4.90_RC3) (envelope-from ) id 1eOo7z-0007oV-16; Tue, 12 Dec 2017 17:13:59 +0000 From: Mark Brown To: Lars-Peter Clausen , Bartosz Golaszewski Cc: linux-kernel@vger.kernel.org, Mark Brown Subject: [PATCH] regmap: Disable debugfs when locking is disabled Date: Tue, 12 Dec 2017 17:13:55 +0000 Message-Id: <20171212171355.29992-1-broonie@kernel.org> X-Mailer: git-send-email 2.15.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The recently added support for disabling the regmap internal locking left debugfs enabled for devices with the locking disabled. This is a problem since debugfs allows userspace to do things like initiate reads from the hardware which will use the scratch buffers protected by the regmap locking so could cause data corruption. For safety address this by just disabling debugfs for these devices. That is overly conservative since some of the debugfs files just read internal data structures but it's much simpler to implmement and less likely to lead to problems with tooling that works with debugfs. Reported-by: Lars-Peter Clausen Signed-off-by: Mark Brown --- Compile tested only so far. drivers/base/regmap/internal.h | 8 ++++++++ drivers/base/regmap/regmap-debugfs.c | 3 +++ drivers/base/regmap/regmap.c | 1 + 3 files changed, 12 insertions(+) -- 2.15.1 diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h index 8641183cac2f..8d652023f8bd 100644 --- a/drivers/base/regmap/internal.h +++ b/drivers/base/regmap/internal.h @@ -77,6 +77,7 @@ struct regmap { int async_ret; #ifdef CONFIG_DEBUG_FS + bool debugfs_disable; struct dentry *debugfs; const char *debugfs_name; @@ -215,10 +216,17 @@ struct regmap_field { extern void regmap_debugfs_initcall(void); extern void regmap_debugfs_init(struct regmap *map, const char *name); extern void regmap_debugfs_exit(struct regmap *map); + +static void regmap_debugfs_disable(struct regmap *map) +{ + map->debugfs_disable = true; +} + #else static inline void regmap_debugfs_initcall(void) { } static inline void regmap_debugfs_init(struct regmap *map, const char *name) { } static inline void regmap_debugfs_exit(struct regmap *map) { } +static inline void regmap_debugfs_disable(struct regmap *map) { } #endif /* regcache core declarations */ diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c index 36ce3511c733..c8ecefd75d6f 100644 --- a/drivers/base/regmap/regmap-debugfs.c +++ b/drivers/base/regmap/regmap-debugfs.c @@ -529,6 +529,9 @@ void regmap_debugfs_init(struct regmap *map, const char *name) struct regmap_range_node *range_node; const char *devname = "dummy"; + if (map->debugfs_disable) + return; + /* If we don't have the debugfs root yet, postpone init */ if (!regmap_debugfs_root) { struct regmap_debugfs_node *node; diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 1da2a9fc40b0..b884da59dd71 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -674,6 +674,7 @@ struct regmap *__regmap_init(struct device *dev, if (config->disable_locking) { map->lock = map->unlock = regmap_lock_unlock_empty; + regmap_debugfs_disable(map); } else if (config->lock && config->unlock) { map->lock = config->lock; map->unlock = config->unlock;