linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Al Viro <viro@ZenIV.linux.org.uk>
Cc: hch@lst.de, linux-fsdevel@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>, Jan Kara <jack@suse.cz>
Subject: [PATCH 2/4] chardev: Increment cdev reference count when i_cdev references it
Date: Wed, 22 Oct 2014 22:14:11 +0200	[thread overview]
Message-ID: <1414008853-13200-3-git-send-email-jack@suse.cz> (raw)
In-Reply-To: <1414008853-13200-1-git-send-email-jack@suse.cz>

Currently i_cdev reference to a character device isn't accounted in the
reference count of the character device. This then requires us to track
all references through a list of all inodes referencing a character
device which is somewhat clumsy and requires list_head in each inode in
the system.

So make i_cdev a reference like any other.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/char_dev.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/fs/char_dev.c b/fs/char_dev.c
index f77f7702fabe..21c210dbdba1 100644
--- a/fs/char_dev.c
+++ b/fs/char_dev.c
@@ -388,12 +388,13 @@ static int chrdev_open(struct inode *inode, struct file *filp)
 		   we dropped the lock. */
 		p = inode->i_cdev;
 		if (!p) {
+			/* Use reference from kobj_lookup for i_cdev ref */
 			inode->i_cdev = p = new;
 			list_add(&inode->i_devices, &p->list);
 			new = NULL;
-		} else if (!cdev_get(p))
-			ret = -ENXIO;
-	} else if (!cdev_get(p))
+		}
+	}
+	if (!cdev_get(p))
 		ret = -ENXIO;
 	spin_unlock(&cdev_lock);
 	cdev_put(new);
@@ -421,10 +422,15 @@ static int chrdev_open(struct inode *inode, struct file *filp)
 
 void cd_forget(struct inode *inode)
 {
+	struct cdev *cdev;
+
 	spin_lock(&cdev_lock);
 	list_del_init(&inode->i_devices);
+	cdev = inode->i_cdev;
 	inode->i_cdev = NULL;
 	spin_unlock(&cdev_lock);
+	if (cdev)
+		cdev_put(cdev);
 }
 
 static void cdev_purge(struct cdev *cdev)
-- 
1.8.1.4


  parent reply	other threads:[~2014-10-22 20:14 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-22 20:14 [PATCH 0/4 v2] fs: Remove i_devices from struct inode Jan Kara
2014-10-22 20:14 ` [PATCH 1/4] blockdev: Don't use i_devices inode field Jan Kara
2014-11-04  9:42   ` Christoph Hellwig
2014-10-22 20:14 ` Jan Kara [this message]
2014-11-04  9:52   ` [PATCH 2/4] chardev: Increment cdev reference count when i_cdev references it Christoph Hellwig
2014-11-04 10:01     ` Jan Kara
2014-11-04 14:46   ` Al Viro
2014-11-04 15:37     ` Jan Kara
2014-11-04 15:40       ` Al Viro
2014-11-04 15:55         ` Jan Kara
2014-11-04 16:03           ` Al Viro
2014-11-05 16:54             ` Jan Kara
2014-10-22 20:14 ` [PATCH 3/4] chardev: Don't use i_devices inode field Jan Kara
2014-11-04  9:54   ` Christoph Hellwig
2014-10-22 20:14 ` [PATCH 4/4] fs: Remove i_devices list head Jan Kara
2014-11-04  9:55   ` Christoph Hellwig
2014-10-31  9:48 ` [PATCH 0/4 v2] fs: Remove i_devices from struct inode Jan Kara
2014-11-04 10:27 [PATCH 0/4 v3] " Jan Kara
2014-11-04 10:27 ` [PATCH 2/4] chardev: Increment cdev reference count when i_cdev references it Jan Kara

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=1414008853-13200-3-git-send-email-jack@suse.cz \
    --to=jack@suse.cz \
    --cc=hch@lst.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@ZenIV.linux.org.uk \
    /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).