Re: [PATCH] cpuidle: Fix memory leaks

From: Rafael J. Wysocki
Date: Fri Oct 01 2021 - 14:45:24 EST


On Wed, Sep 15, 2021 at 5:45 PM Anel Orazgaliyeva <anelkz@xxxxxxxxx> wrote:
>
> > On Wed, Sep 15, 2021 at 02:14:56PM +0200, Rafael J. Wysocki wrote:
> > CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
> >
> >
> >
> > On Mon, Sep 6, 2021 at 8:35 PM Anel Orazgaliyeva <anelkz@xxxxxxxxx> wrote:
> > >
> > > Commit c343bf1ba5ef ("cpuidle: Fix three reference count leaks")
> > > fixes the cleanup of kobjects; however, it removes kfree() calls
> > > altogether, leading to memory leaks.
> >
> > Wait, won't the cleanup be done by cpuidle_free_state_kobj()?
>
> For state cleanup, cpuidle_free_state_kobj() is called on the all the previously created kobjs:
>
> error_state:
> for (i = i - 1; i >= 0; i--)
> cpuidle_free_state_kobj(device, i);
>
> so we still need to cleanup the kobj created in the current iteration.
>
>
> For overall sysfs, the flow is as follows:
>
> cpuidle_register_device
> ret = cpuidle_add_sysfs(dev);
> if (ret)
> goto out_unregister;
>
> out_unregister:
> __cpuidle_unregister_device(dev);
> goto out_unlock;
>
> so when there is an error in cpuidle_add_sysfs() dev doesn’t get freed.

OK, applied as 5.16 material, thanks!