Skip to contentSkip to conversation

crypto: ccp: initialize 'error' variable to zero

PATCH In review Tom Rix 4 participants 4 messages Jan 10, 2023 – Jan 20, 2023

Subsystems (3)
lore
Share & tools
lore

Tom Rix

author
#0 lore raw

PATCH v3 1/1 crypto: ccp: initialize 'error' variable to zero

Clang static analysis reports this problem drivers/crypto/ccp/sev-dev.c:1347:3: warning: 3rd function call
argument is an uninitialized value [core.CallAndMessage]

    dev_err(sev->dev, "SEV: failed to INIT error %#x, rc %d\n",
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

__sev_platform_init_locked() can return without setting the error parameter, causing the dev_err() to report a garbage value.

Fixes 200664d5237f ("crypto: ccp: Add Secure Encrypted Virtualization (SEV) command support")

---
v2 cleanup commit log
v3 cleanup commit log

---
 drivers/crypto/ccp/sev-dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/ccp/sev-dev.c +1 -1
index 56998bc579d6..643cccc06a0b 100644
@@ -1307,7 +1307,7 @@ EXPORT_SYMBOL_GPL(sev_issue_cmd_external_user);
 void sev_pci_init(void)
 {
 	struct sev_device *sev = psp_master->sev_data;
-	int error, rc;
+	int error = 0, rc;
 
 	if (!sev)
 		return;
Signature · 1 line
2.27.0
Reviewed-by on v3 1/1
#1 lore raw
Quoted 7 lines · Tom Rix

Clang static analysis reports this problem drivers/crypto/ccp/sev-dev.c:1347:3: warning: 3rd function call
argument is an uninitialized value [core.CallAndMessage]

    dev_err(sev->dev, "SEV: failed to INIT error %#x, rc %d\n",
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 6 lines

__sev_platform_init_locked() can return without setting the error parameter, causing the dev_err() to report a garbage value.

Fixes 200664d5237f ("crypto: ccp: Add Secure Encrypted Virtualization (SEV) command support")

Thanks for the patch!

Quoted 24 lines

---
v2 cleanup commit log
v3 cleanup commit log

---
 drivers/crypto/ccp/sev-dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/ccp/sev-dev.c +1 -2
index 56998bc579d6..643cccc06a0b 100644
@@ -1307,7 +1307,7 @@ EXPORT_SYMBOL_GPL(sev_issue_cmd_external_user);
 void sev_pci_init(void)
 {
        struct sev_device *sev = psp_master->sev_data;
-       int error, rc;
+       int error = 0, rc;
 
        if (!sev)
                return;
--

2.27.0

Signature · 2 lines
Thanks,
~Nick Desaulniers
maintainer Acked-by on v3 1/1
#2 lore raw
In reply to Tom Rix
Quoted 6 lines · Tom Rix

Clang static analysis reports this problem drivers/crypto/ccp/sev-dev.c:1347:3: warning: 3rd function call
argument is an uninitialized value [core.CallAndMessage]

     dev_err(sev->dev, "SEV: failed to INIT error %#x, rc %d\n",
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 6 lines

__sev_platform_init_locked() can return without setting the error parameter, causing the dev_err() to report a garbage value.

Fixes 200664d5237f ("crypto: ccp: Add Secure Encrypted Virtualization (SEV) command support")
Quoted 20 lines

---
v2 cleanup commit log
v3 cleanup commit log

---
  drivers/crypto/ccp/sev-dev.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/ccp/sev-dev.c +1 -1
index 56998bc579d6..643cccc06a0b 100644
@@ -1307,7 +1307,7 @@ EXPORT_SYMBOL_GPL(sev_issue_cmd_external_user);
  void sev_pci_init(void)
  {
  	struct sev_device *sev = psp_master->sev_data;
-	int error, rc;
+	int error = 0, rc;
 
  	if (!sev)
  		return;
maintainer
#3 lore raw
In reply to Tom Rix
Quoted 10 lines · Tom Rix

Clang static analysis reports this problem drivers/crypto/ccp/sev-dev.c:1347:3: warning: 3rd function call
argument is an uninitialized value [core.CallAndMessage]

    dev_err(sev->dev, "SEV: failed to INIT error %#x, rc %d\n",
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

__sev_platform_init_locked() can return without setting the error parameter, causing the dev_err() to report a garbage value.

Quoted 8 lines
Fixes 200664d5237f ("crypto: ccp: Add Secure Encrypted Virtualization (SEV) command support")

---
v2 cleanup commit log
v3 cleanup commit log

---
 drivers/crypto/ccp/sev-dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

I think error should be removed completely on top of

https://patchwork.kernel.org/project/linux-crypto/patch/[email protected]/

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