mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] crypto: qat - free dc_data with kfree() in the error path
@ 2026-10-19  5:51 ZhaoJinming
  2026-11-02 15:52 ` Giovanni Cabiddu
  0 siblings, 1 reply; 2+ messages in thread
From: ZhaoJinming @ 2026-10-19  5:51 UTC (permalink / raw)
  To: Herbert Xu
  Cc: linux-crypto, qat-linux, linux-kernel, Giovanni Cabiddu,
	David S. Miller, Suman Kumar Chakraborty, Laurent M Coquerel,
	Thorsten Blum, stable, ZhaoJinming

qat_compression_alloc_dc_data() allocates dc_data with kzalloc_node(), but
its error path releases it with devm_kfree():

	dc_data = kzalloc_node(sizeof(*dc_data), GFP_KERNEL,
			       dev_to_node(dev));
	...
err:
	accel_dev->dc_data = NULL;
	kfree(obuff);
	devm_kfree(dev, dc_data);

devm_kfree() only frees memory that was allocated with devm_kmalloc() and
registered with the device resource manager.  dc_data is a plain kmalloc
allocation that was never registered, so devres_destroy() does not find it,
returns -ENOENT and devm_kfree() ends up in WARN_ON() without freeing
anything.  The dc_data structure is leaked.

Commit 4cc871ad0173 ("crypto: qat - use unmanaged allocation for dc_data")
switched dc_data to unmanaged allocation and replaced the devm_kfree() in
qat_free_dc_data(), but missed the identical call in the error path of
qat_compression_alloc_dc_data().  That path is taken when the overflow
buffer allocation or its DMA mapping fails.

Free dc_data with kfree() here as well, matching the allocation and the
other release path.

Fixes: 4cc871ad0173 ("crypto: qat - use unmanaged allocation for dc_data")
Cc: stable@vger.kernel.org
Signed-off-by: ZhaoJinming <zhaojinming@uniontech.com>
---
 drivers/crypto/intel/qat/qat_common/qat_compression.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/intel/qat/qat_common/qat_compression.c b/drivers/crypto/intel/qat/qat_common/qat_compression.c
index 8129ad0c32d8..7a5b648302a0 100644
--- a/drivers/crypto/intel/qat/qat_common/qat_compression.c
+++ b/drivers/crypto/intel/qat/qat_common/qat_compression.c
@@ -241,7 +241,7 @@ static int qat_compression_alloc_dc_data(struct adf_accel_dev *accel_dev)
 err:
 	accel_dev->dc_data = NULL;
 	kfree(obuff);
-	devm_kfree(dev, dc_data);
+	kfree(dc_data);
 	return -ENOMEM;
 }
 

---
base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222
change-id: 20261019-qat-dc-data-kfree-76c7e1ddc2a7

Best regards,
--  
ZhaoJinming <zhaojinming@uniontech.com>


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

* Re: [PATCH] crypto: qat - free dc_data with kfree() in the error path
  2026-10-19  5:51 [PATCH] crypto: qat - free dc_data with kfree() in the error path ZhaoJinming
@ 2026-11-02 15:52 ` Giovanni Cabiddu
  0 siblings, 0 replies; 2+ messages in thread
From: Giovanni Cabiddu @ 2026-11-02 15:52 UTC (permalink / raw)
  To: ZhaoJinming
  Cc: Herbert Xu, linux-crypto, qat-linux, linux-kernel,
	David S. Miller, Suman Kumar Chakraborty, Laurent M Coquerel,
	Thorsten Blum, stable

On Mon, Oct 19, 2026 at 01:51:32PM +0800, ZhaoJinming wrote:
> qat_compression_alloc_dc_data() allocates dc_data with kzalloc_node(), but
> its error path releases it with devm_kfree():
> 
> 	dc_data = kzalloc_node(sizeof(*dc_data), GFP_KERNEL,
> 			       dev_to_node(dev));
> 	...
> err:
> 	accel_dev->dc_data = NULL;
> 	kfree(obuff);
> 	devm_kfree(dev, dc_data);
> 
> devm_kfree() only frees memory that was allocated with devm_kmalloc() and
> registered with the device resource manager.  dc_data is a plain kmalloc
> allocation that was never registered, so devres_destroy() does not find it,
> returns -ENOENT and devm_kfree() ends up in WARN_ON() without freeing
> anything.  The dc_data structure is leaked.
> 
> Commit 4cc871ad0173 ("crypto: qat - use unmanaged allocation for dc_data")
> switched dc_data to unmanaged allocation and replaced the devm_kfree() in
> qat_free_dc_data(), but missed the identical call in the error path of
> qat_compression_alloc_dc_data().  That path is taken when the overflow
> buffer allocation or its DMA mapping fails.
> 
> Free dc_data with kfree() here as well, matching the allocation and the
> other release path.
> 
> Fixes: 4cc871ad0173 ("crypto: qat - use unmanaged allocation for dc_data")
> Cc: stable@vger.kernel.org
> Signed-off-by: ZhaoJinming <zhaojinming@uniontech.com>
Acked-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>

Regards,

-- 
Giovanni

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

end of thread, other threads:[~2026-11-02 15:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-19  5:51 [PATCH] crypto: qat - free dc_data with kfree() in the error path ZhaoJinming
2026-11-02 15:52 ` Giovanni Cabiddu

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

all inboxes | Powered by JetHome®