* [PATCH v2] backport: backport debugfs_create_bool()
@ 2015-11-06 8:04 Johannes Berg
2015-11-07 17:07 ` Hauke Mehrtens
0 siblings, 1 reply; 2+ messages in thread
From: Johannes Berg @ 2015-11-06 8:04 UTC (permalink / raw)
To: backports; +Cc: Johannes Berg
From: Johannes Berg <johannes.berg@intel.com>
The prototype for this function is changing upstream, so backport
a copy of the new one that has a bool * argument instead of u32 *.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
backport/backport-include/linux/debugfs.h | 15 ++++++++
backport/compat/Makefile | 1 +
backport/compat/backport-4.4.c | 64 +++++++++++++++++++++++++++++++
3 files changed, 80 insertions(+)
create mode 100644 backport/compat/backport-4.4.c
diff --git a/backport/backport-include/linux/debugfs.h b/backport/backport-include/linux/debugfs.h
index a68435322b4b..5ea4bfbe928e 100644
--- a/backport/backport-include/linux/debugfs.h
+++ b/backport/backport-include/linux/debugfs.h
@@ -24,4 +24,19 @@ static inline struct dentry *debugfs_create_devm_seqfile(struct device *dev,
#endif /* CONFIG_DEBUG_FS */
#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,19,0) */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,4,0)
+#define debugfs_create_bool LINUX_BACKPORT(debugfs_create_bool)
+#ifdef CONFIG_DEBUG_FS
+struct dentry *debugfs_create_bool(const char *name, umode_t mode,
+ struct dentry *parent, bool *value);
+#else
+static inline struct dentry *
+debugfs_create_bool(const char *name, umode_t mode,
+ struct dentry *parent, bool *value)
+{
+ return ERR_PTR(-ENODEV);
+}
+#endif
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(4,4,0) */
+
#endif /* __BACKPORT_DEBUGFS_H_ */
diff --git a/backport/compat/Makefile b/backport/compat/Makefile
index 666ef9111ace..fa992e780ec1 100644
--- a/backport/compat/Makefile
+++ b/backport/compat/Makefile
@@ -29,6 +29,7 @@ compat-$(CPTCFG_KERNEL_4_0) += backport-4.0.o
compat-$(CPTCFG_KERNEL_4_1) += backport-4.1.o
compat-$(CPTCFG_KERNEL_4_2) += backport-4.2.o
compat-$(CPTCFG_KERNEL_4_3) += backport-4.3.o
+compat-$(CPTCFG_KERNEL_4_4) += backport-4.4.o
compat-$(CPTCFG_BPAUTO_BUILD_CRYPTO_CCM) += crypto-ccm.o
compat-$(CPTCFG_BPAUTO_BUILD_DMA_SHARED_HELPERS) += dma-shared-helpers.o
diff --git a/backport/compat/backport-4.4.c b/backport/compat/backport-4.4.c
new file mode 100644
index 000000000000..d91d100af906
--- /dev/null
+++ b/backport/compat/backport-4.4.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright(c) 2015 Intel Deutschland GmbH
+ *
+ * Backport functionality introduced in Linux 4.4.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/debugfs.h>
+#include <linux/uaccess.h>
+#include <linux/fs.h>
+
+#ifdef CONFIG_DEBUG_FS
+static ssize_t debugfs_read_file_bool(struct file *file, char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+ char buf[3];
+ bool *val = file->private_data;
+
+ if (*val)
+ buf[0] = 'Y';
+ else
+ buf[0] = 'N';
+ buf[1] = '\n';
+ buf[2] = 0x00;
+ return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
+}
+
+static ssize_t debugfs_write_file_bool(struct file *file,
+ const char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+ char buf[32];
+ size_t buf_size;
+ bool bv;
+ bool *val = 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';
+ if (strtobool(buf, &bv) == 0)
+ *val = bv;
+
+ return count;
+}
+
+static const struct file_operations fops_bool = {
+ .read = debugfs_read_file_bool,
+ .write = debugfs_write_file_bool,
+ .open = simple_open,
+ .llseek = default_llseek,
+};
+
+struct dentry *debugfs_create_bool(const char *name, umode_t mode,
+ struct dentry *parent, bool *value)
+{
+ return debugfs_create_file(name, mode, parent, value, &fops_bool);
+}
+EXPORT_SYMBOL_GPL(debugfs_create_bool);
+#endif /* CONFIG_DEBUG_FS */
--
2.6.2
--
To unsubscribe from this list: send the line "unsubscribe backports" in
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] backport: backport debugfs_create_bool()
2015-11-06 8:04 [PATCH v2] backport: backport debugfs_create_bool() Johannes Berg
@ 2015-11-07 17:07 ` Hauke Mehrtens
0 siblings, 0 replies; 2+ messages in thread
From: Hauke Mehrtens @ 2015-11-07 17:07 UTC (permalink / raw)
To: Johannes Berg, backports; +Cc: Johannes Berg
On 11/06/2015 09:04 AM, Johannes Berg wrote:
> From: Johannes Berg <johannes.berg@intel.com>
>
> The prototype for this function is changing upstream, so backport
> a copy of the new one that has a bool * argument instead of u32 *.
>
> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
> ---
> backport/backport-include/linux/debugfs.h | 15 ++++++++
> backport/compat/Makefile | 1 +
> backport/compat/backport-4.4.c | 64 +++++++++++++++++++++++++++++++
> 3 files changed, 80 insertions(+)
> create mode 100644 backport/compat/backport-4.4.c
>
Thank you for the patch, it was applied.
Hauke
--
To unsubscribe from this list: send the line "unsubscribe backports" in
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-11-07 17:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-06 8:04 [PATCH v2] backport: backport debugfs_create_bool() Johannes Berg
2015-11-07 17:07 ` Hauke Mehrtens
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.