* [PATCH v2 1/1] FS: cifs, remove unneeded NULL tests
@ 2010-11-01 15:08 Jiri Slaby
[not found] ` <1288624135-24170-1-git-send-email-jslaby-AlSwsSmVLrQ@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Jiri Slaby @ 2010-11-01 15:08 UTC (permalink / raw)
To: sfrench
Cc: viro, linux-fsdevel, linux-kernel, jirislaby, linux-cifs,
Jeff Layton, Christoph Hellwig
Stanse found that pSMBFile in cifs_ioctl and file->f_path.dentry in
cifs_user_write are dereferenced prior their test to NULL.
The alternative is not to dereference them before the tests. The patch is
to point out the problem, you have to decide.
While at it we cache the inode in cifs_user_write to a local variable
and use all over the function.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Steve French <sfrench@samba.org>
Cc: linux-cifs@vger.kernel.org
Cc: Jeff Layton <jlayton@redhat.com>
Cc: Christoph Hellwig <hch@infradead.org>
---
fs/cifs/file.c | 25 +++++++++++--------------
fs/cifs/ioctl.c | 4 ----
2 files changed, 11 insertions(+), 18 deletions(-)
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index ae82159..5d06eb3 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -956,6 +956,7 @@ cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset,
ssize_t cifs_user_write(struct file *file, const char __user *write_data,
size_t write_size, loff_t *poffset)
{
+ struct inode *inode = file->f_path.dentry->d_inode;
int rc = 0;
unsigned int bytes_written = 0;
unsigned int total_written;
@@ -963,7 +964,7 @@ ssize_t cifs_user_write(struct file *file, const char __user *write_data,
struct cifsTconInfo *pTcon;
int xid, long_op;
struct cifsFileInfo *open_file;
- struct cifsInodeInfo *cifsi = CIFS_I(file->f_path.dentry->d_inode);
+ struct cifsInodeInfo *cifsi = CIFS_I(inode);
cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
@@ -1029,21 +1030,17 @@ ssize_t cifs_user_write(struct file *file, const char __user *write_data,
cifs_stats_bytes_written(pTcon, total_written);
- /* since the write may have blocked check these pointers again */
- if ((file->f_path.dentry) && (file->f_path.dentry->d_inode)) {
- struct inode *inode = file->f_path.dentry->d_inode;
/* Do not update local mtime - server will set its actual value on write
- * inode->i_ctime = inode->i_mtime =
- * current_fs_time(inode->i_sb);*/
- if (total_written > 0) {
- spin_lock(&inode->i_lock);
- if (*poffset > file->f_path.dentry->d_inode->i_size)
- i_size_write(file->f_path.dentry->d_inode,
- *poffset);
- spin_unlock(&inode->i_lock);
- }
- mark_inode_dirty_sync(file->f_path.dentry->d_inode);
+ * inode->i_ctime = inode->i_mtime =
+ * current_fs_time(inode->i_sb);*/
+ if (total_written > 0) {
+ spin_lock(&inode->i_lock);
+ if (*poffset > inode->i_size)
+ i_size_write(inode, *poffset);
+ spin_unlock(&inode->i_lock);
}
+ mark_inode_dirty_sync(inode);
+
FreeXid(xid);
return total_written;
}
diff --git a/fs/cifs/ioctl.c b/fs/cifs/ioctl.c
index 077bf75..2fa22f2 100644
--- a/fs/cifs/ioctl.c
+++ b/fs/cifs/ioctl.c
@@ -63,8 +63,6 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
#ifdef CONFIG_CIFS_POSIX
case FS_IOC_GETFLAGS:
if (CIFS_UNIX_EXTATTR_CAP & caps) {
- if (pSMBFile == NULL)
- break;
rc = CIFSGetExtAttr(xid, tcon, pSMBFile->netfid,
&ExtAttrBits, &ExtAttrMask);
if (rc == 0)
@@ -80,8 +78,6 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
rc = -EFAULT;
break;
}
- if (pSMBFile == NULL)
- break;
/* rc= CIFSGetExtAttr(xid,tcon,pSMBFile->netfid,
extAttrBits, &ExtAttrMask);*/
}
--
1.7.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2 1/1] FS: cifs, remove unneeded NULL tests
[not found] ` <1288624135-24170-1-git-send-email-jslaby-AlSwsSmVLrQ@public.gmane.org>
@ 2010-11-01 16:23 ` Jeff Layton
2010-11-03 10:00 ` Al Viro
1 sibling, 0 replies; 3+ messages in thread
From: Jeff Layton @ 2010-11-01 16:23 UTC (permalink / raw)
To: Jiri Slaby
Cc: sfrench-eUNUBHrolfbYtjvyW6yDsg,
viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn,
linux-fsdevel-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
jirislaby-Re5JQEeQqe8AvxtiuMwx3w,
linux-cifs-u79uwXL29TY76Z2rM5mHXA, Christoph Hellwig
On Mon, 1 Nov 2010 16:08:55 +0100
Jiri Slaby <jslaby-AlSwsSmVLrQ@public.gmane.org> wrote:
> Stanse found that pSMBFile in cifs_ioctl and file->f_path.dentry in
> cifs_user_write are dereferenced prior their test to NULL.
>
> The alternative is not to dereference them before the tests. The patch is
> to point out the problem, you have to decide.
>
> While at it we cache the inode in cifs_user_write to a local variable
> and use all over the function.
>
> Signed-off-by: Jiri Slaby <jslaby-AlSwsSmVLrQ@public.gmane.org>
> Cc: Steve French <sfrench-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
> Cc: linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> Cc: Jeff Layton <jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> Cc: Christoph Hellwig <hch-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
> ---
> fs/cifs/file.c | 25 +++++++++++--------------
> fs/cifs/ioctl.c | 4 ----
> 2 files changed, 11 insertions(+), 18 deletions(-)
>
Reviewed-by: Jeff Layton <jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2 1/1] FS: cifs, remove unneeded NULL tests
[not found] ` <1288624135-24170-1-git-send-email-jslaby-AlSwsSmVLrQ@public.gmane.org>
2010-11-01 16:23 ` Jeff Layton
@ 2010-11-03 10:00 ` Al Viro
1 sibling, 0 replies; 3+ messages in thread
From: Al Viro @ 2010-11-03 10:00 UTC (permalink / raw)
To: Jiri Slaby
Cc: sfrench-eUNUBHrolfbYtjvyW6yDsg,
linux-fsdevel-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
jirislaby-Re5JQEeQqe8AvxtiuMwx3w,
linux-cifs-u79uwXL29TY76Z2rM5mHXA, Jeff Layton, Christoph Hellwig
On Mon, Nov 01, 2010 at 04:08:55PM +0100, Jiri Slaby wrote:
> Stanse found that pSMBFile in cifs_ioctl and file->f_path.dentry in
> cifs_user_write are dereferenced prior their test to NULL.
file->f_path.dentry is never NULL for an opened file, neither is
file->f_path.dentry->d_inode (which cannot change for the entire
lifetime of dentry, BTW). IOW,
> - /* since the write may have blocked check these pointers again */
> - if ((file->f_path.dentry) && (file->f_path.dentry->d_inode)) {
> - struct inode *inode = file->f_path.dentry->d_inode;
in there had always been junk. So yes, losing these tests is the right
thing to do.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-11-03 10:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-01 15:08 [PATCH v2 1/1] FS: cifs, remove unneeded NULL tests Jiri Slaby
[not found] ` <1288624135-24170-1-git-send-email-jslaby-AlSwsSmVLrQ@public.gmane.org>
2010-11-01 16:23 ` Jeff Layton
2010-11-03 10:00 ` Al Viro
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).