Re: [PATCH v2] mfd: sm501: fix reference leak on failed device registration
From: Miquel Raynal
Date: Tue May 05 2026 - 11:13:40 EST
Hi Lee,
On 05/05/2026 at 16:00:13 +01, Lee Jones <lee@xxxxxxxxxx> wrote:
> On Mon, 04 May 2026, Miquel Raynal wrote:
>
>> On Mon, 04 May 2026 15:48:41 +0300, Valery Borovsky wrote:
>> > When platform_device_register() fails in sm501_register_device(), the
>> > platform device allocated by sm501_create_subdev() has its struct device
>> > initialized by device_initialize() inside platform_device_register(). The
>> > error path logs the error but returns without dropping the device reference,
>> > leaking the memory allocated by sm501_create_subdev():
>> >
>> > sm501_register_device()
>> > -> platform_device_register(pdev)
>> > -> device_initialize(&pdev->dev) /* kref = 1 */
>> > -> platform_device_add(pdev) /* fails */
>> > <- dev_err() called, kref still 1, sm501_device_release never called
>> >
>> > [...]
>>
>> Applied to mtd/next, thanks!
>
> I think you misread the subject line.
>
>> [1/1] mfd: sm501: fix reference leak on failed device registration
>> commit: faa9bba3fe2f37e7dcb26d4501d890fbfd7df160
>>
>> Patche(s) should be available on mtd/linux.git and will be
>> part of the next PR (provided that no robot complains by then).
>
> Please remove this from your tree. It should be handled via M[F]D.
Yes, it took a bit of time for me to receive my own answer so I replied
to the original patch immediately stating that I dropped it. For some
reason b4 applied this patch, whereas I was applying another m*t*d patch
from apparently the same series (?). Both the contribution and b4 behaviour
was strange.
Sorry for the noise.
Thanks,
Miquèl