[PATCH v4 6/7] char: misc: Leverage revocable fops replacement

Tzung-Bi Shih posted 7 patches 1 week, 1 day ago
[PATCH v4 6/7] char: misc: Leverage revocable fops replacement
Posted by Tzung-Bi Shih 1 week, 1 day ago
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
PoC patch.

v4:
- New in the series.

 drivers/char/misc.c        | 7 +++++++
 include/linux/miscdevice.h | 3 +++
 2 files changed, 10 insertions(+)

diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 726516fb0a3b..fcbbb0b1af35 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -159,6 +159,13 @@ static int misc_open(struct inode *inode, struct file *file)
 
 	err = 0;
 	replace_fops(file, new_fops);
+
+	if (c->rp && c->rops) {
+		err = revocable_replace_fops(file, c->rp, c->rops);
+		if (err)
+			goto fail;
+	}
+
 	if (file->f_op->open)
 		err = file->f_op->open(inode, file);
 fail:
diff --git a/include/linux/miscdevice.h b/include/linux/miscdevice.h
index 7d0aa718499c..00f5c878266a 100644
--- a/include/linux/miscdevice.h
+++ b/include/linux/miscdevice.h
@@ -5,6 +5,7 @@
 #include <linux/list.h>
 #include <linux/types.h>
 #include <linux/device.h>
+#include <linux/revocable.h>
 
 /*
  *	These allocations are managed by device@lanana.org. If you need
@@ -92,6 +93,8 @@ struct miscdevice {
 	const struct attribute_group **groups;
 	const char *nodename;
 	umode_t mode;
+	struct revocable_provider *rp;
+	const struct revocable_operations *rops;
 };
 
 extern int misc_register(struct miscdevice *misc);
-- 
2.51.0.534.gc79095c0ca-goog