tree-wide: fix assorted typos all over the place
[safe/jmp/linux-2.6] / fs / ncpfs / ioctl.c
index 3a97c95..ec8f45f 100644 (file)
@@ -40,10 +40,10 @@ ncp_get_fs_info(struct ncp_server * server, struct file *file,
        struct inode *inode = file->f_path.dentry->d_inode;
        struct ncp_fs_info info;
 
-       if ((file_permission(file, MAY_WRITE) != 0)
-           && (current->uid != server->m.mounted_uid)) {
+       if (file_permission(file, MAY_WRITE) != 0
+           && current_uid() != server->m.mounted_uid)
                return -EACCES;
-       }
+
        if (copy_from_user(&info, arg, sizeof(info)))
                return -EFAULT;
 
@@ -70,10 +70,10 @@ ncp_get_fs_info_v2(struct ncp_server * server, struct file *file,
        struct inode *inode = file->f_path.dentry->d_inode;
        struct ncp_fs_info_v2 info2;
 
-       if ((file_permission(file, MAY_WRITE) != 0)
-           && (current->uid != server->m.mounted_uid)) {
+       if (file_permission(file, MAY_WRITE) != 0
+           && current_uid() != server->m.mounted_uid)
                return -EACCES;
-       }
+
        if (copy_from_user(&info2, arg, sizeof(info2)))
                return -EFAULT;
 
@@ -98,7 +98,7 @@ struct compat_ncp_objectname_ioctl
 {
        s32             auth_type;
        u32             object_name_len;
-       compat_caddr_t  object_name;    /* an userspace data, in most cases user name */
+       compat_caddr_t  object_name;    /* a userspace data, in most cases user name */
 };
 
 struct compat_ncp_fs_info_v2 {
@@ -141,10 +141,10 @@ ncp_get_compat_fs_info_v2(struct ncp_server * server, struct file *file,
        struct inode *inode = file->f_path.dentry->d_inode;
        struct compat_ncp_fs_info_v2 info2;
 
-       if ((file_permission(file, MAY_WRITE) != 0)
-           && (current->uid != server->m.mounted_uid)) {
+       if (file_permission(file, MAY_WRITE) != 0
+           && current_uid() != server->m.mounted_uid)
                return -EACCES;
-       }
+
        if (copy_from_user(&info2, arg, sizeof(info2)))
                return -EFAULT;
 
@@ -223,10 +223,8 @@ ncp_set_charsets(struct ncp_server* server, struct ncp_nls_ioctl __user *arg)
        oldset_io = server->nls_io;
        server->nls_io = iocharset;
 
-       if (oldset_cp)
-               unload_nls(oldset_cp);
-       if (oldset_io)
-               unload_nls(oldset_io);
+       unload_nls(oldset_cp);
+       unload_nls(oldset_io);
 
        return 0;
 }
@@ -270,16 +268,17 @@ static int __ncp_ioctl(struct inode *inode, struct file *filp,
        struct ncp_ioctl_request request;
        char* bouncebuffer;
        void __user *argp = (void __user *)arg;
+       uid_t uid = current_uid();
 
        switch (cmd) {
 #ifdef CONFIG_COMPAT
        case NCP_IOC_NCPREQUEST_32:
 #endif
        case NCP_IOC_NCPREQUEST:
-               if ((file_permission(filp, MAY_WRITE) != 0)
-                   && (current->uid != server->m.mounted_uid)) {
+               if (file_permission(filp, MAY_WRITE) != 0
+                   && uid != server->m.mounted_uid)
                        return -EACCES;
-               }
+
 #ifdef CONFIG_COMPAT
                if (cmd == NCP_IOC_NCPREQUEST_32) {
                        struct compat_ncp_ioctl_request request32;
@@ -356,10 +355,10 @@ static int __ncp_ioctl(struct inode *inode, struct file *filp,
        case NCP_IOC_GETMOUNTUID16:
        case NCP_IOC_GETMOUNTUID32:
        case NCP_IOC_GETMOUNTUID64:
-               if ((file_permission(filp, MAY_READ) != 0)
-                       && (current->uid != server->m.mounted_uid)) {
+               if (file_permission(filp, MAY_READ) != 0
+                       && uid != server->m.mounted_uid)
                        return -EACCES;
-               }
+
                if (cmd == NCP_IOC_GETMOUNTUID16) {
                        u16 uid;
                        SET_UID(uid, server->m.mounted_uid);
@@ -380,11 +379,10 @@ static int __ncp_ioctl(struct inode *inode, struct file *filp,
                {
                        struct ncp_setroot_ioctl sr;
 
-                       if ((file_permission(filp, MAY_READ) != 0)
-                           && (current->uid != server->m.mounted_uid))
-                       {
+                       if (file_permission(filp, MAY_READ) != 0
+                           && uid != server->m.mounted_uid)
                                return -EACCES;
-                       }
+
                        if (server->m.mounted_vol[0]) {
                                struct dentry* dentry = inode->i_sb->s_root;
 
@@ -408,6 +406,7 @@ static int __ncp_ioctl(struct inode *inode, struct file *filp,
                                return -EFAULT;
                        return 0;
                }
+
        case NCP_IOC_SETROOT:
                {
                        struct ncp_setroot_ioctl sr;
@@ -441,7 +440,7 @@ static int __ncp_ioctl(struct inode *inode, struct file *filp,
                        if (dentry) {
                                struct inode* s_inode = dentry->d_inode;
                                
-                               if (inode) {
+                               if (s_inode) {
                                        NCP_FINFO(s_inode)->volNumber = vnum;
                                        NCP_FINFO(s_inode)->dirEntNum = de;
                                        NCP_FINFO(s_inode)->DosDirNum = dosde;
@@ -455,11 +454,10 @@ static int __ncp_ioctl(struct inode *inode, struct file *filp,
 
 #ifdef CONFIG_NCPFS_PACKET_SIGNING     
        case NCP_IOC_SIGN_INIT:
-               if ((file_permission(filp, MAY_WRITE) != 0)
-                   && (current->uid != server->m.mounted_uid))
-               {
+               if (file_permission(filp, MAY_WRITE) != 0
+                   && uid != server->m.mounted_uid)
                        return -EACCES;
-               }
+
                if (argp) {
                        if (server->sign_wanted)
                        {
@@ -478,24 +476,22 @@ static int __ncp_ioctl(struct inode *inode, struct file *filp,
                return 0;               
                
         case NCP_IOC_SIGN_WANTED:
-               if ((file_permission(filp, MAY_READ) != 0)
-                   && (current->uid != server->m.mounted_uid))
-               {
+               if (file_permission(filp, MAY_READ) != 0
+                   && uid != server->m.mounted_uid)
                        return -EACCES;
-               }
                
                 if (put_user(server->sign_wanted, (int __user *)argp))
                        return -EFAULT;
                 return 0;
+
        case NCP_IOC_SET_SIGN_WANTED:
                {
                        int newstate;
 
-                       if ((file_permission(filp, MAY_WRITE) != 0)
-                           && (current->uid != server->m.mounted_uid))
-                       {
+                       if (file_permission(filp, MAY_WRITE) != 0
+                           && uid != server->m.mounted_uid)
                                return -EACCES;
-                       }
+
                        /* get only low 8 bits... */
                        if (get_user(newstate, (unsigned char __user *)argp))
                                return -EFAULT;
@@ -512,11 +508,10 @@ static int __ncp_ioctl(struct inode *inode, struct file *filp,
 
 #ifdef CONFIG_NCPFS_IOCTL_LOCKING
        case NCP_IOC_LOCKUNLOCK:
-               if ((file_permission(filp, MAY_WRITE) != 0)
-                   && (current->uid != server->m.mounted_uid))
-               {
+               if (file_permission(filp, MAY_WRITE) != 0
+                   && uid != server->m.mounted_uid)
                        return -EACCES;
-               }
+
                {
                        struct ncp_lock_ioctl    rqdata;
 
@@ -585,9 +580,8 @@ outrel:
 
 #ifdef CONFIG_COMPAT
        case NCP_IOC_GETOBJECTNAME_32:
-               if (current->uid != server->m.mounted_uid) {
+               if (uid != server->m.mounted_uid)
                        return -EACCES;
-               }
                {
                        struct compat_ncp_objectname_ioctl user;
                        size_t outl;
@@ -609,10 +603,10 @@ outrel:
                        return 0;
                }
 #endif
+
        case NCP_IOC_GETOBJECTNAME:
-               if (current->uid != server->m.mounted_uid) {
+               if (uid != server->m.mounted_uid)
                        return -EACCES;
-               }
                {
                        struct ncp_objectname_ioctl user;
                        size_t outl;
@@ -633,13 +627,13 @@ outrel:
                                return -EFAULT;
                        return 0;
                }
+
 #ifdef CONFIG_COMPAT
        case NCP_IOC_SETOBJECTNAME_32:
 #endif
        case NCP_IOC_SETOBJECTNAME:
-               if (current->uid != server->m.mounted_uid) {
+               if (uid != server->m.mounted_uid)
                        return -EACCES;
-               }
                {
                        struct ncp_objectname_ioctl user;
                        void* newname;
@@ -664,13 +658,10 @@ outrel:
                        if (user.object_name_len > NCP_OBJECT_NAME_MAX_LEN)
                                return -ENOMEM;
                        if (user.object_name_len) {
-                               newname = kmalloc(user.object_name_len, GFP_USER);
-                               if (!newname)
-                                       return -ENOMEM;
-                               if (copy_from_user(newname, user.object_name, user.object_name_len)) {
-                                       kfree(newname);
-                                       return -EFAULT;
-                               }
+                               newname = memdup_user(user.object_name,
+                                                     user.object_name_len);
+                               if (IS_ERR(newname))
+                                       return PTR_ERR(newname);
                        } else {
                                newname = NULL;
                        }
@@ -691,13 +682,13 @@ outrel:
                        kfree(oldname);
                        return 0;
                }
+
 #ifdef CONFIG_COMPAT
        case NCP_IOC_GETPRIVATEDATA_32:
 #endif
        case NCP_IOC_GETPRIVATEDATA:
-               if (current->uid != server->m.mounted_uid) {
+               if (uid != server->m.mounted_uid)
                        return -EACCES;
-               }
                {
                        struct ncp_privatedata_ioctl user;
                        size_t outl;
@@ -736,13 +727,13 @@ outrel:
 
                        return 0;
                }
+
 #ifdef CONFIG_COMPAT
        case NCP_IOC_SETPRIVATEDATA_32:
 #endif
        case NCP_IOC_SETPRIVATEDATA:
-               if (current->uid != server->m.mounted_uid) {
+               if (uid != server->m.mounted_uid)
                        return -EACCES;
-               }
                {
                        struct ncp_privatedata_ioctl user;
                        void* new;
@@ -764,13 +755,9 @@ outrel:
                        if (user.len > NCP_PRIVATE_DATA_MAX_LEN)
                                return -ENOMEM;
                        if (user.len) {
-                               new = kmalloc(user.len, GFP_USER);
-                               if (!new)
-                                       return -ENOMEM;
-                               if (copy_from_user(new, user.data, user.len)) {
-                                       kfree(new);
-                                       return -EFAULT;
-                               }
+                               new = memdup_user(user.data, user.len);
+                               if (IS_ERR(new))
+                                       return PTR_ERR(new);
                        } else {
                                new = NULL;
                        }
@@ -794,9 +781,10 @@ outrel:
 #endif /* CONFIG_NCPFS_NLS */
 
        case NCP_IOC_SETDENTRYTTL:
-               if ((file_permission(filp, MAY_WRITE) != 0) &&
-                                (current->uid != server->m.mounted_uid))
+               if (file_permission(filp, MAY_WRITE) != 0 &&
+                   uid != server->m.mounted_uid)
                        return -EACCES;
+
                {
                        u_int32_t user;
 
@@ -847,7 +835,7 @@ static int ncp_ioctl_need_write(unsigned int cmd)
        case NCP_IOC_SETROOT:
                return 0;
        default:
-               /* unkown IOCTL command, assume write */
+               /* unknown IOCTL command, assume write */
                return 1;
        }
 }