linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Harkes <jaharkes@cs.cmu.edu>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Jan Harkes <jaharkes@cs.cmu.edu>,
	linux-fsdevel@vger.kernel.org, Fabian Frederick <fabf@skynet.be>
Subject: [PATCH 22/22] coda: ftoc validity check integration
Date: Fri, 17 May 2019 14:37:00 -0400	[thread overview]
Message-ID: <a2c27663ec4547018c92d71c63b1dff4650b6546.1558117389.git.jaharkes@cs.cmu.edu> (raw)
In-Reply-To: <cover.1558117389.git.jaharkes@cs.cmu.edu>

From: Fabian Frederick <fabf@skynet.be>

This patch moves cfi check in coda_ftoc() instead of repeating
it in the wild.

Module size
   text	   data	    bss	    dec	    hex	filename
  28297	   1040	    700	  30037	   7555	fs/coda/coda.ko.before
  28263	    980	    700	  29943	   74f7	fs/coda/coda.ko.after

Signed-off-by: Fabian Frederick <fabf@skynet.be>
Signed-off-by: Jan Harkes <jaharkes@cs.cmu.edu>
---
 fs/coda/cnode.c     | 10 ++++++++++
 fs/coda/coda_fs_i.h |  3 +--
 fs/coda/dir.c       |  6 ++----
 fs/coda/file.c      | 17 +++++------------
 4 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/fs/coda/cnode.c b/fs/coda/cnode.c
index e2dcf2addf3f..06855f6c7902 100644
--- a/fs/coda/cnode.c
+++ b/fs/coda/cnode.c
@@ -148,6 +148,16 @@ struct inode *coda_fid_to_inode(struct CodaFid *fid, struct super_block *sb)
 	return inode;
 }
 
+struct coda_file_info *coda_ftoc(struct file *file)
+{
+	struct coda_file_info *cfi = file->private_data;
+
+	BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
+
+	return cfi;
+
+}
+
 /* the CONTROL inode is made without asking attributes from Venus */
 struct inode *coda_cnode_makectl(struct super_block *sb)
 {
diff --git a/fs/coda/coda_fs_i.h b/fs/coda/coda_fs_i.h
index d702ba1a2bf9..c99d574d1c43 100644
--- a/fs/coda/coda_fs_i.h
+++ b/fs/coda/coda_fs_i.h
@@ -42,8 +42,6 @@ struct coda_file_info {
 	unsigned int	   cfi_mapcount;  /* nr of times this file is mapped */
 };
 
-#define CODA_FTOC(file) ((struct coda_file_info *)((file)->private_data))
-
 /* flags */
 #define C_VATTR       0x1   /* Validity of vattr in inode */
 #define C_FLUSH       0x2   /* used after a flush */
@@ -54,6 +52,7 @@ struct inode *coda_cnode_make(struct CodaFid *, struct super_block *);
 struct inode *coda_iget(struct super_block *sb, struct CodaFid *fid, struct coda_vattr *attr);
 struct inode *coda_cnode_makectl(struct super_block *sb);
 struct inode *coda_fid_to_inode(struct CodaFid *fid, struct super_block *sb);
+struct coda_file_info *coda_ftoc(struct file *file);
 void coda_replace_fid(struct inode *, struct CodaFid *, struct CodaFid *);
 
 #endif
diff --git a/fs/coda/dir.c b/fs/coda/dir.c
index 716a0b932ec0..ca40c2556ba6 100644
--- a/fs/coda/dir.c
+++ b/fs/coda/dir.c
@@ -356,8 +356,7 @@ static int coda_venus_readdir(struct file *coda_file, struct dir_context *ctx)
 	ino_t ino;
 	int ret;
 
-	cfi = CODA_FTOC(coda_file);
-	BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
+	cfi = coda_ftoc(coda_file);
 	host_file = cfi->cfi_container;
 
 	cii = ITOC(file_inode(coda_file));
@@ -426,8 +425,7 @@ static int coda_readdir(struct file *coda_file, struct dir_context *ctx)
 	struct file *host_file;
 	int ret;
 
-	cfi = CODA_FTOC(coda_file);
-	BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
+	cfi = coda_ftoc(coda_file);
 	host_file = cfi->cfi_container;
 
 	if (host_file->f_op->iterate || host_file->f_op->iterate_shared) {
diff --git a/fs/coda/file.c b/fs/coda/file.c
index a6b32c883a50..0dbd13ab72e3 100644
--- a/fs/coda/file.c
+++ b/fs/coda/file.c
@@ -37,9 +37,7 @@ static ssize_t
 coda_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
 {
 	struct file *coda_file = iocb->ki_filp;
-	struct coda_file_info *cfi = CODA_FTOC(coda_file);
-
-	BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
+	struct coda_file_info *cfi = coda_ftoc(coda_file);
 
 	return vfs_iter_read(cfi->cfi_container, to, &iocb->ki_pos, 0);
 }
@@ -49,12 +47,10 @@ coda_file_write_iter(struct kiocb *iocb, struct iov_iter *to)
 {
 	struct file *coda_file = iocb->ki_filp;
 	struct inode *coda_inode = file_inode(coda_file);
-	struct coda_file_info *cfi = CODA_FTOC(coda_file);
+	struct coda_file_info *cfi = coda_ftoc(coda_file);
 	struct file *host_file;
 	ssize_t ret;
 
-	BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
-
 	host_file = cfi->cfi_container;
 	file_start_write(host_file);
 	inode_lock(coda_inode);
@@ -105,8 +101,7 @@ coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma)
 	struct coda_vm_ops *cvm_ops;
 	int ret;
 
-	cfi = CODA_FTOC(coda_file);
-	BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
+	cfi = coda_ftoc(coda_file);
 	host_file = cfi->cfi_container;
 
 	if (!host_file->f_op->mmap)
@@ -208,8 +203,7 @@ int coda_release(struct inode *coda_inode, struct file *coda_file)
 	struct inode *host_inode;
 	int err;
 
-	cfi = CODA_FTOC(coda_file);
-	BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
+	cfi = coda_ftoc(coda_file);
 
 	err = venus_close(coda_inode->i_sb, coda_i2f(coda_inode),
 			  coda_flags, coda_file->f_cred->fsuid);
@@ -251,8 +245,7 @@ int coda_fsync(struct file *coda_file, loff_t start, loff_t end, int datasync)
 		return err;
 	inode_lock(coda_inode);
 
-	cfi = CODA_FTOC(coda_file);
-	BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
+	cfi = coda_ftoc(coda_file);
 	host_file = cfi->cfi_container;
 
 	err = vfs_fsync(host_file, datasync);
-- 
2.20.1


  parent reply	other threads:[~2019-05-17 18:37 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-17 18:36 [PATCH 00/22] Coda updates Jan Harkes
2019-05-17 18:36 ` [PATCH 01/22] coda: pass the host file in vma->vm_file on mmap Jan Harkes
     [not found]   ` <20190518122241.D867120B7C@mail.kernel.org>
2019-05-18 13:18     ` Jan Harkes
2019-05-17 18:36 ` [PATCH 02/22] uapi linux/coda.h: use __kernel_pid_t for userspace Jan Harkes
2019-05-17 18:36 ` [PATCH 03/22] uapi linux/coda_psdev.h: move upc_req definition from uapi to kernel side headers Jan Harkes
2019-05-17 18:36 ` [PATCH 04/22] coda: add error handling for fget Jan Harkes
2019-05-17 18:36 ` [PATCH 05/22] coda: potential buffer overflow in coda_psdev_write() Jan Harkes
2019-05-17 18:36 ` [PATCH 06/22] coda: Fix build using bare-metal toolchain Jan Harkes
2019-05-17 18:36 ` [PATCH 07/22] coda: don't try to print names that were considered too long Jan Harkes
2019-05-17 18:36 ` [PATCH 08/22] uapi linux/coda_psdev.h: Move CODA_REQ_ from uapi to kernel side headers Jan Harkes
2019-05-17 18:36 ` [PATCH 09/22] coda: clean up indentation, replace spaces with tab Jan Harkes
2019-05-17 18:36 ` [PATCH 10/22] coda: stop using 'struct timespec' in user API Jan Harkes
2019-05-17 18:36 ` [PATCH 11/22] coda: change Coda's user api to use 64-bit time_t in timespec Jan Harkes
2019-05-17 18:36 ` [PATCH 12/22] coda: get rid of CODA_ALLOC() Jan Harkes
2019-05-17 18:36 ` [PATCH 13/22] coda: get rid of CODA_FREE() Jan Harkes
2019-05-17 18:36 ` [PATCH 14/22] coda: bump module version Jan Harkes
2019-05-17 18:36 ` [PATCH 15/22] coda: Move internal defs out of include/linux/ [ver #2] Jan Harkes
2019-05-17 18:36 ` [PATCH 16/22] coda: remove uapi/linux/coda_psdev.h Jan Harkes
2019-05-17 23:29   ` Andrew Morton
2019-05-17 23:49     ` Andrew Morton
2019-05-17 23:51     ` Jan Harkes
2019-05-17 18:36 ` [PATCH 17/22] coda: destroy mutex in put_super() Jan Harkes
2019-05-17 18:36 ` [PATCH 18/22] coda: use SIZE() for stat Jan Harkes
2019-05-17 18:36 ` [PATCH 19/22] coda: add __init to init_coda_psdev() Jan Harkes
2019-05-17 18:36 ` [PATCH 20/22] coda: remove sysctl object from module when unused Jan Harkes
2019-05-17 18:36 ` [PATCH 21/22] coda: remove sb test in coda_fid_to_inode() Jan Harkes
2019-05-17 18:37 ` Jan Harkes [this message]
  -- strict thread matches above, loose matches on Subject: below --
2019-03-20 16:45 [PATCH 00/22] Coda updates for linux-5.1 Jan Harkes
2019-03-20 16:45 ` [PATCH 22/22] coda: ftoc validity check integration Jan Harkes

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=a2c27663ec4547018c92d71c63b1dff4650b6546.1558117389.git.jaharkes@cs.cmu.edu \
    --to=jaharkes@cs.cmu.edu \
    --cc=akpm@linux-foundation.org \
    --cc=fabf@skynet.be \
    --cc=linux-fsdevel@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).