Miscdevice now supports revocable fops replacement.  Use it to secure
the cros_ec_device.

Signed-off-by: Tzung-Bi Shih <[email protected]>
---
PoC patch.

v4:
- New in the series.

 drivers/platform/chrome/cros_ec_chardev.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/chrome/cros_ec_chardev.c 
b/drivers/platform/chrome/cros_ec_chardev.c
index c9d80ad5b57e..cacc73635d6b 100644
--- a/drivers/platform/chrome/cros_ec_chardev.c
+++ b/drivers/platform/chrome/cros_ec_chardev.c
@@ -166,7 +166,6 @@ static int cros_ec_chardev_open(struct inode *inode, struct 
file *filp)
        if (!priv)
                return -ENOMEM;
 
-       priv->ec_dev = ec_dev;
        priv->cmd_offset = ec->cmd_offset;
        filp->private_data = priv;
        INIT_LIST_HEAD(&priv->events);
@@ -370,6 +369,18 @@ static const struct file_operations chardev_fops = {
 #endif
 };
 
+static int cros_ec_chardev_rev_try_access(struct revocable *rev, void *data)
+{
+       struct chardev_priv *priv = data;
+
+       priv->ec_dev = revocable_try_access(rev);
+       return priv->ec_dev ? 0 : -ENODEV;
+}
+
+static const struct revocable_operations cros_ec_chardev_rops = {
+       .try_access = cros_ec_chardev_rev_try_access,
+};
+
 static int cros_ec_chardev_probe(struct platform_device *pdev)
 {
        struct cros_ec_dev *ec = dev_get_drvdata(pdev->dev.parent);
@@ -385,6 +396,8 @@ static int cros_ec_chardev_probe(struct platform_device 
*pdev)
        misc->fops = &chardev_fops;
        misc->name = ec_platform->ec_name;
        misc->parent = pdev->dev.parent;
+       misc->rp = ec->ec_dev->revocable_provider;
+       misc->rops = &cros_ec_chardev_rops;
 
        dev_set_drvdata(&pdev->dev, misc);
 
-- 
2.51.0.534.gc79095c0ca-goog


Reply via email to