* [PATCH] debugfs: Add debugfs_create_ulong()
@ 2015-10-09 15:04 Viresh Kumar
2015-10-09 16:39 ` Stephen Boyd
2015-10-09 17:11 ` [PATCH V2] " Viresh Kumar
0 siblings, 2 replies; 7+ messages in thread
From: Viresh Kumar @ 2015-10-09 15:04 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: linaro-kernel, Rafael Wysocki, linux-kernel, arnd, sboyd,
linux-pm, linux, stern, Viresh Kumar
Add debugfs_create_ulong() for the users of type 'unsigned long'. These
will be 32 bits long on a 32 bit machine and 64 bits long on a 64 bit
machine and so can't use the traditional debugfs_create_u64() or
debugfs_create_u32() APIs.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
Hi Greg,
I thought there were few supporters of this interface and I need it for
the OPP debugfs stuff. So this is an attempt to move the discussion out
of the closed thread, to an open one where others can join.
And if all goes well, then you can apply it directly. Its tested with
the OPP debugfs stuff :)
fs/debugfs/file.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++
include/linux/debugfs.h | 4 ++++
2 files changed, 59 insertions(+)
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index b70c20fae502..28a7fe6ea618 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -251,6 +251,60 @@ struct dentry *debugfs_create_u64(const char *name, umode_t mode,
}
EXPORT_SYMBOL_GPL(debugfs_create_u64);
+static int debugfs_ulong_set(void *data, u64 val)
+{
+ *(unsigned long *)data = val;
+ return 0;
+}
+
+static int debugfs_ulong_get(void *data, u64 *val)
+{
+ *val = *(unsigned long *)data;
+ return 0;
+}
+DEFINE_SIMPLE_ATTRIBUTE(fops_ulong, debugfs_ulong_get, debugfs_ulong_set, "%llu\n");
+DEFINE_SIMPLE_ATTRIBUTE(fops_ulong_ro, debugfs_ulong_get, NULL, "%llu\n");
+DEFINE_SIMPLE_ATTRIBUTE(fops_ulong_wo, NULL, debugfs_ulong_set, "%llu\n");
+
+/**
+ * debugfs_create_ulong - create a debugfs file that is used to read and write
+ * an unsigned long value.
+ * @name: a pointer to a string containing the name of the file to create.
+ * @mode: the permission that the file should have
+ * @parent: a pointer to the parent dentry for this file. This should be a
+ * directory dentry if set. If this parameter is %NULL, then the
+ * file will be created in the root of the debugfs filesystem.
+ * @value: a pointer to the variable that the file should read to and write
+ * from.
+ *
+ * This function creates a file in debugfs with the given name that
+ * contains the value of the variable @value. If the @mode variable is so
+ * set, it can be read from, and written to.
+ *
+ * This function will return a pointer to a dentry if it succeeds. This
+ * pointer must be passed to the debugfs_remove() function when the file is
+ * to be removed (no automatic cleanup happens if your module is unloaded,
+ * you are responsible here.) If an error occurs, %NULL will be returned.
+ *
+ * If debugfs is not enabled in the kernel, the value -%ENODEV will be
+ * returned. It is not wise to check for this value, but rather, check for
+ * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling
+ * code.
+ */
+struct dentry *debugfs_create_ulong(const char *name, umode_t mode,
+ struct dentry *parent, unsigned long *value)
+{
+ /* if there are no write bits set, make read only */
+ if (!(mode & S_IWUGO))
+ return debugfs_create_file(name, mode, parent, value, &fops_ulong_ro);
+ /* if there are no read bits set, make write only */
+ if (!(mode & S_IRUGO))
+ return debugfs_create_file(name, mode, parent, value, &fops_ulong_wo);
+
+ return debugfs_create_file(name, mode, parent, value, &fops_ulong);
+}
+EXPORT_SYMBOL_GPL(debugfs_create_ulong);
+
DEFINE_SIMPLE_ATTRIBUTE(fops_x8, debugfs_u8_get, debugfs_u8_set, "0x%02llx\n");
DEFINE_SIMPLE_ATTRIBUTE(fops_x8_ro, debugfs_u8_get, NULL, "0x%02llx\n");
DEFINE_SIMPLE_ATTRIBUTE(fops_x8_wo, NULL, debugfs_u8_set, "0x%02llx\n");
@@ -264,6 +318,7 @@ DEFINE_SIMPLE_ATTRIBUTE(fops_x32_ro, debugfs_u32_get, NULL, "0x%08llx\n");
DEFINE_SIMPLE_ATTRIBUTE(fops_x32_wo, NULL, debugfs_u32_set, "0x%08llx\n");
DEFINE_SIMPLE_ATTRIBUTE(fops_x64, debugfs_u64_get, debugfs_u64_set, "0x%016llx\n");
+DEFINE_SIMPLE_ATTRIBUTE(fops_xlong, debugfs_ulong_get, debugfs_ulong_set, "0x%016llx\n");
/*
* debugfs_create_x{8,16,32,64} - create a debugfs file that is used to read and write an unsigned {8,16,32,64}-bit value
diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h
index 8321fe3058d6..60b150248b54 100644
--- a/include/linux/debugfs.h
+++ b/include/linux/debugfs.h
@@ -79,6 +79,8 @@ struct dentry *debugfs_create_u32(const char *name, umode_t mode,
struct dentry *parent, u32 *value);
struct dentry *debugfs_create_u64(const char *name, umode_t mode,
struct dentry *parent, u64 *value);
+struct dentry *debugfs_create_ulong(const char *name, umode_t mode,
+ struct dentry *parent, unsigned long *value);
struct dentry *debugfs_create_x8(const char *name, umode_t mode,
struct dentry *parent, u8 *value);
struct dentry *debugfs_create_x16(const char *name, umode_t mode,
@@ -87,6 +89,8 @@ struct dentry *debugfs_create_x32(const char *name, umode_t mode,
struct dentry *parent, u32 *value);
struct dentry *debugfs_create_x64(const char *name, umode_t mode,
struct dentry *parent, u64 *value);
+struct dentry *debugfs_create_xlong(const char *name, umode_t mode,
+ struct dentry *parent, unsigned long *value);
struct dentry *debugfs_create_size_t(const char *name, umode_t mode,
struct dentry *parent, size_t *value);
struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode,
--
2.4.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] debugfs: Add debugfs_create_ulong()
2015-10-09 15:04 [PATCH] debugfs: Add debugfs_create_ulong() Viresh Kumar
@ 2015-10-09 16:39 ` Stephen Boyd
2015-10-09 17:11 ` [PATCH V2] " Viresh Kumar
1 sibling, 0 replies; 7+ messages in thread
From: Stephen Boyd @ 2015-10-09 16:39 UTC (permalink / raw)
To: Viresh Kumar
Cc: Greg Kroah-Hartman, linaro-kernel, Rafael Wysocki, linux-kernel,
arnd, linux-pm, linux, stern
On 10/09, Viresh Kumar wrote:
> @@ -87,6 +89,8 @@ struct dentry *debugfs_create_x32(const char *name, umode_t mode,
> struct dentry *parent, u32 *value);
> struct dentry *debugfs_create_x64(const char *name, umode_t mode,
> struct dentry *parent, u64 *value);
> +struct dentry *debugfs_create_xlong(const char *name, umode_t mode,
> + struct dentry *parent, unsigned long *value);
Where is this function defined? The non-x version looks ok.
--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH V2] debugfs: Add debugfs_create_ulong()
2015-10-09 15:04 [PATCH] debugfs: Add debugfs_create_ulong() Viresh Kumar
2015-10-09 16:39 ` Stephen Boyd
@ 2015-10-09 17:11 ` Viresh Kumar
2015-10-14 18:51 ` Stephen Boyd
1 sibling, 1 reply; 7+ messages in thread
From: Viresh Kumar @ 2015-10-09 17:11 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: linaro-kernel, Rafael Wysocki, linux-kernel, arnd, sboyd,
linux-pm, linux, stern, Viresh Kumar
Add debugfs_create_ulong() for the users of type 'unsigned long'. These
will be 32 bits long on a 32 bit machine and 64 bits long on a 64 bit
machine.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
V1->V2:
- Fix missing debugfs_create_xlong() routine, was left in the
repository.
fs/debugfs/file.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++
include/linux/debugfs.h | 4 +++
2 files changed, 76 insertions(+)
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index b70c20fae502..129d19b72fd4 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -251,6 +251,60 @@ struct dentry *debugfs_create_u64(const char *name, umode_t mode,
}
EXPORT_SYMBOL_GPL(debugfs_create_u64);
+static int debugfs_ulong_set(void *data, u64 val)
+{
+ *(unsigned long *)data = val;
+ return 0;
+}
+
+static int debugfs_ulong_get(void *data, u64 *val)
+{
+ *val = *(unsigned long *)data;
+ return 0;
+}
+DEFINE_SIMPLE_ATTRIBUTE(fops_ulong, debugfs_ulong_get, debugfs_ulong_set, "%llu\n");
+DEFINE_SIMPLE_ATTRIBUTE(fops_ulong_ro, debugfs_ulong_get, NULL, "%llu\n");
+DEFINE_SIMPLE_ATTRIBUTE(fops_ulong_wo, NULL, debugfs_ulong_set, "%llu\n");
+
+/**
+ * debugfs_create_ulong - create a debugfs file that is used to read and write
+ * an unsigned long value.
+ * @name: a pointer to a string containing the name of the file to create.
+ * @mode: the permission that the file should have
+ * @parent: a pointer to the parent dentry for this file. This should be a
+ * directory dentry if set. If this parameter is %NULL, then the
+ * file will be created in the root of the debugfs filesystem.
+ * @value: a pointer to the variable that the file should read to and write
+ * from.
+ *
+ * This function creates a file in debugfs with the given name that
+ * contains the value of the variable @value. If the @mode variable is so
+ * set, it can be read from, and written to.
+ *
+ * This function will return a pointer to a dentry if it succeeds. This
+ * pointer must be passed to the debugfs_remove() function when the file is
+ * to be removed (no automatic cleanup happens if your module is unloaded,
+ * you are responsible here.) If an error occurs, %NULL will be returned.
+ *
+ * If debugfs is not enabled in the kernel, the value -%ENODEV will be
+ * returned. It is not wise to check for this value, but rather, check for
+ * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling
+ * code.
+ */
+struct dentry *debugfs_create_ulong(const char *name, umode_t mode,
+ struct dentry *parent, unsigned long *value)
+{
+ /* if there are no write bits set, make read only */
+ if (!(mode & S_IWUGO))
+ return debugfs_create_file(name, mode, parent, value, &fops_ulong_ro);
+ /* if there are no read bits set, make write only */
+ if (!(mode & S_IRUGO))
+ return debugfs_create_file(name, mode, parent, value, &fops_ulong_wo);
+
+ return debugfs_create_file(name, mode, parent, value, &fops_ulong);
+}
+EXPORT_SYMBOL_GPL(debugfs_create_ulong);
+
DEFINE_SIMPLE_ATTRIBUTE(fops_x8, debugfs_u8_get, debugfs_u8_set, "0x%02llx\n");
DEFINE_SIMPLE_ATTRIBUTE(fops_x8_ro, debugfs_u8_get, NULL, "0x%02llx\n");
DEFINE_SIMPLE_ATTRIBUTE(fops_x8_wo, NULL, debugfs_u8_set, "0x%02llx\n");
@@ -264,6 +318,7 @@ DEFINE_SIMPLE_ATTRIBUTE(fops_x32_ro, debugfs_u32_get, NULL, "0x%08llx\n");
DEFINE_SIMPLE_ATTRIBUTE(fops_x32_wo, NULL, debugfs_u32_set, "0x%08llx\n");
DEFINE_SIMPLE_ATTRIBUTE(fops_x64, debugfs_u64_get, debugfs_u64_set, "0x%016llx\n");
+DEFINE_SIMPLE_ATTRIBUTE(fops_xlong, debugfs_ulong_get, debugfs_ulong_set, "0x%016llx\n");
/*
* debugfs_create_x{8,16,32,64} - create a debugfs file that is used to read and write an unsigned {8,16,32,64}-bit value
@@ -362,6 +417,23 @@ struct dentry *debugfs_create_x64(const char *name, umode_t mode,
}
EXPORT_SYMBOL_GPL(debugfs_create_x64);
+/**
+ * debugfs_create_xlong - create a debugfs file that is used to read and write an unsigned long value
+ * @name: a pointer to a string containing the name of the file to create.
+ * @mode: the permission that the file should have
+ * @parent: a pointer to the parent dentry for this file. This should be a
+ * directory dentry if set. If this parameter is %NULL, then the
+ * file will be created in the root of the debugfs filesystem.
+ * @value: a pointer to the variable that the file should read to and write
+ * from.
+ */
+struct dentry *debugfs_create_xlong(const char *name, umode_t mode,
+ struct dentry *parent, unsigned long *value)
+{
+ return debugfs_create_file(name, mode, parent, value, &fops_xlong);
+}
+EXPORT_SYMBOL_GPL(debugfs_create_xlong);
+
static int debugfs_size_t_set(void *data, u64 val)
{
diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h
index 8321fe3058d6..60b150248b54 100644
--- a/include/linux/debugfs.h
+++ b/include/linux/debugfs.h
@@ -79,6 +79,8 @@ struct dentry *debugfs_create_u32(const char *name, umode_t mode,
struct dentry *parent, u32 *value);
struct dentry *debugfs_create_u64(const char *name, umode_t mode,
struct dentry *parent, u64 *value);
+struct dentry *debugfs_create_ulong(const char *name, umode_t mode,
+ struct dentry *parent, unsigned long *value);
struct dentry *debugfs_create_x8(const char *name, umode_t mode,
struct dentry *parent, u8 *value);
struct dentry *debugfs_create_x16(const char *name, umode_t mode,
@@ -87,6 +89,8 @@ struct dentry *debugfs_create_x32(const char *name, umode_t mode,
struct dentry *parent, u32 *value);
struct dentry *debugfs_create_x64(const char *name, umode_t mode,
struct dentry *parent, u64 *value);
+struct dentry *debugfs_create_xlong(const char *name, umode_t mode,
+ struct dentry *parent, unsigned long *value);
struct dentry *debugfs_create_size_t(const char *name, umode_t mode,
struct dentry *parent, size_t *value);
struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode,
--
2.4.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH V2] debugfs: Add debugfs_create_ulong()
2015-10-09 17:11 ` [PATCH V2] " Viresh Kumar
@ 2015-10-14 18:51 ` Stephen Boyd
2015-10-15 7:12 ` Viresh Kumar
0 siblings, 1 reply; 7+ messages in thread
From: Stephen Boyd @ 2015-10-14 18:51 UTC (permalink / raw)
To: Viresh Kumar
Cc: Greg Kroah-Hartman, linaro-kernel, Rafael Wysocki, linux-kernel,
arnd, linux-pm, linux, stern
On 10/09, Viresh Kumar wrote:
> +struct dentry *debugfs_create_xlong(const char *name, umode_t mode,
> + struct dentry *parent, unsigned long *value)
> +{
> + return debugfs_create_file(name, mode, parent, value, &fops_xlong);
Were you going to refresh this on my debugfs_create_mode()
patches? Otherwise the patch looks fine to me.
--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2] debugfs: Add debugfs_create_ulong()
2015-10-14 18:51 ` Stephen Boyd
@ 2015-10-15 7:12 ` Viresh Kumar
2015-10-15 18:25 ` Stephen Boyd
0 siblings, 1 reply; 7+ messages in thread
From: Viresh Kumar @ 2015-10-15 7:12 UTC (permalink / raw)
To: Stephen Boyd
Cc: Greg Kroah-Hartman, linaro-kernel, Rafael Wysocki, linux-kernel,
arnd, linux-pm, linux, stern
On 14-10-15, 11:51, Stephen Boyd wrote:
> On 10/09, Viresh Kumar wrote:
> > +struct dentry *debugfs_create_xlong(const char *name, umode_t mode,
> > + struct dentry *parent, unsigned long *value)
> > +{
> > + return debugfs_create_file(name, mode, parent, value, &fops_xlong);
>
> Were you going to refresh this on my debugfs_create_mode()
> patches? Otherwise the patch looks fine to me.
I thought you need to refresh your set as I posted this before you
have :)
--
viresh
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2] debugfs: Add debugfs_create_ulong()
2015-10-15 7:12 ` Viresh Kumar
@ 2015-10-15 18:25 ` Stephen Boyd
2015-10-18 5:10 ` Greg Kroah-Hartman
0 siblings, 1 reply; 7+ messages in thread
From: Stephen Boyd @ 2015-10-15 18:25 UTC (permalink / raw)
To: Viresh Kumar
Cc: Greg Kroah-Hartman, linaro-kernel, Rafael Wysocki, linux-kernel,
arnd, linux-pm, linux, stern
On 10/15, Viresh Kumar wrote:
> On 14-10-15, 11:51, Stephen Boyd wrote:
> > On 10/09, Viresh Kumar wrote:
> > > +struct dentry *debugfs_create_xlong(const char *name, umode_t mode,
> > > + struct dentry *parent, unsigned long *value)
> > > +{
> > > + return debugfs_create_file(name, mode, parent, value, &fops_xlong);
> >
> > Were you going to refresh this on my debugfs_create_mode()
> > patches? Otherwise the patch looks fine to me.
>
> I thought you need to refresh your set as I posted this before you
> have :)
>
:)
Well this patch is creating xlong without any
read-only/write-only ops, so it has the same potential problems
as what the debugfs_create_mode() series was fixing. I'm fine
either way though.
--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2] debugfs: Add debugfs_create_ulong()
2015-10-15 18:25 ` Stephen Boyd
@ 2015-10-18 5:10 ` Greg Kroah-Hartman
0 siblings, 0 replies; 7+ messages in thread
From: Greg Kroah-Hartman @ 2015-10-18 5:10 UTC (permalink / raw)
To: Stephen Boyd
Cc: Viresh Kumar, linaro-kernel, Rafael Wysocki, linux-kernel, arnd,
linux-pm, linux, stern
On Thu, Oct 15, 2015 at 11:25:55AM -0700, Stephen Boyd wrote:
> On 10/15, Viresh Kumar wrote:
> > On 14-10-15, 11:51, Stephen Boyd wrote:
> > > On 10/09, Viresh Kumar wrote:
> > > > +struct dentry *debugfs_create_xlong(const char *name, umode_t mode,
> > > > + struct dentry *parent, unsigned long *value)
> > > > +{
> > > > + return debugfs_create_file(name, mode, parent, value, &fops_xlong);
> > >
> > > Were you going to refresh this on my debugfs_create_mode()
> > > patches? Otherwise the patch looks fine to me.
> >
> > I thought you need to refresh your set as I posted this before you
> > have :)
> >
>
> :)
>
> Well this patch is creating xlong without any
> read-only/write-only ops, so it has the same potential problems
> as what the debugfs_create_mode() series was fixing. I'm fine
> either way though.
Viresh, please rebase your patch on top of Stephen's series, it should
make your patch much smaller. I've applied his series to my tree now.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-10-18 5:10 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-09 15:04 [PATCH] debugfs: Add debugfs_create_ulong() Viresh Kumar
2015-10-09 16:39 ` Stephen Boyd
2015-10-09 17:11 ` [PATCH V2] " Viresh Kumar
2015-10-14 18:51 ` Stephen Boyd
2015-10-15 7:12 ` Viresh Kumar
2015-10-15 18:25 ` Stephen Boyd
2015-10-18 5:10 ` Greg Kroah-Hartman
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).