Re: [PATCH] ASoC: sma1307: fix double free of devm_kzalloc() memory
From: Mark Brown
Date: Thu Mar 12 2026 - 08:07:04 EST
On Thu, Mar 12, 2026 at 04:47:49PM +0800, Guangshuo Li wrote:
> A previous change added NULL checks and cleanup for allocation
> failures in sma1307_setting_loaded().
>
> However, the cleanup for mode_set entries is wrong. Those entries are
> allocated with devm_kzalloc(), so they are device-managed resources and
> must not be freed with kfree(). Manually freeing them in the error path
> can lead to a double free when devres later releases the same memory.
>
> Drop the manual kfree() loop and let devres handle the cleanup.
You're right that we shouldn't be using kfree() here, however the
settings can be reloaded via the userpace visible reset control the
driver has so removing the free entirely will leake the mode strings.
We need a devm_kfree() here I think.
Attachment:
signature.asc
Description: PGP signature