Skip to contentSkip to conversation

crypto: ccp: Fix dereferencing uninitialized error pointer

PATCH In review Ashish Kalra 3 participants 5 messages May 28, 2025 – Jun 16, 2025

Subsystems (3)
lore
Share & tools
lore

Ashish Kalra

author maintainer
#0 lore raw

PATCH 1/1 crypto: ccp: Fix dereferencing uninitialized error pointer

From: Ashish Kalra <[email protected]>

Fix below smatch warnings:
drivers/crypto/ccp/sev-dev.c:1312 __sev_platform_init_locked()
error: we previously assumed 'error' could be null

Fixes 9770b428b1a2 ("crypto: ccp - Move dev_info/err messages for SEV/SNP init and shutdown")
---
 drivers/crypto/ccp/sev-dev.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/crypto/ccp/sev-dev.c +5 -3
index 3451bada884e..8fb94c5f006a 100644
@@ -1276,9 +1276,11 @@ static int __sev_platform_init_handle_init_ex_path(struct sev_device *sev)
 
 static int __sev_platform_init_locked(int *error)
 {
-	int rc, psp_ret = SEV_RET_NO_FW_CALL;
+	int rc, psp_ret, dfflush_error;
 	struct sev_device *sev;
 
+	psp_ret = dfflush_error = SEV_RET_NO_FW_CALL;
+
 	if (!psp_master || !psp_master->sev_data)
 		return -ENODEV;
 
@@ -1320,10 +1322,10 @@ static int __sev_platform_init_locked(int *error)
 
 	/* Prepare for first SEV guest launch after INIT */
 	wbinvd_on_all_cpus();
-	rc = __sev_do_cmd_locked(SEV_CMD_DF_FLUSH, NULL, error);
+	rc = __sev_do_cmd_locked(SEV_CMD_DF_FLUSH, NULL, &dfflush_error);
 	if (rc) {
 		dev_err(sev->dev, "SEV: DF_FLUSH failed %#x, rc %d\n",
-			*error, rc);
+			dfflush_error, rc);
 		return rc;
 	}
 
Signature · 1 line
2.34.1
maintainer
#1 lore raw

drivers/crypto/ccp/sev-dev.c static int __sev_platform_init_locked(int *error) · line 1328

Quoted 11 lines · Ashish Kalra
drivers/crypto/ccp/sev-dev.c +2 -2
@@ -1320,10 +1322,10 @@ static int __sev_platform_init_locked(int *error)
 
 	/* Prepare for first SEV guest launch after INIT */
 	wbinvd_on_all_cpus();
-	rc = __sev_do_cmd_locked(SEV_CMD_DF_FLUSH, NULL, error);
+	rc = __sev_do_cmd_locked(SEV_CMD_DF_FLUSH, NULL, &dfflush_error);
 	if (rc) {
 		dev_err(sev->dev, "SEV: DF_FLUSH failed %#x, rc %d\n",
-			*error, rc);
+			dfflush_error, rc);

dfflush_error is never returned to the caller unlike psp_ret, is this intentional?

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
author maintainer
#2 lore raw
Quoted 4 lines · Herbert Xu
Quoted 3 lines · Ashish Kalra
(quoted diff) +0 -0
@@ -1320,10 +1322,10 @@ static int __sev_platform_init_locked(int *error)
 
Quoted 11 lines

drivers/crypto/ccp/sev-dev.c static int __sev_platform_init_locked(int *error) · line 1328

Quoted 8 lines
drivers/crypto/ccp/sev-dev.c +2 -2
 	/* Prepare for first SEV guest launch after INIT */
 	wbinvd_on_all_cpus();
-	rc = __sev_do_cmd_locked(SEV_CMD_DF_FLUSH, NULL, error);
+	rc = __sev_do_cmd_locked(SEV_CMD_DF_FLUSH, NULL, &dfflush_error);
 	if (rc) {
 		dev_err(sev->dev, "SEV: DF_FLUSH failed %#x, rc %d\n",
-			*error, rc);
+			dfflush_error, rc);

dfflush_error is never returned to the caller unlike psp_ret, is this intentional?

Yes, this is intentional.

As this function does SEV_INIT, it needs to return the firmware error (psp_ret) of SEV_INIT back to the caller.

For DF_FLUSH failures, errors are indicated only via the log and for that dfflush_error is used.

Thanks,
Ashish

Quoted 2 lines

Thanks,

maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Ashish Kalra
Quoted 10 lines · Ashish Kalra

From: Ashish Kalra <[email protected]>

Fix below smatch warnings:
drivers/crypto/ccp/sev-dev.c:1312 __sev_platform_init_locked()
error: we previously assumed 'error' could be null

Fixes 9770b428b1a2 ("crypto: ccp - Move dev_info/err messages for SEV/SNP init and shutdown")
Quoted 34 lines
---
 drivers/crypto/ccp/sev-dev.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/crypto/ccp/sev-dev.c +5 -3
index 3451bada884e..8fb94c5f006a 100644
@@ -1276,9 +1276,11 @@ static int __sev_platform_init_handle_init_ex_path(struct sev_device *sev)
 
 static int __sev_platform_init_locked(int *error)
 {
-	int rc, psp_ret = SEV_RET_NO_FW_CALL;
+	int rc, psp_ret, dfflush_error;
 	struct sev_device *sev;
 
+	psp_ret = dfflush_error = SEV_RET_NO_FW_CALL;
+
 	if (!psp_master || !psp_master->sev_data)
 		return -ENODEV;
 
@@ -1320,10 +1322,10 @@ static int __sev_platform_init_locked(int *error)
 
 	/* Prepare for first SEV guest launch after INIT */
 	wbinvd_on_all_cpus();
-	rc = __sev_do_cmd_locked(SEV_CMD_DF_FLUSH, NULL, error);
+	rc = __sev_do_cmd_locked(SEV_CMD_DF_FLUSH, NULL, &dfflush_error);
 	if (rc) {
 		dev_err(sev->dev, "SEV: DF_FLUSH failed %#x, rc %d\n",
-			*error, rc);
+			dfflush_error, rc);
 		return rc;
 	}
 
maintainer
#4 lore raw
In reply to Ashish Kalra
Quoted 6 lines · Ashish Kalra

From: Ashish Kalra <[email protected]>

Fix below smatch warnings:
drivers/crypto/ccp/sev-dev.c:1312 __sev_platform_init_locked()
error: we previously assumed 'error' could be null

Quoted 7 lines
Fixes 9770b428b1a2 ("crypto: ccp - Move dev_info/err messages for SEV/SNP init and shutdown")
---
 drivers/crypto/ccp/sev-dev.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt