From: Brian Russell <brian.russell@brocade.com>
To: "Hans J. Koch" <hjk@hansjkoch.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: <linux-kernel@vger.kernel.org>
Subject: [PATCH] uio: Fix uio driver to refcount device
Date: Wed, 11 Mar 2015 15:31:42 +0000 [thread overview]
Message-ID: <55005FDE.20602@brocade.com> (raw)
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
next reply other threads:[~2015-03-11 15:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-11 15:31 Brian Russell [this message]
2015-03-11 15:43 ` [PATCH] uio: Fix uio driver to refcount device Greg Kroah-Hartman
2015-03-11 15:59 ` Brian Russell
2015-03-11 16:02 ` Greg Kroah-Hartman
2015-03-11 16:15 ` Brian Russell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=55005FDE.20602@brocade.com \
--to=brian.russell@brocade.com \
--cc=gregkh@linuxfoundation.org \
--cc=hjk@hansjkoch.de \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox