@@ -32,10 +32,6 @@ int ovl_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
3232 if (err )
3333 return err ;
3434
35- err = ovl_want_write (dentry );
36- if (err )
37- goto out ;
38-
3935 if (attr -> ia_valid & ATTR_SIZE ) {
4036 /* Truncate should trigger data copy up as well */
4137 full_copy_up = true;
@@ -54,7 +50,7 @@ int ovl_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
5450 winode = d_inode (upperdentry );
5551 err = get_write_access (winode );
5652 if (err )
57- goto out_drop_write ;
53+ goto out ;
5854 }
5955
6056 if (attr -> ia_valid & (ATTR_KILL_SUID |ATTR_KILL_SGID ))
@@ -78,19 +74,23 @@ int ovl_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
7874 */
7975 attr -> ia_valid &= ~ATTR_OPEN ;
8076
77+ err = ovl_want_write (dentry );
78+ if (err )
79+ goto out_put_write ;
80+
8181 inode_lock (upperdentry -> d_inode );
8282 old_cred = ovl_override_creds (dentry -> d_sb );
8383 err = ovl_do_notify_change (ofs , upperdentry , attr );
8484 revert_creds (old_cred );
8585 if (!err )
8686 ovl_copyattr (dentry -> d_inode );
8787 inode_unlock (upperdentry -> d_inode );
88+ ovl_drop_write (dentry );
8889
90+ out_put_write :
8991 if (winode )
9092 put_write_access (winode );
9193 }
92- out_drop_write :
93- ovl_drop_write (dentry );
9494out :
9595 return err ;
9696}
@@ -361,27 +361,27 @@ int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name,
361361 struct path realpath ;
362362 const struct cred * old_cred ;
363363
364- err = ovl_want_write (dentry );
365- if (err )
366- goto out ;
367-
368364 if (!value && !upperdentry ) {
369365 ovl_path_lower (dentry , & realpath );
370366 old_cred = ovl_override_creds (dentry -> d_sb );
371367 err = vfs_getxattr (mnt_idmap (realpath .mnt ), realdentry , name , NULL , 0 );
372368 revert_creds (old_cred );
373369 if (err < 0 )
374- goto out_drop_write ;
370+ goto out ;
375371 }
376372
377373 if (!upperdentry ) {
378374 err = ovl_copy_up (dentry );
379375 if (err )
380- goto out_drop_write ;
376+ goto out ;
381377
382378 realdentry = ovl_dentry_upper (dentry );
383379 }
384380
381+ err = ovl_want_write (dentry );
382+ if (err )
383+ goto out ;
384+
385385 old_cred = ovl_override_creds (dentry -> d_sb );
386386 if (value ) {
387387 err = ovl_do_setxattr (ofs , realdentry , name , value , size ,
@@ -391,12 +391,10 @@ int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name,
391391 err = ovl_do_removexattr (ofs , realdentry , name );
392392 }
393393 revert_creds (old_cred );
394+ ovl_drop_write (dentry );
394395
395396 /* copy c/mtime */
396397 ovl_copyattr (inode );
397-
398- out_drop_write :
399- ovl_drop_write (dentry );
400398out :
401399 return err ;
402400}
@@ -611,10 +609,6 @@ static int ovl_set_or_remove_acl(struct dentry *dentry, struct inode *inode,
611609 struct dentry * upperdentry = ovl_dentry_upper (dentry );
612610 struct dentry * realdentry = upperdentry ?: ovl_dentry_lower (dentry );
613611
614- err = ovl_want_write (dentry );
615- if (err )
616- return err ;
617-
618612 /*
619613 * If ACL is to be removed from a lower file, check if it exists in
620614 * the first place before copying it up.
@@ -630,31 +624,34 @@ static int ovl_set_or_remove_acl(struct dentry *dentry, struct inode *inode,
630624 revert_creds (old_cred );
631625 if (IS_ERR (real_acl )) {
632626 err = PTR_ERR (real_acl );
633- goto out_drop_write ;
627+ goto out ;
634628 }
635629 posix_acl_release (real_acl );
636630 }
637631
638632 if (!upperdentry ) {
639633 err = ovl_copy_up (dentry );
640634 if (err )
641- goto out_drop_write ;
635+ goto out ;
642636
643637 realdentry = ovl_dentry_upper (dentry );
644638 }
645639
640+ err = ovl_want_write (dentry );
641+ if (err )
642+ goto out ;
643+
646644 old_cred = ovl_override_creds (dentry -> d_sb );
647645 if (acl )
648646 err = ovl_do_set_acl (ofs , realdentry , acl_name , acl );
649647 else
650648 err = ovl_do_remove_acl (ofs , realdentry , acl_name );
651649 revert_creds (old_cred );
650+ ovl_drop_write (dentry );
652651
653652 /* copy c/mtime */
654653 ovl_copyattr (inode );
655-
656- out_drop_write :
657- ovl_drop_write (dentry );
654+ out :
658655 return err ;
659656}
660657
@@ -778,14 +775,14 @@ int ovl_fileattr_set(struct mnt_idmap *idmap,
778775 unsigned int flags ;
779776 int err ;
780777
781- err = ovl_want_write (dentry );
782- if (err )
783- goto out ;
784-
785778 err = ovl_copy_up (dentry );
786779 if (!err ) {
787780 ovl_path_real (dentry , & upperpath );
788781
782+ err = ovl_want_write (dentry );
783+ if (err )
784+ goto out ;
785+
789786 old_cred = ovl_override_creds (inode -> i_sb );
790787 /*
791788 * Store immutable/append-only flags in xattr and clear them
@@ -798,6 +795,7 @@ int ovl_fileattr_set(struct mnt_idmap *idmap,
798795 if (!err )
799796 err = ovl_real_fileattr_set (& upperpath , fa );
800797 revert_creds (old_cred );
798+ ovl_drop_write (dentry );
801799
802800 /*
803801 * Merge real inode flags with inode flags read from
@@ -812,7 +810,6 @@ int ovl_fileattr_set(struct mnt_idmap *idmap,
812810 /* Update ctime */
813811 ovl_copyattr (inode );
814812 }
815- ovl_drop_write (dentry );
816813out :
817814 return err ;
818815}
0 commit comments