linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: tegra - Remove an incorrect iommu_fwspec_free() call in tegra_se_remove()
@ 2024-05-25 15:14 Christophe JAILLET
  2024-05-29  6:40 ` Akhil R
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Christophe JAILLET @ 2024-05-25 15:14 UTC (permalink / raw)
  To: Akhil R, Herbert Xu, David S. Miller, Thierry Reding,
	Jonathan Hunter
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-crypto,
	linux-tegra

The only iommu function call in this driver is a
tegra_dev_iommu_get_stream_id() which does not allocate anything and does
not take any reference.

More-over, what is freed is "se->dev" which has been devm_kzalloc()'ed in
the probe.

So there is no point in calling iommu_fwspec_free() in the remove function.

Remove this incorrect function call.

Fixes: 0880bb3b00c8 ("crypto: tegra - Add Tegra Security Engine driver")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile tested only

This patch is completely speculative. *Review with care*.
---
 drivers/crypto/tegra/tegra-se-main.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/crypto/tegra/tegra-se-main.c b/drivers/crypto/tegra/tegra-se-main.c
index 9955874b3dc3..f94c0331b148 100644
--- a/drivers/crypto/tegra/tegra-se-main.c
+++ b/drivers/crypto/tegra/tegra-se-main.c
@@ -326,7 +326,6 @@ static void tegra_se_remove(struct platform_device *pdev)
 
 	crypto_engine_stop(se->engine);
 	crypto_engine_exit(se->engine);
-	iommu_fwspec_free(se->dev);
 	host1x_client_unregister(&se->client);
 }
 
-- 
2.45.1


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

* RE: [PATCH] crypto: tegra - Remove an incorrect iommu_fwspec_free() call in tegra_se_remove()
  2024-05-25 15:14 [PATCH] crypto: tegra - Remove an incorrect iommu_fwspec_free() call in tegra_se_remove() Christophe JAILLET
@ 2024-05-29  6:40 ` Akhil R
  2024-05-29  6:53 ` Akhil R
  2024-05-31 10:24 ` Herbert Xu
  2 siblings, 0 replies; 8+ messages in thread
From: Akhil R @ 2024-05-29  6:40 UTC (permalink / raw)
  To: Christophe JAILLET, Herbert Xu, David S. Miller, Thierry Reding,
	Jon Hunter
  Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
	linux-crypto@vger.kernel.org, linux-tegra@vger.kernel.org,
	Mikko Perttunen

> 
> The only iommu function call in this driver is a
> tegra_dev_iommu_get_stream_id() which does not allocate anything and does
> not take any reference.
> 
> More-over, what is freed is "se->dev" which has been devm_kzalloc()'ed in the
> probe.
> 
> So there is no point in calling iommu_fwspec_free() in the remove function.
> 
> Remove this incorrect function call.
> 
> Fixes: 0880bb3b00c8 ("crypto: tegra - Add Tegra Security Engine driver")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Compile tested only
> 
> This patch is completely speculative. *Review with care*.
> ---
>  drivers/crypto/tegra/tegra-se-main.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/drivers/crypto/tegra/tegra-se-main.c b/drivers/crypto/tegra/tegra-se-
> main.c
> index 9955874b3dc3..f94c0331b148 100644
> --- a/drivers/crypto/tegra/tegra-se-main.c
> +++ b/drivers/crypto/tegra/tegra-se-main.c
> @@ -326,7 +326,6 @@ static void tegra_se_remove(struct platform_device
> *pdev)
> 
>         crypto_engine_stop(se->engine);
>         crypto_engine_exit(se->engine);
> -       iommu_fwspec_free(se->dev);
>         host1x_client_unregister(&se->client);
>  }
> 

This was a futile attempt to fix a kmemleak warning in host1x_client_unregister() in a very old kernel.
I don't see it anymore, either with or without this change. So,

Tested-by: Akhil R <akhilrajeev@nvidia.com>
Acked-by: Akhil R <akhilrajeev@nvidia.com>

Regards,
Akhil

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

* RE: [PATCH] crypto: tegra - Remove an incorrect iommu_fwspec_free() call in tegra_se_remove()
  2024-05-25 15:14 [PATCH] crypto: tegra - Remove an incorrect iommu_fwspec_free() call in tegra_se_remove() Christophe JAILLET
  2024-05-29  6:40 ` Akhil R
@ 2024-05-29  6:53 ` Akhil R
  2024-05-30 10:30   ` Thierry Reding
  2024-05-31  5:23   ` Herbert Xu
  2024-05-31 10:24 ` Herbert Xu
  2 siblings, 2 replies; 8+ messages in thread
From: Akhil R @ 2024-05-29  6:53 UTC (permalink / raw)
  To: Christophe JAILLET, Herbert Xu, David S. Miller, Thierry Reding,
	Jon Hunter
  Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
	linux-crypto@vger.kernel.org, linux-tegra@vger.kernel.org

> The only iommu function call in this driver is a
> tegra_dev_iommu_get_stream_id() which does not allocate anything and does
> not take any reference.
> 
> More-over, what is freed is "se->dev" which has been devm_kzalloc()'ed in the
> probe.

I did not completely understand what is being tried to convey here.
If I understand it right, iommu_fwspec_free() does not do anything
with the "devm_kzalloc"ed variable. 

It would probably be a good idea to remove this line from the commit message.

> 
> So there is no point in calling iommu_fwspec_free() in the remove function.
> 
> Remove this incorrect function call.
> 
> Fixes: 0880bb3b00c8 ("crypto: tegra - Add Tegra Security Engine driver")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>


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

* Re: [PATCH] crypto: tegra - Remove an incorrect iommu_fwspec_free() call in tegra_se_remove()
  2024-05-29  6:53 ` Akhil R
@ 2024-05-30 10:30   ` Thierry Reding
  2024-05-31  5:23   ` Herbert Xu
  1 sibling, 0 replies; 8+ messages in thread
From: Thierry Reding @ 2024-05-30 10:30 UTC (permalink / raw)
  To: Akhil R, Christophe JAILLET, Herbert Xu, David S. Miller,
	Jon Hunter
  Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
	linux-crypto@vger.kernel.org, linux-tegra@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 1067 bytes --]

On Wed May 29, 2024 at 8:53 AM CEST, Akhil R wrote:
> > The only iommu function call in this driver is a
> > tegra_dev_iommu_get_stream_id() which does not allocate anything and does
> > not take any reference.
> > 
> > More-over, what is freed is "se->dev" which has been devm_kzalloc()'ed in the
> > probe.
>
> I did not completely understand what is being tried to convey here.
> If I understand it right, iommu_fwspec_free() does not do anything
> with the "devm_kzalloc"ed variable. 
>
> It would probably be a good idea to remove this line from the commit message.

Yeah, I think that's a bit misleading. What iommu_fwspec_free() does is
get the iommu_fwspec from the passed-in device and then frees that
iommu_fwspec.

That said, as I was looking around I didn't spot anything that was
calling iommu_fwspec_free() in any of the cleanup paths, so either I'm
missing something or it's a real memory leak (though perhaps one that we
are ignoring on purpose because these are usually attached to devices
that don't just go away).

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] crypto: tegra - Remove an incorrect iommu_fwspec_free() call in tegra_se_remove()
  2024-05-29  6:53 ` Akhil R
  2024-05-30 10:30   ` Thierry Reding
@ 2024-05-31  5:23   ` Herbert Xu
  2024-05-31  5:36     ` Akhil R
  1 sibling, 1 reply; 8+ messages in thread
From: Herbert Xu @ 2024-05-31  5:23 UTC (permalink / raw)
  To: Akhil R
  Cc: Christophe JAILLET, David S. Miller, Thierry Reding, Jon Hunter,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
	linux-crypto@vger.kernel.org, linux-tegra@vger.kernel.org

On Wed, May 29, 2024 at 06:53:42AM +0000, Akhil R wrote:
> > The only iommu function call in this driver is a
> > tegra_dev_iommu_get_stream_id() which does not allocate anything and does
> > not take any reference.
> > 
> > More-over, what is freed is "se->dev" which has been devm_kzalloc()'ed in the
> > probe.
> 
> I did not completely understand what is being tried to convey here.
> If I understand it right, iommu_fwspec_free() does not do anything
> with the "devm_kzalloc"ed variable. 
> 
> It would probably be a good idea to remove this line from the commit message.

I think he means that as the memory was allocated via devm, it will
be automatically freed by the kernel and the driver does not need
to (and should not) free the memory by hand.

Cheers,
-- 
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] 8+ messages in thread

* RE: [PATCH] crypto: tegra - Remove an incorrect iommu_fwspec_free() call in tegra_se_remove()
  2024-05-31  5:23   ` Herbert Xu
@ 2024-05-31  5:36     ` Akhil R
  2024-05-31 20:04       ` Marion & Christophe JAILLET
  0 siblings, 1 reply; 8+ messages in thread
From: Akhil R @ 2024-05-31  5:36 UTC (permalink / raw)
  To: Herbert Xu
  Cc: Christophe JAILLET, David S. Miller, Thierry Reding, Jon Hunter,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
	linux-crypto@vger.kernel.org, linux-tegra@vger.kernel.org



> -----Original Message-----
> From: Herbert Xu <herbert@gondor.apana.org.au>
> Sent: Friday, May 31, 2024 10:53 AM
> To: Akhil R <akhilrajeev@nvidia.com>
> Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>; David S. Miller
> <davem@davemloft.net>; Thierry Reding <thierry.reding@gmail.com>; Jon
> Hunter <jonathanh@nvidia.com>; linux-kernel@vger.kernel.org; kernel-
> janitors@vger.kernel.org; linux-crypto@vger.kernel.org; linux-
> tegra@vger.kernel.org
> Subject: Re: [PATCH] crypto: tegra - Remove an incorrect iommu_fwspec_free()
> call in tegra_se_remove()
> 
> External email: Use caution opening links or attachments
> 
> 
> On Wed, May 29, 2024 at 06:53:42AM +0000, Akhil R wrote:
> > > The only iommu function call in this driver is a
> > > tegra_dev_iommu_get_stream_id() which does not allocate anything and
> does
> > > not take any reference.
> > >
> > > More-over, what is freed is "se->dev" which has been devm_kzalloc()'ed in the
> > > probe.
> >
> > I did not completely understand what is being tried to convey here.
> > If I understand it right, iommu_fwspec_free() does not do anything
> > with the "devm_kzalloc"ed variable.
> >
> > It would probably be a good idea to remove this line from the commit message.
> 
> I think he means that as the memory was allocated via devm, it will
> be automatically freed by the kernel and the driver does not need
> to (and should not) free the memory by hand.

Ya. But iommu_fwspec_free() does not free the memory allocated via devm.

I think iommu_fwspec_free() is expected to be called in symmetry with
iommu_fwspec_init(). So, I do agree that the SE driver does not allocate
what is freed by iommu_fwspec_free(), but I feel this line is a bit misleading.



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

* Re: [PATCH] crypto: tegra - Remove an incorrect iommu_fwspec_free() call in tegra_se_remove()
  2024-05-25 15:14 [PATCH] crypto: tegra - Remove an incorrect iommu_fwspec_free() call in tegra_se_remove() Christophe JAILLET
  2024-05-29  6:40 ` Akhil R
  2024-05-29  6:53 ` Akhil R
@ 2024-05-31 10:24 ` Herbert Xu
  2 siblings, 0 replies; 8+ messages in thread
From: Herbert Xu @ 2024-05-31 10:24 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Akhil R, David S. Miller, Thierry Reding, Jonathan Hunter,
	linux-kernel, kernel-janitors, linux-crypto, linux-tegra

On Sat, May 25, 2024 at 05:14:35PM +0200, Christophe JAILLET wrote:
> The only iommu function call in this driver is a
> tegra_dev_iommu_get_stream_id() which does not allocate anything and does
> not take any reference.
> 
> More-over, what is freed is "se->dev" which has been devm_kzalloc()'ed in
> the probe.
> 
> So there is no point in calling iommu_fwspec_free() in the remove function.
> 
> Remove this incorrect function call.
> 
> Fixes: 0880bb3b00c8 ("crypto: tegra - Add Tegra Security Engine driver")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Compile tested only
> 
> This patch is completely speculative. *Review with care*.
> ---
>  drivers/crypto/tegra/tegra-se-main.c | 1 -
>  1 file changed, 1 deletion(-)

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] 8+ messages in thread

* Re: [PATCH] crypto: tegra - Remove an incorrect iommu_fwspec_free() call in tegra_se_remove()
  2024-05-31  5:36     ` Akhil R
@ 2024-05-31 20:04       ` Marion & Christophe JAILLET
  0 siblings, 0 replies; 8+ messages in thread
From: Marion & Christophe JAILLET @ 2024-05-31 20:04 UTC (permalink / raw)
  To: Akhil R, Herbert Xu
  Cc: David S. Miller, Thierry Reding, Jon Hunter,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
	linux-crypto@vger.kernel.org, linux-tegra@vger.kernel.org


Le 31/05/2024 à 07:36, Akhil R a écrit :
>> -----Original Message-----
>> From: Herbert Xu <herbert@gondor.apana.org.au>
>> Sent: Friday, May 31, 2024 10:53 AM
>> To: Akhil R <akhilrajeev@nvidia.com>
>> Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>; David S. Miller
>> <davem@davemloft.net>; Thierry Reding <thierry.reding@gmail.com>; Jon
>> Hunter <jonathanh@nvidia.com>; linux-kernel@vger.kernel.org; kernel-
>> janitors@vger.kernel.org; linux-crypto@vger.kernel.org; linux-
>> tegra@vger.kernel.org
>> Subject: Re: [PATCH] crypto: tegra - Remove an incorrect iommu_fwspec_free()
>> call in tegra_se_remove()
>>
>> External email: Use caution opening links or attachments
>>
>>
>> On Wed, May 29, 2024 at 06:53:42AM +0000, Akhil R wrote:
>>>> The only iommu function call in this driver is a
>>>> tegra_dev_iommu_get_stream_id() which does not allocate anything and
>> does
>>>> not take any reference.
>>>>
>>>> More-over, what is freed is "se->dev" which has been devm_kzalloc()'ed in the
>>>> probe.
>>> I did not completely understand what is being tried to convey here.
>>> If I understand it right, iommu_fwspec_free() does not do anything
>>> with the "devm_kzalloc"ed variable.
>>>
>>> It would probably be a good idea to remove this line from the commit message.
>> I think he means that as the memory was allocated via devm, it will
>> be automatically freed by the kernel and the driver does not need
>> to (and should not) free the memory by hand.


Yes, that is my point.

> Ya. But iommu_fwspec_free() does not free the memory allocated via devm.
>
> I think iommu_fwspec_free() is expected to be called in symmetry with
> iommu_fwspec_init(). So, I do agree that the SE driver does not allocate
> what is freed by iommu_fwspec_free(), but I feel this line is a bit misleading.
>
Yes, I spoke too fast.
What is freed is dev_iommu_fwspec_get(dev);, not dev. So the sentence I 
wrote makes no sense and should be removed :(


CJ



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

end of thread, other threads:[~2024-05-31 20:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-25 15:14 [PATCH] crypto: tegra - Remove an incorrect iommu_fwspec_free() call in tegra_se_remove() Christophe JAILLET
2024-05-29  6:40 ` Akhil R
2024-05-29  6:53 ` Akhil R
2024-05-30 10:30   ` Thierry Reding
2024-05-31  5:23   ` Herbert Xu
2024-05-31  5:36     ` Akhil R
2024-05-31 20:04       ` Marion & Christophe JAILLET
2024-05-31 10:24 ` Herbert Xu

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).