cifs: make cifs_ioctl handle NULL filp->private_data correctly

Commit 13cfb7334e made cifs_ioctl use the tlink attached to the
cifsFileInfo for a filp. This ignores the case of an open directory
however, which in CIFS can have a NULL private_data until a readdir
is done on it.

This patch re-adds the NULL pointer checks that were removed in commit
50ae28f01 and moves the setting of tcon and "caps" variables lower.

Long term, a better fix would be to establish a f_op->open routine for
directories that populates that field at open time, but that requires
some other changes to how readdir calls are handled.

Reported-by: Kjell Rune Skaaraas <kjella79@yahoo.no>
Reviewed-and-Tested-by: Suresh Jayaraman <sjayaraman@suse.de>
Signed-off-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: Steve French <sfrench@us.ibm.com>

authored by Jeff Layton and committed by Steve French 61876395 151f52f0

+10 -2
+10 -2
fs/cifs/ioctl.c
··· 38 struct cifs_sb_info *cifs_sb; 39 #ifdef CONFIG_CIFS_POSIX 40 struct cifsFileInfo *pSMBFile = filep->private_data; 41 - struct cifsTconInfo *tcon = tlink_tcon(pSMBFile->tlink); 42 __u64 ExtAttrBits = 0; 43 __u64 ExtAttrMask = 0; 44 - __u64 caps = le64_to_cpu(tcon->fsUnixInfo.Capability); 45 #endif /* CONFIG_CIFS_POSIX */ 46 47 xid = GetXid(); ··· 62 break; 63 #ifdef CONFIG_CIFS_POSIX 64 case FS_IOC_GETFLAGS: 65 if (CIFS_UNIX_EXTATTR_CAP & caps) { 66 rc = CIFSGetExtAttr(xid, tcon, pSMBFile->netfid, 67 &ExtAttrBits, &ExtAttrMask); ··· 77 break; 78 79 case FS_IOC_SETFLAGS: 80 if (CIFS_UNIX_EXTATTR_CAP & caps) { 81 if (get_user(ExtAttrBits, (int __user *)arg)) { 82 rc = -EFAULT;
··· 38 struct cifs_sb_info *cifs_sb; 39 #ifdef CONFIG_CIFS_POSIX 40 struct cifsFileInfo *pSMBFile = filep->private_data; 41 + struct cifsTconInfo *tcon; 42 __u64 ExtAttrBits = 0; 43 __u64 ExtAttrMask = 0; 44 + __u64 caps; 45 #endif /* CONFIG_CIFS_POSIX */ 46 47 xid = GetXid(); ··· 62 break; 63 #ifdef CONFIG_CIFS_POSIX 64 case FS_IOC_GETFLAGS: 65 + if (pSMBFile == NULL) 66 + break; 67 + tcon = tlink_tcon(pSMBFile->tlink); 68 + caps = le64_to_cpu(tcon->fsUnixInfo.Capability); 69 if (CIFS_UNIX_EXTATTR_CAP & caps) { 70 rc = CIFSGetExtAttr(xid, tcon, pSMBFile->netfid, 71 &ExtAttrBits, &ExtAttrMask); ··· 73 break; 74 75 case FS_IOC_SETFLAGS: 76 + if (pSMBFile == NULL) 77 + break; 78 + tcon = tlink_tcon(pSMBFile->tlink); 79 + caps = le64_to_cpu(tcon->fsUnixInfo.Capability); 80 if (CIFS_UNIX_EXTATTR_CAP & caps) { 81 if (get_user(ExtAttrBits, (int __user *)arg)) { 82 rc = -EFAULT;