lkml.org 
[lkml]   [2015]   [Mar]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH v2] uio: Fix uio driver to refcount device
Protect uio driver from crashing if its owner is hot unplugged while there
are open fds.

Signed-off-by: Brian Russell <brussell@brocade.com>
---
drivers/uio/uio.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index 6276f13..70ce015 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -434,9 +434,11 @@ static int uio_open(struct inode *inode, struct file *filep)
goto out;
}

+ get_device(idev);
+
if (!try_module_get(idev->owner)) {
ret = -ENODEV;
- goto out;
+ goto err_module_get;
}

listener = kmalloc(sizeof(*listener), GFP_KERNEL);
@@ -462,6 +464,9 @@ err_infoopen:
err_alloc_listener:
module_put(idev->owner);

+err_module_get:
+ put_device(idev);
+
out:
return ret;
}
@@ -485,6 +490,7 @@ static int uio_release(struct inode *inode, struct file *filep)

module_put(idev->owner);
kfree(listener);
+ put_device(idev);
return ret;
}

--
2.1.4

\
 
 \ /
  Last update: 2015-03-13 11:21    [W:0.029 / U:4.156 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site