Re: [PATCH v1 1/2] ACPI: NFIT: Fix memory leak, and local use of devm_*()
From: Andy Shevchenko
Date: Mon Oct 02 2023 - 05:37:27 EST
On Tue, Sep 26, 2023 at 09:45:19PM +0300, Michal Wilczynski wrote:
> devm_*() family of functions purpose is managing memory attached to a
> device. So in general it should only be used for allocations that should
> last for the whole lifecycle of the device. This is not the case for
> acpi_nfit_init_interleave_set(). There are two allocations that are only
> used locally in this function. What's more - if the function exits on
> error path memory is never freed. It's still attached to dev and would
> be freed on device detach, so this leak could be called a 'local leak'.
>
> Fix this by switching from devm_kcalloc() to kcalloc(), and adding
> proper rollback.
LGTM,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
--
With Best Regards,
Andy Shevchenko