[PATCH 3/5] mtdram: Allow to enable/disable flight recorder mode at runtime.

Dirk Behme dirk.behme at de.bosch.com
Wed Dec 6 00:50:37 PST 2017


From: Manfred Spraul <manfred at colorfullife.com>

The patch allows to enable/disable the flight recorder mode by
writing to the debugfs file.

Signed-off-by: Manfred Spraul <manfred.spraul at de.bosch.com>
Cc: Manfred Spraul <manfred at colorfullife.com>
---
 drivers/mtd/devices/mtdram.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c
index 1dc0a5ce0f07..a6f5a656eb94 100644
--- a/drivers/mtd/devices/mtdram.c
+++ b/drivers/mtd/devices/mtdram.c
@@ -87,8 +87,45 @@ static ssize_t nandrec_read_file(struct file *file, char __user *user_buf,
 	return r;
 }
 
+static ssize_t nandrec_write_file(struct file *file, const char __user *buf,
+				  size_t count, loff_t *ppos)
+{
+	ssize_t r;
+	char kbuf[8];
+
+	mutex_lock(&fr_mutex);
+
+	*ppos = 0;
+	memset(kbuf, 0, sizeof(kbuf));
+
+	r = debugfs_file_get(fr_dentry);
+	if (likely(!r)) {
+		r = simple_write_to_buffer(kbuf, sizeof(kbuf) - 1,
+					   ppos, buf, count);
+		debugfs_file_put(fr_dentry);
+	}
+
+	if (r > 0) {
+		unsigned long newval;
+		int ret;
+
+		ret = kstrtoul(kbuf, 0, &newval);
+		if (ret == 0)
+			fr_enabled = newval;
+		else
+			r = ret;
+	}
+	if (fr_enabled)
+		pr_info("MTDRAM flight recorder enabled.\n");
+	else
+		pr_info("MTDRAM flight recorder disabled.\n");
+	mutex_unlock(&fr_mutex);
+	return r;
+}
+
 static const struct file_operations fr_fops = {
 	.read =		nandrec_read_file,
+	.write =	nandrec_write_file,
 	.open =		simple_open,
 };
 
-- 
2.14.1




More information about the linux-mtd mailing list