Skip to content

Commit fa4ae42

Browse files
committed
virt/coco/sev-guest: Convert the sw_exit_info_2 checking to a switch-case
snp_issue_guest_request() checks the value returned by the hypervisor in sw_exit_info_2 and returns a different error depending on it. Convert those checks into a switch-case to make it more readable when more error values are going to be checked in the future. No functional changes. Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Tom Lendacky <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d25bae7 commit fa4ae42

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

arch/x86/kernel/sev.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,15 +2210,21 @@ int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, unsigned
22102210
goto e_put;
22112211

22122212
*fw_err = ghcb->save.sw_exit_info_2;
2213-
if (ghcb->save.sw_exit_info_2) {
2213+
switch (*fw_err) {
2214+
case 0:
2215+
break;
2216+
2217+
case SNP_GUEST_REQ_INVALID_LEN:
22142218
/* Number of expected pages are returned in RBX */
2215-
if (exit_code == SVM_VMGEXIT_EXT_GUEST_REQUEST &&
2216-
ghcb->save.sw_exit_info_2 == SNP_GUEST_REQ_INVALID_LEN) {
2219+
if (exit_code == SVM_VMGEXIT_EXT_GUEST_REQUEST) {
22172220
input->data_npages = ghcb_get_rbx(ghcb);
22182221
ret = -ENOSPC;
2219-
} else {
2220-
ret = -EIO;
2222+
break;
22212223
}
2224+
fallthrough;
2225+
default:
2226+
ret = -EIO;
2227+
break;
22222228
}
22232229

22242230
e_put:

0 commit comments

Comments
 (0)