linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: initialize error variable
@ 2021-08-16 19:23 trix
  2021-08-16 20:01 ` Tom Lendacky
  0 siblings, 1 reply; 2+ messages in thread
From: trix @ 2021-08-16 19:23 UTC (permalink / raw)
  To: brijesh.singh, thomas.lendacky, john.allen, herbert, davem,
	ashish.kalra, rientjes
  Cc: linux-crypto, linux-kernel, Tom Rix

From: Tom Rix <trix@redhat.com>

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.")
Signed-off-by: Tom Rix <trix@redhat.com>
---
 drivers/crypto/ccp/sev-dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
index 2ecb0e1f65d8d..b2b9f0f4daf2d 100644
--- a/drivers/crypto/ccp/sev-dev.c
+++ b/drivers/crypto/ccp/sev-dev.c
@@ -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;
-- 
2.26.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] crypto: initialize error variable
  2021-08-16 19:23 [PATCH] crypto: initialize error variable trix
@ 2021-08-16 20:01 ` Tom Lendacky
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Lendacky @ 2021-08-16 20:01 UTC (permalink / raw)
  To: trix, brijesh.singh, john.allen, herbert, davem, ashish.kalra, rientjes
  Cc: linux-crypto, linux-kernel

On 8/16/21 2:23 PM, trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
> 
> 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.")
> Signed-off-by: Tom Rix <trix@redhat.com>
> ---
>  drivers/crypto/ccp/sev-dev.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
> index 2ecb0e1f65d8d..b2b9f0f4daf2d 100644
> --- a/drivers/crypto/ccp/sev-dev.c
> +++ b/drivers/crypto/ccp/sev-dev.c
> @@ -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/20210707183616.5620-13-brijesh.singh@amd.com/

Thanks,
Tom

>  
>  	if (!sev)
>  		return;
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-16 20:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-16 19:23 [PATCH] crypto: initialize error variable trix
2021-08-16 20:01 ` Tom Lendacky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).