From patchwork Wed Oct 27 21:22:53 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 286682 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o9RLN8M9020842 for ; Wed, 27 Oct 2010 21:23:08 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757296Ab0J0VXH (ORCPT ); Wed, 27 Oct 2010 17:23:07 -0400 Received: from mail-ey0-f174.google.com ([209.85.215.174]:60779 "EHLO mail-ey0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757269Ab0J0VXF (ORCPT ); Wed, 27 Oct 2010 17:23:05 -0400 Received: by eye27 with SMTP id 27so1139251eye.19 for ; Wed, 27 Oct 2010 14:23:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:mime-version:content-type:content-disposition:user-agent; bh=eB+Um+Sjwiy6NLKaCJ/YKaGXPBoMNtQGfJsHhYiNcT8=; b=BxSnFsf/r5pdlCkSyq+zvuE+iZqcOEmgcDuq0R3H9t3qtnyTxSZdL+RVjpf3k/0WWN YrI21IXXyCkusdkEjB8QwhBRlef1G2O1v2TpT87Jjx2aPwTcTADuc3TMgT7Hl6P2uBlC Q1QIa43/zcvP8hjb/oPMPjde8Imt+y98V6qq4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; b=FrAWUOvwlNmahuRm7cbWwuCKtAJbsPo/WVq7WpsCfOPT3zcDN8r57HfLMw/neqDnUe eAT5+suvKPSF0G/th1MSb/xpT/Fo5IKZ42FWruUejyEHJUxAJ6GB2QmmrEknP1RxpiZG uuGOuoygKwSWRwV/JSgHkSCPElF2XFG6SqYxs= Received: by 10.216.240.198 with SMTP id e48mr1452735wer.0.1288214583878; Wed, 27 Oct 2010 14:23:03 -0700 (PDT) Received: from bicker (h2df2.n1.ips.mtn.co.ug [41.210.173.242]) by mx.google.com with ESMTPS id p4sm185392wej.4.2010.10.27.14.23.00 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 27 Oct 2010 14:23:03 -0700 (PDT) Date: Wed, 27 Oct 2010 23:22:53 +0200 From: Dan Carpenter To: Steve French Cc: linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, kernel-janitors@vger.kernel.org Subject: [patch 2/2] cifs: dereferencing first then checking Message-ID: <20101027212253.GL6062@bicker> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Wed, 27 Oct 2010 21:23:08 +0000 (UTC) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 06a006b..33a19b4 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -775,13 +775,13 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock) cFYI(1, "Unknown type of lock"); cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); - tcon = tlink_tcon(((struct cifsFileInfo *)file->private_data)->tlink); if (file->private_data == NULL) { rc = -EBADF; FreeXid(xid); return rc; } + tcon = tlink_tcon(((struct cifsFileInfo *)file->private_data)->tlink); netfid = ((struct cifsFileInfo *)file->private_data)->netfid; if ((tcon->ses->capabilities & CAP_UNIX) && @@ -1179,7 +1179,7 @@ struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *cifs_inode, bool fsuid_only) { struct cifsFileInfo *open_file; - struct cifs_sb_info *cifs_sb = CIFS_SB(cifs_inode->vfs_inode.i_sb); + struct cifs_sb_info *cifs_sb; bool any_available = false; int rc; @@ -1192,6 +1192,7 @@ struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *cifs_inode, dump_stack(); return NULL; } + cifs_sb = CIFS_SB(cifs_inode->vfs_inode.i_sb); /* only filter by fsuid on multiuser mounts */ if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)) @@ -1628,15 +1629,26 @@ int cifs_fsync(struct file *file, int datasync) file->f_path.dentry->d_name.name, datasync); rc = filemap_write_and_wait(inode->i_mapping); - if (rc == 0) { - rc = CIFS_I(inode)->write_behind_rc; - CIFS_I(inode)->write_behind_rc = 0; - tcon = tlink_tcon(smbfile->tlink); - if (!rc && tcon && smbfile && - !(CIFS_SB(inode->i_sb)->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)) - rc = CIFSSMBFlush(xid, tcon, smbfile->netfid); - } + if (rc) + goto err_out; + + rc = CIFS_I(inode)->write_behind_rc; + CIFS_I(inode)->write_behind_rc = 0; + if (rc) + goto err_out; + + if (CIFS_SB(inode->i_sb)->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC) + goto done; + if (!smbfile) + goto done; + tcon = tlink_tcon(smbfile->tlink); + if (!tcon) + goto done; + + rc = CIFSSMBFlush(xid, tcon, smbfile->netfid); +err_out: +done: FreeXid(xid); return rc; }