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

Message ID 20171206085039.27164-4-dirk.behme@de.bosch.com
State Changes Requested
Delegated to: Richard Weinberger
Headers show
Series
  • Add flight recorder to MTDRAM
Related show

Commit Message

Dirk Behme Dec. 6, 2017, 8:50 a.m.
From: Manfred Spraul <manfred@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@de.bosch.com>
Cc: Manfred Spraul <manfred@colorfullife.com>
---
 drivers/mtd/devices/mtdram.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

Patch

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,
 };