Skip to content

Commit 38017d4

Browse files
author
Miklos Szeredi
committed
cachefiles: tmpfile error handling cleanup
Separate the error labels from the success path and use 'ret' to store the error value before jumping to the error label. Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent 19ee534 commit 38017d4

1 file changed

Lines changed: 26 additions & 29 deletions

File tree

fs/cachefiles/namei.c

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -460,31 +460,27 @@ struct file *cachefiles_create_tmpfile(struct cachefiles_object *object)
460460

461461
path.mnt = cache->mnt;
462462
ret = cachefiles_inject_write_error();
463-
if (ret == 0)
463+
if (ret == 0) {
464464
path.dentry = vfs_tmpfile(&init_user_ns, fan, S_IFREG, O_RDWR);
465-
else
466-
path.dentry = ERR_PTR(ret);
467-
if (IS_ERR(path.dentry)) {
468-
trace_cachefiles_vfs_error(object, d_inode(fan), PTR_ERR(path.dentry),
465+
ret = PTR_ERR_OR_ZERO(path.dentry);
466+
}
467+
if (ret) {
468+
trace_cachefiles_vfs_error(object, d_inode(fan), ret,
469469
cachefiles_trace_tmpfile_error);
470-
if (PTR_ERR(path.dentry) == -EIO)
470+
if (ret == -EIO)
471471
cachefiles_io_error_obj(object, "Failed to create tmpfile");
472-
file = ERR_CAST(path.dentry);
473-
goto out;
472+
goto err;
474473
}
475474

476475
trace_cachefiles_tmpfile(object, d_backing_inode(path.dentry));
477476

478-
if (!cachefiles_mark_inode_in_use(object, path.dentry)) {
479-
file = ERR_PTR(-EBUSY);
480-
goto out_dput;
481-
}
477+
ret = -EBUSY;
478+
if (!cachefiles_mark_inode_in_use(object, path.dentry))
479+
goto err_dput;
482480

483481
ret = cachefiles_ondemand_init_object(object);
484-
if (ret < 0) {
485-
file = ERR_PTR(ret);
486-
goto out_unuse;
487-
}
482+
if (ret < 0)
483+
goto err_unuse;
488484

489485
ni_size = object->cookie->object_size;
490486
ni_size = round_up(ni_size, CACHEFILES_DIO_BLOCK_SIZE);
@@ -499,36 +495,37 @@ struct file *cachefiles_create_tmpfile(struct cachefiles_object *object)
499495
trace_cachefiles_vfs_error(
500496
object, d_backing_inode(path.dentry), ret,
501497
cachefiles_trace_trunc_error);
502-
file = ERR_PTR(ret);
503-
goto out_unuse;
498+
goto err_unuse;
504499
}
505500
}
506501

507502
file = open_with_fake_path(&path, O_RDWR | O_LARGEFILE | O_DIRECT,
508503
d_backing_inode(path.dentry), cache->cache_cred);
504+
ret = PTR_ERR(file);
509505
if (IS_ERR(file)) {
510506
trace_cachefiles_vfs_error(object, d_backing_inode(path.dentry),
511-
PTR_ERR(file),
512-
cachefiles_trace_open_error);
513-
goto out_unuse;
507+
ret, cachefiles_trace_open_error);
508+
goto err_unuse;
514509
}
510+
ret = -EINVAL;
515511
if (unlikely(!file->f_op->read_iter) ||
516512
unlikely(!file->f_op->write_iter)) {
517513
fput(file);
518514
pr_notice("Cache does not support read_iter and write_iter\n");
519-
file = ERR_PTR(-EINVAL);
520-
goto out_unuse;
515+
goto err_unuse;
521516
}
522-
523-
goto out_dput;
524-
525-
out_unuse:
526-
cachefiles_do_unmark_inode_in_use(object, path.dentry);
527-
out_dput:
528517
dput(path.dentry);
529518
out:
530519
cachefiles_end_secure(cache, saved_cred);
531520
return file;
521+
522+
err_unuse:
523+
cachefiles_do_unmark_inode_in_use(object, path.dentry);
524+
err_dput:
525+
dput(path.dentry);
526+
err:
527+
file = ERR_PTR(ret);
528+
goto out;
532529
}
533530

534531
/*

0 commit comments

Comments
 (0)