public inbox for linux-crypto@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] crypto: ccp: Fix dereferencing uninitialized error pointer
@ 2025-05-28 20:20 Ashish Kalra
  2025-05-28 23:26 ` Herbert Xu
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Ashish Kalra @ 2025-05-28 20:20 UTC (permalink / raw)
  To: thomas.lendacky, john.allen, herbert, davem, dan.carpenter
  Cc: linux-crypto, linux-kernel

From: Ashish Kalra <ashish.kalra@amd.com>

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")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/r/202505071746.eWOx5QgC-lkp@intel.com/
Signed-off-by: Ashish Kalra <ashish.kalra@amd.com>
---
 drivers/crypto/ccp/sev-dev.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
index 3451bada884e..8fb94c5f006a 100644
--- a/drivers/crypto/ccp/sev-dev.c
+++ b/drivers/crypto/ccp/sev-dev.c
@@ -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;
 	}
 
-- 
2.34.1


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

* Re: [PATCH] crypto: ccp: Fix dereferencing uninitialized error pointer
  2025-05-28 20:20 [PATCH] crypto: ccp: Fix dereferencing uninitialized error pointer Ashish Kalra
@ 2025-05-28 23:26 ` Herbert Xu
  2025-05-29  1:19   ` Kalra, Ashish
  2025-05-29 19:48 ` Tom Lendacky
  2025-06-16  2:46 ` Herbert Xu
  2 siblings, 1 reply; 5+ messages in thread
From: Herbert Xu @ 2025-05-28 23:26 UTC (permalink / raw)
  To: Ashish Kalra
  Cc: thomas.lendacky, john.allen, davem, dan.carpenter, linux-crypto,
	linux-kernel

On Wed, May 28, 2025 at 08:20:18PM +0000, Ashish Kalra wrote:
>
> @@ -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,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: [PATCH] crypto: ccp: Fix dereferencing uninitialized error pointer
  2025-05-28 23:26 ` Herbert Xu
@ 2025-05-29  1:19   ` Kalra, Ashish
  0 siblings, 0 replies; 5+ messages in thread
From: Kalra, Ashish @ 2025-05-29  1:19 UTC (permalink / raw)
  To: Herbert Xu
  Cc: thomas.lendacky, john.allen, davem, dan.carpenter, linux-crypto,
	linux-kernel


On 5/28/2025 6:26 PM, Herbert Xu wrote:
> On Wed, May 28, 2025 at 08:20:18PM +0000, Ashish Kalra wrote:
>>
>> @@ -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?

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

> 
> Thanks,


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

* Re: [PATCH] crypto: ccp: Fix dereferencing uninitialized error pointer
  2025-05-28 20:20 [PATCH] crypto: ccp: Fix dereferencing uninitialized error pointer Ashish Kalra
  2025-05-28 23:26 ` Herbert Xu
@ 2025-05-29 19:48 ` Tom Lendacky
  2025-06-16  2:46 ` Herbert Xu
  2 siblings, 0 replies; 5+ messages in thread
From: Tom Lendacky @ 2025-05-29 19:48 UTC (permalink / raw)
  To: Ashish Kalra, john.allen, herbert, davem, dan.carpenter
  Cc: linux-crypto, linux-kernel

On 5/28/25 15:20, Ashish Kalra wrote:
> From: Ashish Kalra <ashish.kalra@amd.com>
> 
> 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")
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes: https://lore.kernel.org/r/202505071746.eWOx5QgC-lkp@intel.com/
> Signed-off-by: Ashish Kalra <ashish.kalra@amd.com>

Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>

> ---
>  drivers/crypto/ccp/sev-dev.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
> index 3451bada884e..8fb94c5f006a 100644
> --- a/drivers/crypto/ccp/sev-dev.c
> +++ b/drivers/crypto/ccp/sev-dev.c
> @@ -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;
>  	}
>  

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

* Re: [PATCH] crypto: ccp: Fix dereferencing uninitialized error pointer
  2025-05-28 20:20 [PATCH] crypto: ccp: Fix dereferencing uninitialized error pointer Ashish Kalra
  2025-05-28 23:26 ` Herbert Xu
  2025-05-29 19:48 ` Tom Lendacky
@ 2025-06-16  2:46 ` Herbert Xu
  2 siblings, 0 replies; 5+ messages in thread
From: Herbert Xu @ 2025-06-16  2:46 UTC (permalink / raw)
  To: Ashish Kalra
  Cc: thomas.lendacky, john.allen, davem, dan.carpenter, linux-crypto,
	linux-kernel

On Wed, May 28, 2025 at 08:20:18PM +0000, Ashish Kalra wrote:
> From: Ashish Kalra <ashish.kalra@amd.com>
> 
> 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")
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes: https://lore.kernel.org/r/202505071746.eWOx5QgC-lkp@intel.com/
> Signed-off-by: Ashish Kalra <ashish.kalra@amd.com>
> ---
>  drivers/crypto/ccp/sev-dev.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

end of thread, other threads:[~2025-06-16  2:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-28 20:20 [PATCH] crypto: ccp: Fix dereferencing uninitialized error pointer Ashish Kalra
2025-05-28 23:26 ` Herbert Xu
2025-05-29  1:19   ` Kalra, Ashish
2025-05-29 19:48 ` Tom Lendacky
2025-06-16  2:46 ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox