netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benedikt Spranger <b.spranger@linutronix.de>
To: netdev@vger.kernel.org
Cc: Alexander Frank <Alexander.Frank@eberspaecher.com>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Benedikt Spranger <b.spranger@linutronix.de>,
	"Hans J. Koch" <hjk@hansjkoch.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Holger Dengler <dengler@linutronix.de>
Subject: [PATCH 1/7] uio: add module owner to prevent inappropriate module unloading
Date: Tue, 13 Aug 2013 11:08:36 +0200	[thread overview]
Message-ID: <1376384922-8519-3-git-send-email-b.spranger@linutronix.de> (raw)
In-Reply-To: <1376384922-8519-1-git-send-email-b.spranger@linutronix.de>

If an UIO device is created by another driver (MFD for instance) it has to be
ensured that the MFD driver isn't removed while the UIO is still in use.
This patch adds a reference to the parent driver which does module refcounting
in order to avoid an too early removal.

Cc: "Hans J. Koch" <hjk@hansjkoch.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Benedikt Spranger <b.spranger@linutronix.de>
Signed-off-by: Holger Dengler <dengler@linutronix.de>
---
 drivers/uio/uio.c          | 9 +++++++++
 include/linux/uio_driver.h | 2 ++
 2 files changed, 11 insertions(+)

diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index 3b96f18..9a95220 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -444,6 +444,11 @@ static int uio_open(struct inode *inode, struct file *filep)
 		goto out;
 	}
 
+	if (!try_module_get(idev->info->owner)) {
+		ret = -ENODEV;
+		goto err_get_module;
+	}
+
 	listener = kmalloc(sizeof(*listener), GFP_KERNEL);
 	if (!listener) {
 		ret = -ENOMEM;
@@ -465,6 +470,9 @@ err_infoopen:
 	kfree(listener);
 
 err_alloc_listener:
+	module_put(idev->info->owner);
+
+err_get_module:
 	module_put(idev->owner);
 
 out:
@@ -488,6 +496,7 @@ static int uio_release(struct inode *inode, struct file *filep)
 	if (idev->info->release)
 		ret = idev->info->release(idev->info, inode);
 
+	module_put(idev->info->owner);
 	module_put(idev->owner);
 	kfree(listener);
 	return ret;
diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h
index 1ad4724..99f1696 100644
--- a/include/linux/uio_driver.h
+++ b/include/linux/uio_driver.h
@@ -80,6 +80,7 @@ struct uio_device;
  * @open:		open operation for this uio device
  * @release:		release operation for this uio device
  * @irqcontrol:		disable/enable irqs when 0/1 is written to /dev/uioX
+ * @owner:		module which created the uio device incase
  */
 struct uio_info {
 	struct uio_device	*uio_dev;
@@ -95,6 +96,7 @@ struct uio_info {
 	int (*open)(struct uio_info *info, struct inode *inode);
 	int (*release)(struct uio_info *info, struct inode *inode);
 	int (*irqcontrol)(struct uio_info *info, s32 irq_on);
+	struct module			*owner;
 };
 
 extern int __must_check
-- 
1.8.4.rc2

  parent reply	other threads:[~2013-08-13  9:08 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-13  9:08 [PATCH 0/7] add FlexRay support Benedikt Spranger
2013-08-13  9:08 ` Benedikt Spranger
2013-08-13  9:08 ` Benedikt Spranger [this message]
2013-08-13 17:48   ` [PATCH 1/7] uio: add module owner to prevent inappropriate module unloading Greg Kroah-Hartman
2013-08-14  7:19     ` Benedikt Spranger
2013-08-14 16:33       ` Greg Kroah-Hartman
2013-08-15  6:42         ` Benedikt Spranger
2013-08-15  6:59           ` Greg Kroah-Hartman
2013-08-15  7:27             ` Benedikt Spranger
2013-08-15  8:09               ` Greg Kroah-Hartman
2013-08-15  8:18                 ` Sebastian Andrzej Siewior
2013-08-15 15:55                   ` Greg Kroah-Hartman
2013-08-15 16:03                     ` Sebastian Andrzej Siewior
2013-08-15 16:42                       ` Greg Kroah-Hartman
2013-08-15 16:54                         ` Sebastian Andrzej Siewior
2013-08-15 17:13                           ` Greg Kroah-Hartman
2013-08-13  9:08 ` [PATCH 2/7] uio: Allow to create custom UIO attributes Benedikt Spranger
2013-08-13 17:54   ` Greg Kroah-Hartman
2013-08-13  9:08 ` [PATCH 3/7] mfd: core: copy DMA mask and params from parent Benedikt Spranger
2013-08-13 10:03   ` Lee Jones
2013-08-13  9:08 ` [PATCH 4/7] mfd: add MFD based flexcard driver Benedikt Spranger
2013-08-13  9:55   ` Lee Jones
2013-08-14  8:12     ` Benedikt Spranger
2013-08-14  9:45       ` Lee Jones
2013-08-13  9:08 ` [PATCH 5/7] clocksource: Add flexcard support Benedikt Spranger
2013-08-13  9:08 ` [PATCH 6/7] net: add the AF_FLEXRAY protocol Benedikt Spranger
2013-08-18 18:50   ` Oliver Hartkopp
2013-08-13  9:08 ` [PATCH 7/7] net: add a flexray driver Benedikt Spranger

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=1376384922-8519-3-git-send-email-b.spranger@linutronix.de \
    --to=b.spranger@linutronix.de \
    --cc=Alexander.Frank@eberspaecher.com \
    --cc=bigeasy@linutronix.de \
    --cc=dengler@linutronix.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=hjk@hansjkoch.de \
    --cc=netdev@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;
as well as URLs for NNTP newsgroup(s).