Skip to content

Commit d2084fd

Browse files
author
Al Viro
committed
SVM-SEV: convert the rest of fget() uses to fdget() in there
Reviewed-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent e73d437 commit d2084fd

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

arch/x86/kvm/svm/sev.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,18 +1767,20 @@ int sev_vm_move_enc_context_from(struct kvm *kvm, unsigned int source_fd)
17671767
{
17681768
struct kvm_sev_info *dst_sev = &to_kvm_svm(kvm)->sev_info;
17691769
struct kvm_sev_info *src_sev, *cg_cleanup_sev;
1770-
struct file *source_kvm_file;
1770+
struct fd f = fdget(source_fd);
17711771
struct kvm *source_kvm;
17721772
bool charged = false;
17731773
int ret;
17741774

1775-
source_kvm_file = fget(source_fd);
1776-
if (!file_is_kvm(source_kvm_file)) {
1775+
if (!f.file)
1776+
return -EBADF;
1777+
1778+
if (!file_is_kvm(f.file)) {
17771779
ret = -EBADF;
17781780
goto out_fput;
17791781
}
17801782

1781-
source_kvm = source_kvm_file->private_data;
1783+
source_kvm = f.file->private_data;
17821784
ret = sev_lock_two_vms(kvm, source_kvm);
17831785
if (ret)
17841786
goto out_fput;
@@ -1828,8 +1830,7 @@ int sev_vm_move_enc_context_from(struct kvm *kvm, unsigned int source_fd)
18281830
out_unlock:
18291831
sev_unlock_two_vms(kvm, source_kvm);
18301832
out_fput:
1831-
if (source_kvm_file)
1832-
fput(source_kvm_file);
1833+
fdput(f);
18331834
return ret;
18341835
}
18351836

@@ -2046,18 +2047,20 @@ int sev_mem_enc_unregister_region(struct kvm *kvm,
20462047

20472048
int sev_vm_copy_enc_context_from(struct kvm *kvm, unsigned int source_fd)
20482049
{
2049-
struct file *source_kvm_file;
2050+
struct fd f = fdget(source_fd);
20502051
struct kvm *source_kvm;
20512052
struct kvm_sev_info *source_sev, *mirror_sev;
20522053
int ret;
20532054

2054-
source_kvm_file = fget(source_fd);
2055-
if (!file_is_kvm(source_kvm_file)) {
2055+
if (!f.file)
2056+
return -EBADF;
2057+
2058+
if (!file_is_kvm(f.file)) {
20562059
ret = -EBADF;
20572060
goto e_source_fput;
20582061
}
20592062

2060-
source_kvm = source_kvm_file->private_data;
2063+
source_kvm = f.file->private_data;
20612064
ret = sev_lock_two_vms(kvm, source_kvm);
20622065
if (ret)
20632066
goto e_source_fput;
@@ -2103,8 +2106,7 @@ int sev_vm_copy_enc_context_from(struct kvm *kvm, unsigned int source_fd)
21032106
e_unlock:
21042107
sev_unlock_two_vms(kvm, source_kvm);
21052108
e_source_fput:
2106-
if (source_kvm_file)
2107-
fput(source_kvm_file);
2109+
fdput(f);
21082110
return ret;
21092111
}
21102112

0 commit comments

Comments
 (0)