diff mbox series

crypto: ccp - Free ccp if initialization fails

Message ID alpine.DEB.2.21.1906231217040.15277@chino.kir.corp.google.com (mailing list archive)
State Rejected
Delegated to: Herbert Xu
Headers show
Series crypto: ccp - Free ccp if initialization fails | expand

Commit Message

David Rientjes June 23, 2019, 7:18 p.m. UTC
If ccp_dev_init() fails, kfree() the allocated ccp since it will otherwise
be leaked.

Fixes: 720419f01832 ("crypto: ccp - Introduce the AMD Secure Processor
device")

Reported-by: Cfir Cohen <cfir@google.com>
Signed-off-by: David Rientjes <rientjes@google.com>
---
 drivers/crypto/ccp/ccp-dev.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Tom Lendacky June 24, 2019, 1:04 p.m. UTC | #1
On 6/23/19 2:18 PM, David Rientjes wrote:
> If ccp_dev_init() fails, kfree() the allocated ccp since it will otherwise
> be leaked.

Not needed. It's allocated with devm_kzalloc(), so it won't be leaked.

Thanks,
Tom

> 
> Fixes: 720419f01832 ("crypto: ccp - Introduce the AMD Secure Processor
> device")
> 
> Reported-by: Cfir Cohen <cfir@google.com>
> Signed-off-by: David Rientjes <rientjes@google.com>
> ---
>  drivers/crypto/ccp/ccp-dev.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/crypto/ccp/ccp-dev.c b/drivers/crypto/ccp/ccp-dev.c
> --- a/drivers/crypto/ccp/ccp-dev.c
> +++ b/drivers/crypto/ccp/ccp-dev.c
> @@ -609,6 +609,7 @@ int ccp_dev_init(struct sp_device *sp)
>  
>  e_err:
>  	sp->ccp_data = NULL;
> +	kfree(ccp);
>  
>  	dev_notice(dev, "ccp initialization failed\n");
>  
>
Gary R Hook June 24, 2019, 2:58 p.m. UTC | #2
On 6/24/19 8:04 AM, Lendacky, Thomas wrote:
> On 6/23/19 2:18 PM, David Rientjes wrote:
>> If ccp_dev_init() fails, kfree() the allocated ccp since it will otherwise
>> be leaked.
> 
> Not needed. It's allocated with devm_kzalloc(), so it won't be leaked.
> 
> Thanks,
> Tom

Nacked-By: Gary R Hook <gary.hook@amd.com>

> 
>>
>> Fixes: 720419f01832 ("crypto: ccp - Introduce the AMD Secure Processor
>> device")
>>
>> Reported-by: Cfir Cohen <cfir@google.com>
>> Signed-off-by: David Rientjes <rientjes@google.com>
>> ---
>>   drivers/crypto/ccp/ccp-dev.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/crypto/ccp/ccp-dev.c b/drivers/crypto/ccp/ccp-dev.c
>> --- a/drivers/crypto/ccp/ccp-dev.c
>> +++ b/drivers/crypto/ccp/ccp-dev.c
>> @@ -609,6 +609,7 @@ int ccp_dev_init(struct sp_device *sp)
>>   
>>   e_err:
>>   	sp->ccp_data = NULL;
>> +	kfree(ccp);
>>   
>>   	dev_notice(dev, "ccp initialization failed\n");
>>   
>>
diff mbox series

Patch

diff --git a/drivers/crypto/ccp/ccp-dev.c b/drivers/crypto/ccp/ccp-dev.c
--- a/drivers/crypto/ccp/ccp-dev.c
+++ b/drivers/crypto/ccp/ccp-dev.c
@@ -609,6 +609,7 @@  int ccp_dev_init(struct sp_device *sp)
 
 e_err:
 	sp->ccp_data = NULL;
+	kfree(ccp);
 
 	dev_notice(dev, "ccp initialization failed\n");