* [PATCH 2/3] regmap: Add support for writing to regmap `registers'
@ 2012-02-22 12:43 Dimitris Papastamos
2012-02-22 12:55 ` Mark Brown
0 siblings, 1 reply; 3+ messages in thread
From: Dimitris Papastamos @ 2012-02-22 12:43 UTC (permalink / raw)
To: Mark Brown; +Cc: Liam Girdwood, linux-kernel
To enable writing to the regmap `registers' file, users will
need to modify the source directly and #define REGMAP_ALLOW_WRITE_DEBUGFS.
The reason for this is that it is dangerous to expose this
functionality in general where clients could potentially be PMICs.
Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
---
drivers/base/regmap/regmap-debugfs.c | 39 ++++++++++++++++++++++++++++++++++
1 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c
index f4ac8d6..656e81f 100644
--- a/drivers/base/regmap/regmap-debugfs.c
+++ b/drivers/base/regmap/regmap-debugfs.c
@@ -103,9 +103,48 @@ out:
return ret;
}
+#undef REGMAP_ALLOW_WRITE_DEBUGFS
+#ifdef 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. */
+static ssize_t regmap_map_write_file(struct file *file, const char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+ char buf[32];
+ size_t buf_size;
+ char *start = buf;
+ unsigned long reg, value;
+ struct regmap *map = file->private_data;
+
+ buf_size = min(count, (sizeof(buf)-1));
+ if (copy_from_user(buf, user_buf, buf_size))
+ return -EFAULT;
+ buf[buf_size] = 0;
+
+ while (*start == ' ')
+ start++;
+ reg = simple_strtoul(start, &start, 16);
+ while (*start == ' ')
+ start++;
+ if (strict_strtoul(start, 16, &value))
+ return -EINVAL;
+
+ /* Userspace has been fiddling around behind the kernel's back */
+ add_taint(TAINT_USER);
+
+ regmap_write(map, reg, value);
+ return buf_size;
+}
+#endif
+
static const struct file_operations regmap_map_fops = {
.open = regmap_open_file,
.read = regmap_map_read_file,
+#ifdef REGMAP_ALLOW_WRITE_DEBUGFS
+ .write = regmap_map_write_file,
+#endif
.llseek = default_llseek,
};
--
1.7.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 2/3] regmap: Add support for writing to regmap `registers'
2012-02-22 12:43 [PATCH 2/3] regmap: Add support for writing to regmap `registers' Dimitris Papastamos
@ 2012-02-22 12:55 ` Mark Brown
2012-02-22 13:57 ` Dimitris Papastamos
0 siblings, 1 reply; 3+ messages in thread
From: Mark Brown @ 2012-02-22 12:55 UTC (permalink / raw)
To: Dimitris Papastamos; +Cc: Liam Girdwood, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 865 bytes --]
On Wed, Feb 22, 2012 at 12:43:50PM +0000, Dimitris Papastamos wrote:
> To enable writing to the regmap `registers' file, users will
> need to modify the source directly and #define REGMAP_ALLOW_WRITE_DEBUGFS.
> The reason for this is that it is dangerous to expose this
> functionality in general where clients could potentially be PMICs.
Applied but...
> +static ssize_t regmap_map_write_file(struct file *file, const char __user *user_buf,
> + size_t count, loff_t *ppos)
...with this wrapped into 80 columns.
> static const struct file_operations regmap_map_fops = {
> .open = regmap_open_file,
> .read = regmap_map_read_file,
> +#ifdef REGMAP_ALLOW_WRITE_DEBUGFS
> + .write = regmap_map_write_file,
> +#endif
It's also a bit more idiomatic to have an #else #define function NULL in
the main ifdef for stuff like this; I'll fix that up as well.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 2/3] regmap: Add support for writing to regmap `registers'
2012-02-22 12:55 ` Mark Brown
@ 2012-02-22 13:57 ` Dimitris Papastamos
0 siblings, 0 replies; 3+ messages in thread
From: Dimitris Papastamos @ 2012-02-22 13:57 UTC (permalink / raw)
To: Mark Brown; +Cc: Liam Girdwood, linux-kernel
On Wed, Feb 22, 2012 at 12:55:52PM +0000, Mark Brown wrote:
> On Wed, Feb 22, 2012 at 12:43:50PM +0000, Dimitris Papastamos wrote:
> > To enable writing to the regmap `registers' file, users will
> > need to modify the source directly and #define REGMAP_ALLOW_WRITE_DEBUGFS.
> > The reason for this is that it is dangerous to expose this
> > functionality in general where clients could potentially be PMICs.
> >
> > static const struct file_operations regmap_map_fops = {
> > .open = regmap_open_file,
> > .read = regmap_map_read_file,
> > +#ifdef REGMAP_ALLOW_WRITE_DEBUGFS
> > + .write = regmap_map_write_file,
> > +#endif
>
> It's also a bit more idiomatic to have an #else #define function NULL in
> the main ifdef for stuff like this; I'll fix that up as well.
Oops yea, that makes sense.
Thanks,
Dimitris
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-02-22 13:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-22 12:43 [PATCH 2/3] regmap: Add support for writing to regmap `registers' Dimitris Papastamos
2012-02-22 12:55 ` Mark Brown
2012-02-22 13:57 ` Dimitris Papastamos
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).