From: Michael Roth <michael.roth@amd.com>
To: <linux-crypto@vger.kernel.org>
Cc: <herbert@gondor.apana.org.au>, <davem@davemloft.net>,
<ackerleytng@google.com>, <thomas.lendacky@amd.com>,
<ashish.kalra@amd.com>, <aik@amd.com>, <seanjc@google.com>
Subject: [PATCH v2 6/9] crypto: ccp: - Rework sev_ioctl_do_pdh_export() to avoid goto usage
Date: Thu, 15 Oct 2026 23:09:34 -0500 [thread overview]
Message-ID: <20261016041109.1778673-7-michael.roth@amd.com> (raw)
In-Reply-To: <20261016041109.1778673-1-michael.roth@amd.com>
In preparation for switching the function to use mutex guard()'s, drop
the goto by relying on an if block instead.
Signed-off-by: Michael Roth <michael.roth@amd.com>
---
drivers/crypto/ccp/sev-dev.c | 49 +++++++++++++++++-------------------
1 file changed, 23 insertions(+), 26 deletions(-)
diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
index bea3c30f00b0..4375c0480e81 100644
--- a/drivers/crypto/ccp/sev-dev.c
+++ b/drivers/crypto/ccp/sev-dev.c
@@ -2451,41 +2451,38 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable)
input_pdh_cert_address = (void __user *)input.pdh_cert_address;
input_cert_chain_address = (void __user *)input.cert_chain_address;
- /* Userspace wants to query the certificate length. */
- if (!input.pdh_cert_address ||
- !input.pdh_cert_len ||
- !input.cert_chain_address ||
- !input.cert_chain_len)
- goto cmd;
-
- /* Allocate a physically contiguous buffer to store the PDH blob. */
- if (input.pdh_cert_len > SEV_FW_BLOB_MAX_SIZE)
- return -EFAULT;
+ /* Otherwise, userspace just wants to query the certificate length. */
+ if (input.pdh_cert_address &&
+ input.pdh_cert_len &&
+ input.cert_chain_address &&
+ input.cert_chain_len) {
+ /* Allocate a physically contiguous buffer to store the PDH blob. */
+ if (input.pdh_cert_len > SEV_FW_BLOB_MAX_SIZE)
+ return -EFAULT;
- /* Allocate a physically contiguous buffer to store the cert chain blob. */
- if (input.cert_chain_len > SEV_FW_BLOB_MAX_SIZE)
- return -EFAULT;
+ /* Allocate a physically contiguous buffer to store the cert chain blob. */
+ if (input.cert_chain_len > SEV_FW_BLOB_MAX_SIZE)
+ return -EFAULT;
- pdh_blob = kzalloc(input.pdh_cert_len, GFP_KERNEL);
- if (!pdh_blob)
- return -ENOMEM;
+ pdh_blob = kzalloc(input.pdh_cert_len, GFP_KERNEL);
+ if (!pdh_blob)
+ return -ENOMEM;
- data.pdh_cert_address = __psp_pa(pdh_blob);
- data.pdh_cert_len = input.pdh_cert_len;
+ data.pdh_cert_address = __psp_pa(pdh_blob);
+ data.pdh_cert_len = input.pdh_cert_len;
- cert_blob = kzalloc(input.cert_chain_len, GFP_KERNEL);
- if (!cert_blob)
- return -ENOMEM;
+ cert_blob = kzalloc(input.cert_chain_len, GFP_KERNEL);
+ if (!cert_blob)
+ return -ENOMEM;
- data.cert_chain_address = __psp_pa(cert_blob);
- data.cert_chain_len = input.cert_chain_len;
+ data.cert_chain_address = __psp_pa(cert_blob);
+ data.cert_chain_len = input.cert_chain_len;
+ }
-cmd:
/* If platform is not in INIT state then transition it to INIT. */
if (sev->sev_plat_status.state != SEV_STATE_INIT) {
- if (!writable) {
+ if (!writable)
return -EPERM;
- }
ret = sev_move_to_init_state(argp, &shutdown_required);
if (ret)
return ret;
--
2.43.0
next prev parent reply other threads:[~2026-10-16 4:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 4:09 [PATCH v2 0/9] crypto: ccp - Make sev_cmd_mutex more granular Michael Roth
2026-10-16 4:09 ` [PATCH v2 1/9] crypto: ccp - Shut down SEV firmware before copying to user Michael Roth
2026-10-16 4:09 ` [PATCH v2 2/9] crypto: ccp - Check SNP initialization state after copying user inputs Michael Roth
2026-10-16 4:09 ` [PATCH v2 3/9] crypto: ccp - Use __free() handlers for sev_ioctl_do_pek_csr() allocations Michael Roth
2026-10-16 4:09 ` [PATCH v2 4/9] crypto: ccp - Use __free() handlers for sev_ioctl_do_pek_import() allocations Michael Roth
2026-10-16 4:09 ` [PATCH v2 5/9] crypto: ccp - Use __free() handlers for sev_ioctl_do_pdh_export() allocations Michael Roth
2026-10-16 4:09 ` Michael Roth [this message]
2026-10-16 4:09 ` [PATCH v2 7/9] crypto: ccp - Make usage of sev_cmd_mutex more granular Michael Roth
2026-10-16 4:09 ` [PATCH v2 8/9] crypto: ccp - Use __free() handlers for __sev_do_snp_platform_status() allocations Michael Roth
2026-10-16 4:09 ` [PATCH v2 9/9] crypto: ccp - Allocate status page outside sev_cmd_mutex in SNP_PLATFORM_STATUS Michael Roth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261016041109.1778673-7-michael.roth@amd.com \
--to=michael.roth@amd.com \
--cc=ackerleytng@google.com \
--cc=aik@amd.com \
--cc=ashish.kalra@amd.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=seanjc@google.com \
--cc=thomas.lendacky@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox