Skip to content

Commit 23a31d8

Browse files
chuckleverbrauner
authored andcommitted
shmem: Refactor shmem_symlink()
De-duplicate the error handling paths. No change in behavior is expected. Suggested-by: Jeff Layton <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Chuck Lever <[email protected]> Message-Id: <168814733654.530310.9958360833543413152.stgit@manet.1015granger.net> Signed-off-by: Christian Brauner <[email protected]>
1 parent 6faddda commit 23a31d8

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

mm/shmem.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3422,26 +3422,22 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir,
34223422

34233423
error = security_inode_init_security(inode, dir, &dentry->d_name,
34243424
shmem_initxattrs, NULL);
3425-
if (error && error != -EOPNOTSUPP) {
3426-
iput(inode);
3427-
return error;
3428-
}
3425+
if (error && error != -EOPNOTSUPP)
3426+
goto out_iput;
34293427

34303428
inode->i_size = len-1;
34313429
if (len <= SHORT_SYMLINK_LEN) {
34323430
inode->i_link = kmemdup(symname, len, GFP_KERNEL);
34333431
if (!inode->i_link) {
3434-
iput(inode);
3435-
return -ENOMEM;
3432+
error = -ENOMEM;
3433+
goto out_iput;
34363434
}
34373435
inode->i_op = &shmem_short_symlink_operations;
34383436
} else {
34393437
inode_nohighmem(inode);
34403438
error = shmem_get_folio(inode, 0, &folio, SGP_WRITE);
3441-
if (error) {
3442-
iput(inode);
3443-
return error;
3444-
}
3439+
if (error)
3440+
goto out_iput;
34453441
inode->i_mapping->a_ops = &shmem_aops;
34463442
inode->i_op = &shmem_symlink_inode_operations;
34473443
memcpy(folio_address(folio), symname, len);
@@ -3456,6 +3452,9 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir,
34563452
d_instantiate(dentry, inode);
34573453
dget(dentry);
34583454
return 0;
3455+
out_iput:
3456+
iput(inode);
3457+
return error;
34593458
}
34603459

34613460
static void shmem_put_link(void *arg)

0 commit comments

Comments
 (0)