From patchwork Tue Jun 17 19:36:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Pargmann X-Patchwork-Id: 4369851 Return-Path: X-Original-To: patchwork-linux-arm@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 260F5BEEAA for ; Tue, 17 Jun 2014 19:40:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 516EC2020A for ; Tue, 17 Jun 2014 19:40:04 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A3E97202D1 for ; Tue, 17 Jun 2014 19:40:02 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WwzC3-0003MF-Fp; Tue, 17 Jun 2014 19:37:19 +0000 Received: from metis.ext.pengutronix.de ([2001:6f8:1178:4:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WwzC0-0003JA-90 for linux-arm-kernel@lists.infradead.org; Tue, 17 Jun 2014 19:37:17 +0000 Received: from dude.hi.pengutronix.de ([2001:6f8:1178:2:a236:9fff:fe00:814]) by metis.ext.pengutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1WwzBU-0005ks-Sf; Tue, 17 Jun 2014 21:36:44 +0200 Received: from mpa by dude.hi.pengutronix.de with local (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1WwzBU-0005Qf-2D; Tue, 17 Jun 2014 21:36:44 +0200 From: Markus Pargmann To: Mark Brown Subject: [PATCH] regmap: Add Kconfig option for debugfs register writes Date: Tue, 17 Jun 2014 21:36:35 +0200 Message-Id: <1403033795-9122-1-git-send-email-mpa@pengutronix.de> X-Mailer: git-send-email 2.0.0 X-SA-Exim-Connect-IP: 2001:6f8:1178:2:a236:9fff:fe00:814 X-SA-Exim-Mail-From: mpa@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140617_123716_731772_99DA733C X-CRM114-Status: GOOD ( 16.66 ) X-Spam-Score: -1.0 (-) Cc: kernel@pengutronix.de, Markus Pargmann , Dimitris Papastamos , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,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 To enable writing of registers through the regmap debugfs interface, it was necessary to alter the regmap-debugfs.c source code. This is not really practical. As this is a powerful tool for debugging, this patch creates an expert kconfig option for this function. This makes it easier to enable register writing in the kernel. This patch also fixes the file mode when the regmap debugfs write code is compiled. Cc: Dimitris Papastamos Signed-off-by: Markus Pargmann --- drivers/base/regmap/Kconfig | 14 ++++++++++++++ drivers/base/regmap/regmap-debugfs.c | 16 ++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/drivers/base/regmap/Kconfig b/drivers/base/regmap/Kconfig index 4251570610c9..ce86600dbe75 100644 --- a/drivers/base/regmap/Kconfig +++ b/drivers/base/regmap/Kconfig @@ -23,3 +23,17 @@ config REGMAP_MMIO config REGMAP_IRQ bool + +config REGMAP_ALLOW_WRITE_DEBUGFS + default n + depends on DEBUG_FS + depends on EXPERT + depends on REGMAP + bool "Regmap, allow direct register writes through debugfs" + help + This option enables regmap debugfs write support. If this is enabled, + you can directly write registers using the registers file in the + regmap debugfs. + + This is potentially dangerous. Do not enable this option unless you + know what you are doing. diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c index 45d812c0ea77..12906f2bdf00 100644 --- a/drivers/base/regmap/regmap-debugfs.c +++ b/drivers/base/regmap/regmap-debugfs.c @@ -261,13 +261,10 @@ static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf, count, ppos); } -#undef REGMAP_ALLOW_WRITE_DEBUGFS -#ifdef REGMAP_ALLOW_WRITE_DEBUGFS +#if IS_ENABLED(CONFIG_REGMAP_ALLOW_WRITE_DEBUGFS) /* * This can be dangerous especially when we have clients such as - * PMICs, therefore don't provide any real compile time configuration option - * for this feature, people who want to use this will need to modify - * the source code directly. + * PMICs, therefore this function can only be selected in expert kconfig mode. */ static ssize_t regmap_map_write_file(struct file *file, const char __user *user_buf, @@ -512,7 +509,14 @@ void regmap_debugfs_init(struct regmap *map, const char *name) map, ®map_reg_ranges_fops); if (map->max_register || regmap_readable(map, 0)) { - debugfs_create_file("registers", 0400, map->debugfs, + unsigned int registers_mode; + + if (IS_ENABLED(CONFIG_REGMAP_ALLOW_WRITE_DEBUGFS)) + registers_mode = 0600; + else + registers_mode = 0400; + + debugfs_create_file("registers", registers_mode, map->debugfs, map, ®map_map_fops); debugfs_create_file("access", 0400, map->debugfs, map, ®map_access_fops);