@@ -727,17 +727,16 @@ static int mq_attr_ok(struct ipc_namespace *ipc_ns, struct mq_attr *attr)
727727/*
728728 * Invoked when creating a new queue via sys_mq_open
729729 */
730- static struct file * do_create (struct ipc_namespace * ipc_ns , struct inode * dir ,
730+ static int do_create (struct ipc_namespace * ipc_ns , struct inode * dir ,
731731 struct path * path , int oflag , umode_t mode ,
732732 struct mq_attr * attr )
733733{
734- const struct cred * cred = current_cred ();
735734 int ret ;
736735
737736 if (attr ) {
738737 ret = mq_attr_ok (ipc_ns , attr );
739738 if (ret )
740- return ERR_PTR ( ret ) ;
739+ return ret ;
741740 } else {
742741 struct mq_attr def_attr ;
743742
@@ -747,28 +746,23 @@ static struct file *do_create(struct ipc_namespace *ipc_ns, struct inode *dir,
747746 ipc_ns -> mq_msgsize_default );
748747 ret = mq_attr_ok (ipc_ns , & def_attr );
749748 if (ret )
750- return ERR_PTR ( ret ) ;
749+ return ret ;
751750 }
752751
753- ret = vfs_mkobj (path -> dentry , mode & ~current_umask (),
752+ return vfs_mkobj (path -> dentry , mode & ~current_umask (),
754753 mqueue_create_attr , attr );
755- if (ret )
756- return ERR_PTR (ret );
757- return dentry_open (path , oflag , cred );
758754}
759755
760756/* Opens existing queue */
761- static struct file * do_open (struct path * path , int oflag )
757+ static int do_open (struct path * path , int oflag )
762758{
763759 static const int oflag2acc [O_ACCMODE ] = { MAY_READ , MAY_WRITE ,
764760 MAY_READ | MAY_WRITE };
765761 int acc ;
766762 if ((oflag & O_ACCMODE ) == (O_RDWR | O_WRONLY ))
767- return ERR_PTR ( - EINVAL ) ;
763+ return - EINVAL ;
768764 acc = oflag2acc [oflag & O_ACCMODE ];
769- if (inode_permission (d_inode (path -> dentry ), acc ))
770- return ERR_PTR (- EACCES );
771- return dentry_open (path , oflag , current_cred ());
765+ return inode_permission (d_inode (path -> dentry ), acc );
772766}
773767
774768static int do_mq_open (const char __user * u_name , int oflag , umode_t mode ,
@@ -805,28 +799,30 @@ static int do_mq_open(const char __user *u_name, int oflag, umode_t mode,
805799 if (oflag & O_CREAT ) {
806800 if (d_really_is_positive (path .dentry )) { /* entry already exists */
807801 audit_inode (name , path .dentry , 0 );
808- if (oflag & O_EXCL ) {
802+ if (oflag & O_EXCL )
809803 error = - EEXIST ;
810- goto out ;
811- }
812- filp = do_open (& path , oflag );
804+ else
805+ error = do_open (& path , oflag );
813806 } else {
814807 if (ro ) {
815808 error = ro ;
816- goto out ;
809+ } else {
810+ audit_inode_parent_hidden (name , root );
811+ error = do_create (ipc_ns , d_inode (root ), & path ,
812+ oflag , mode , attr );
817813 }
818- audit_inode_parent_hidden (name , root );
819- filp = do_create (ipc_ns , d_inode (root ), & path ,
820- oflag , mode , attr );
821814 }
822815 } else {
823816 if (d_really_is_negative (path .dentry )) {
824817 error = - ENOENT ;
825- goto out ;
818+ } else {
819+ audit_inode (name , path .dentry , 0 );
820+ error = do_open (& path , oflag );
826821 }
827- audit_inode (name , path .dentry , 0 );
828- filp = do_open (& path , oflag );
829822 }
823+ if (error )
824+ goto out ;
825+ filp = dentry_open (& path , oflag , current_cred ());
830826
831827 if (!IS_ERR (filp ))
832828 fd_install (fd , filp );
0 commit comments