]> Gentwo Git Trees - linux/.git/commit
dmaengine: idxd: Fix double free in idxd_setup_wqs()
authorDan Carpenter <dan.carpenter@linaro.org>
Mon, 11 Aug 2025 10:43:39 +0000 (13:43 +0300)
committerVinod Koul <vkoul@kernel.org>
Wed, 20 Aug 2025 17:32:04 +0000 (23:02 +0530)
commit39aaa337449e71a41d4813be0226a722827ba606
tree41dc0bdb6af7e8ceee4b38bf7970a2deadcfd7e3
parentb7cb9a034305d52222433fad10c3de10204f29e7
dmaengine: idxd: Fix double free in idxd_setup_wqs()

The clean up in idxd_setup_wqs() has had a couple bugs because the error
handling is a bit subtle.  It's simpler to just re-write it in a cleaner
way.  The issues here are:

1) If "idxd->max_wqs" is <= 0 then we call put_device(conf_dev) when
   "conf_dev" hasn't been initialized.
2) If kzalloc_node() fails then again "conf_dev" is invalid.  It's
   either uninitialized or it points to the "conf_dev" from the
   previous iteration so it leads to a double free.

It's better to free partial loop iterations within the loop and then
the unwinding at the end can handle whole loop iterations.  I also
renamed the labels to describe what the goto does and not where the goto
was located.

Fixes: 3fd2f4bc010c ("dmaengine: idxd: fix memory leak in error handling path of idxd_setup_wqs")
Reported-by: Colin Ian King <colin.i.king@gmail.com>
Closes: https://lore.kernel.org/all/20250811095836.1642093-1-colin.i.king@gmail.com/
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Link: https://lore.kernel.org/r/aJnJW3iYTDDCj9sk@stanley.mountain
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/dma/idxd/init.c