From: "Kirill A. Shutemov" <kirill@shutemov.name>
To: David Woodhouse <dwmw2@infradead.org>
Cc: Jan Kara <jack@suse.cz>, Alexander Viro <viro@zeniv.linux.org.uk>,
David Howells <dhowells@redhat.com>,
Alexander Shishkin <virtuoso@slind.org>,
linux-mtd@lists.infradead.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org,
"Kirill A. Shutemov" <kirill@shutemov.name>
Subject: [PATCH] mtd: Do not corrupt backing device for inode
Date: Wed, 21 Apr 2010 18:21:09 +0300 [thread overview]
Message-ID: <1271863269-5423-1-git-send-email-kirill@shutemov.name> (raw)
In-Reply-To: <20100415172300.GF3561@quack.suse.cz>
We cannot modify file->f_mapping->backing_dev_info directly, because it
will corrupt backing device for inode, since inode->i_mapping ==
file->f_mapping (see __dentry_open() in fs/open.c).
So we have to copy f_mapping first.
Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
---
drivers/mtd/mtdchar.c | 22 +++++++++++++++++++++-
1 files changed, 21 insertions(+), 1 deletions(-)
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 5b081cb..d85be4d 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -88,8 +88,23 @@ static int mtd_open(struct inode *inode, struct file *file)
goto out;
}
- if (mtd->backing_dev_info)
+ if (mtd->backing_dev_info) {
+ /*
+ * We assume that file->f_mapping is equal to inode->i_mapping.
+ */
+ BUG_ON(file->f_mapping != inode->i_mapping);
+
+ /*
+ * We cannot modify file->f_mapping->backing_dev_info directly,
+ * because it will corrupt backing device for inode, since
+ * inode->i_mapping is equal to file->f_mapping. So we have to
+ * copy f_mapping first.
+ */
+ file->f_mapping = kmalloc(sizeof(*file->f_mapping), GFP_KERNEL);
+ memcpy(file->f_mapping, inode->i_mapping,
+ sizeof(*file->f_mapping));
file->f_mapping->backing_dev_info = mtd->backing_dev_info;
+ }
/* You can't open it RW if it's not a writeable device */
if ((file->f_mode & FMODE_WRITE) && !(mtd->flags & MTD_WRITEABLE)) {
@@ -129,6 +144,11 @@ static int mtd_close(struct inode *inode, struct file *file)
file->private_data = NULL;
kfree(mfi);
+ if (mtd->backing_dev_info) {
+ kfree(file->f_mapping);
+ file->f_mapping = inode->i_mapping;
+ }
+
return 0;
} /* mtd_close */
--
1.7.0.4
next prev parent reply other threads:[~2010-04-21 15:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-13 11:33 [BUG] Rewriting backing_dev_info in MTD Kirill A. Shutemov
2010-04-15 17:23 ` Jan Kara
2010-04-21 15:21 ` Kirill A. Shutemov [this message]
2010-04-22 11:08 ` [PATCH] mtd: Do not corrupt backing device for inode David Woodhouse
2010-04-22 15:20 ` Jan Kara
2010-05-03 16:56 ` [PATCH] mtd: Do not corrupt backing device of device node inode Kirill A. Shutemov
2010-05-03 18:54 ` 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=1271863269-5423-1-git-send-email-kirill@shutemov.name \
--to=kirill@shutemov.name \
--cc=dhowells@redhat.com \
--cc=dwmw2@infradead.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=viro@zeniv.linux.org.uk \
--cc=virtuoso@slind.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).