Re: [PATCH v2 1/2] thermal: core: Reference count the zone in thermal_zone_get_by_id()

From: Lukasz Luba
Date: Fri Oct 04 2024 - 09:52:12 EST




On 10/4/24 14:48, Rafael J. Wysocki wrote:
On Fri, Oct 4, 2024 at 3:43 PM Rafael J. Wysocki <rafael@xxxxxxxxxx> wrote:

On Fri, Oct 4, 2024 at 3:37 PM Lukasz Luba <lukasz.luba@xxxxxxx> wrote:



On 10/4/24 14:25, Rafael J. Wysocki wrote:
Hi Łukasz,

On Fri, Oct 4, 2024 at 10:01 AM Lukasz Luba <lukasz.luba@xxxxxxx> wrote:

Hi Rafael,

On 10/3/24 13:25, Rafael J. Wysocki wrote:
From: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>


[snip]



I wasn't aware of that helpers in cleanup.h.

Could you help me to understand when this this
'if (_T) put_device((&_T->device)' will be called?

When the pointer variable initialized via the CLASS() macro goes out
of scope (that is, before freeing the memory occupied by the pointer
itself).


OK, so do we still need the old code in
thermal_zone_device_unregister(), which calls
put_device(&tz->device) ?

Yes, we do.

Maybe that code can go away?

That particular one drops the reference acquired by device_register()
and I don't see an alternative clean way to drop it.

The problem there is that local variable tz goes out of scope at the
end of the function (at least formally) and put_device(&tz->device)
needs to be called before the wait_for_completion(&tz->removal) which
definitely needs tz to be still around.

OK, I see now. That makes sense. With that feel free to add:

Reviewed-by: Lukasz Luba <lukasz.luba@xxxxxxx>