Re: [PATCH 1/1] mfd: core: Fix memory leak of 'cell'

From: Lee Jones
Date: Thu Aug 13 2020 - 04:01:13 EST


On Thu, 13 Aug 2020, Marek Szyprowski wrote:

> Hi All,
>
> On 05.08.2020 16:26, Marek Szyprowski wrote:
> > On 16.07.2020 16:28, Lee Jones wrote:
> >> When creating a platform device from an MFD cell description, we
> >> allocate some memory and make a copy which is then stored inside the
> >> platform_device's structure.  However, care is not currently taken to
> >> free the allocated memory when the platform device is torn down.
> >>
> >> This patch takes care of the leak.
> >>
> >> Signed-off-by: Lee Jones <lee.jones@xxxxxxxxxx>
> >
> > This patch landed recently in linux-next as commit 126f33704d9d ("mfd:
> > core: Fix memory leak of 'cell'"). Sadly it causes a regression on
> > Samsung Exynos4412-based Trats2 board:
> > ...
> > Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
> >
> > I suspect that this is somehow related to the deferred probe and/or
> > devm_ helpers, but I didn't analyze it further yet. Reverting it on
> > top of current linux-next (and resolving conflict) fixes the boot.
> > Bisecting it was really hard because the issue is not fully
> > reproducible, what suggests memory trashing. Various tests of
> > linux-next with the reverted patch have shown at least that the issue
> > is gone.
> >
> > I've compiled the kernel from exynos_defconfig, the dts used for the
> > test is arch/arm/boot/dts/exynos4412-trats2.dts
>
> Finally I've found some time to analyze this issue.
>
> Indeed this patch is wrong it causes double free on the mfd_cell.
> mfd_cell is already properly freed by the platform_device_release()
> function when kref of the pdev goes down to zero:
> https://elixir.bootlin.com/linux/latest/source/drivers/base/platform.c#L426

Thank you for the explanation.

> I will send a revert with the explaination.

No need. I remove it from my tree. Thanks.

--
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog