From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6BC8C156678; Fri, 4 Oct 2024 13:52:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728049928; cv=none; b=O8X+2q3WLyjw/IBg9MVD3sjALotwA9TEvOTq4W3Qm08Os+W/C7NVDE3HR/ZZ25dKPgdnDkolyMXVOrpvLlaEDs4PTNJ7e57CvJky+t1QyUR+PFicUw7rflZyk7iOSWpmtInPXGCbjWnu+Yt9tYxL6Uo5qKtGF9ETM31GQUQeci0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728049928; c=relaxed/simple; bh=z9rJf3VSM5rW82ltr4/yb3bcP3enExc8iYKWhR+CLec=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=YLWNSgBemk3Uli9IFjzmzi4LWn9VGfOpplzEiKjidYcE56nPR92bo3SS0nSAlD4wZ/H8juAS/+w5792cJAvdnyg0zQJ9E7BetDR+t/CyD7FRJOZXTrA7I1m5oJkLjfZgLOycIWMvvb4bw8e5aSfLCMf38e5mzblRHq2R/P16SaA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2F2FA339; Fri, 4 Oct 2024 06:52:35 -0700 (PDT) Received: from [10.57.77.142] (unknown [10.57.77.142]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 394B73F58B; Fri, 4 Oct 2024 06:52:04 -0700 (PDT) Message-ID: Date: Fri, 4 Oct 2024 14:53:03 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/2] thermal: core: Reference count the zone in thermal_zone_get_by_id() To: "Rafael J. Wysocki" Cc: "Rafael J. Wysocki" , LKML , Linux PM , Daniel Lezcano , Zhang Rui , Srinivas Pandruvada References: <12549318.O9o76ZdvQC@rjwysocki.net> <6112242.lOV4Wx5bFT@rjwysocki.net> <5222419a-2664-4bb5-b1d4-77a46677bb4d@arm.com> Content-Language: en-US From: Lukasz Luba In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 10/4/24 14:48, Rafael J. Wysocki wrote: > On Fri, Oct 4, 2024 at 3:43 PM Rafael J. Wysocki wrote: >> >> On Fri, Oct 4, 2024 at 3:37 PM Lukasz Luba wrote: >>> >>> >>> >>> On 10/4/24 14:25, Rafael J. Wysocki wrote: >>>> Hi Łukasz, >>>> >>>> On Fri, Oct 4, 2024 at 10:01 AM Lukasz Luba wrote: >>>>> >>>>> Hi Rafael, >>>>> >>>>> On 10/3/24 13:25, Rafael J. Wysocki wrote: >>>>>> From: Rafael J. Wysocki >>>>>> [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