Skip to contentSkip to conversation

crypto: initialize error variable

PATCH In review [email protected] 2 participants 2 messages Aug 16, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: initialize error variable

From: Tom Rix <[email protected]>

Static analysis reports this problem
sev-dev.c:1094:19: warning: The left operand of '==' is a garbage value

        if (rc && (error == SEV_RET_SECURE_DATA_INVALID)) {
                   ~~~~~ ^

The error variable may not be set by the call to sev_platform_init(). So initialize error to SEV_RET_SUCCESS.

Fixes 1d55fdc85799 ("crypto: ccp - Retry SEV INIT command in case of integrity check failure.")
---
 drivers/crypto/ccp/sev-dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/ccp/sev-dev.c +1 -1
index 2ecb0e1f65d8d..b2b9f0f4daf2d 100644
@@ -1065,7 +1065,7 @@ void sev_pci_init(void)
 {
 	struct sev_device *sev = psp_master->sev_data;
 	struct page *tmr_page;
-	int error, rc;
+	int error = SEV_RET_SUCCESS, rc;
 
 	if (!sev)
 		return;
Signature · 1 line
2.26.3
maintainer
#1 lore raw
Quoted 21 lines · On 8/16/21 2:23 PM, [email protected] wrote:

From: Tom Rix <[email protected]>

Static analysis reports this problem
sev-dev.c:1094:19: warning: The left operand of '==' is a garbage value

        if (rc && (error == SEV_RET_SECURE_DATA_INVALID)) {
                   ~~~~~ ^

The error variable may not be set by the call to sev_platform_init(). So initialize error to SEV_RET_SUCCESS.

Fixes 1d55fdc85799 ("crypto: ccp - Retry SEV INIT command in case of integrity check failure.")
---
 drivers/crypto/ccp/sev-dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/ccp/sev-dev.c +0 -0
index 2ecb0e1f65d8d..b2b9f0f4daf2d 100644

drivers/crypto/ccp/sev-dev.c void sev_pci_init(void) · line 1068

Quoted 5 lines
drivers/crypto/ccp/sev-dev.c +1 -1
@@ -1065,7 +1065,7 @@ void sev_pci_init(void)
 {
 	struct sev_device *sev = psp_master->sev_data;
 	struct page *tmr_page;
-	int error, rc;
+	int error = SEV_RET_SUCCESS, rc;

Looking ahead to recently submitted SEV-SNP patches that will also use the error variable (and will also need to initialize it), lets move the initialization of error to just before the call to sev_platform_init() so it doesn't end up with a possible stale value in the future:

https://lore.kernel.org/lkml/[email protected]/

Thanks,
Tom

Quoted 4 lines
drivers/crypto/ccp/sev-dev.c +0 -0
 	if (!sev)
 		return;