Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4087654rdb; Mon, 11 Dec 2023 08:28:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IEF4NJsNNpoJ7fT9eSgKG4w4/6R8Ud7mwagXzMxKX7YcbpI5UGUWKRlbBwNb38VhxLlRLU6 X-Received: by 2002:a05:6a20:cf49:b0:186:aac2:26b9 with SMTP id hz9-20020a056a20cf4900b00186aac226b9mr1830234pzb.30.1702312136891; Mon, 11 Dec 2023 08:28:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702312136; cv=none; d=google.com; s=arc-20160816; b=dEcDPi2mrg3lOEQhrrxR8DWsM/dTZUQH83ZJNS4mmymFKQMF6M4EQWJzgZUqe7toJH rMSpv2+jSbqCJihD2raSob35jUy67DDtDYsD8HcWvaT0viiIKP57XOUeUJDtU077Jrh0 ggSZjgxEOBzPAIolzLzVs6JtHRvcRU57UR7HiNR6fTWeBfAcogdVnE4sERpP0wWH6Ca1 /bcAvCE9QZowzfvCJGvguStOU9vgAUOjZbK4DuGx4kS2gWPMcq0SCC3cERu7MMq8fMtA BnRHyCy1iYbK8kA839a4nAZ1v9GCfMl5aDc+fhEQtTe+WUoNYOGJ8+f6y4KDuSKLXSqJ v8Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=UY6XrDoqDxgMJunuedrsiS+ICxcRp6UXL9LejdoCOD4=; fh=LBoYCTwcnc4aGCO1Ky9m5KD26cM4ZwLGFt7YdcTzbHo=; b=ol0sRtiAoeM8MRYNpF/WQEDECLK3B9PGdTPhOGqqOpgVNWeERCSX8Jm5cm8zJhWPOA HUalW5WgzNBbXijtxpEEGIKLGcKZ6aBHcLg/WIWEc837L/XsBn1TYjCny5HCnY9j1OQa Uoba6TfnJTdybOzCGuWAPtoboLSVlRtS31pMDoQxwuYf1Ykn9RTxo8KP5tDMvKuVnv91 HVFIyWj4+5cdwL99PhKNDzL/ztGMlKimRHoXVy18tdNQHhlAvZhEllB5jzq7h+96L+2i rBNGYCK+dTzo7KEo29rLzUywO3gWxqv3dQrb2wwcPb8k0l5z04t6raG8CH6EHysrYI/D B7OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CrENPrpO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id y9-20020a63e249000000b005c1b2d93e52si6371816pgj.368.2023.12.11.08.28.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 08:28:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CrENPrpO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id DC322803C460; Mon, 11 Dec 2023 08:28:53 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234979AbjLKQ2i (ORCPT + 99 others); Mon, 11 Dec 2023 11:28:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234938AbjLKQ2h (ORCPT ); Mon, 11 Dec 2023 11:28:37 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0793A9E for ; Mon, 11 Dec 2023 08:28:43 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40c4846847eso10325695e9.1 for ; Mon, 11 Dec 2023 08:28:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1702312121; x=1702916921; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=UY6XrDoqDxgMJunuedrsiS+ICxcRp6UXL9LejdoCOD4=; b=CrENPrpOV1/yyW/9NLQUEJl11Z+8XDyfLztUWzdKZRhxvFzQ3yuohxRcWViGj3HBsB O53GIlAOpCCZAwPYa/cHBO78aej4lWN81kDhVwvYteREkk9vcg5vYb1qcJiKpkitrvKr OOXtBoahOsDZV99nqS6Y6ZQaxpR87l42v5V+kTcaE1yz6Ogqcls+SoEhuV81L3APmgNh k3Q+eA5hCBigXEYBGvXp+Ka4EwJ4xvRpqBQgi0fsT4s9GniXsERUNuJ0DrROFGtPUDLO s+lEpjoKTwMuFVYvWgBnISyFxhhCAAHoRM/omycZBAR+kP+rVbc3xDh++YpBeDZwsMKw EBkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702312121; x=1702916921; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UY6XrDoqDxgMJunuedrsiS+ICxcRp6UXL9LejdoCOD4=; b=YToiBhKYEKIscmmlELk0rX/F5preCw1VxRwN8tSf+sEQrLMn1iqx0gLjmxSqnd1p0w SIJ7T2FkIiXNE3DRLdOwzNs4pbCl4Sy9q8x+sxKCcmVfqPgFlrl0N03JpTB5pC7p1B3B wKTGrEBSDINJADz/xvXIK5Gu/C7+7edlfc9lAeepYjUcS+tNF+JCztkFnaWT/p+hn53T +TFp+EQt5hQfT+JbkBhUs/5kemx7VmvzcWBHkOQRB+e3w2QLcN2sdqQ2YN2LeboKYFaO LH5hhCo2gY+DYj2tytVQG/GBLpmdLL7Iv+FJck5QTbABqyT9y8em8161ocWTJqTARJSZ +rvA== X-Gm-Message-State: AOJu0YxWjCmEMYboCqaP1whVhmu6IQsW1wYjgn+KYkk6yb1UMdcTx3Vu KRs8MGNFmWK8T7fLvPvZjJaw2g== X-Received: by 2002:a7b:cb90:0:b0:40c:337e:cbb with SMTP id m16-20020a7bcb90000000b0040c337e0cbbmr2344436wmi.88.1702312121331; Mon, 11 Dec 2023 08:28:41 -0800 (PST) Received: from ?IPV6:2a05:6e02:1041:c10:c49e:e1a5:3210:b8c0? ([2a05:6e02:1041:c10:c49e:e1a5:3210:b8c0]) by smtp.googlemail.com with ESMTPSA id a19-20020a05600c349300b004064cd71aa8sm13425670wmq.34.2023.12.11.08.28.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 11 Dec 2023 08:28:40 -0800 (PST) Message-ID: <0a0d5dd4-6b7a-428b-8ef1-bb6aff76fb51@linaro.org> Date: Mon, 11 Dec 2023 17:28:40 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 1/3] thermal: core: Make thermal_zone_device_unregister() return after freeing the zone Content-Language: en-US To: "Rafael J. Wysocki" , Linux PM Cc: Srinivas Pandruvada , Zhang Rui , Linux ACPI , LKML , Lukasz Luba References: <1880915.tdWV9SEqCh@kreacher> <13414639.uLZWGnKmhe@kreacher> From: Daniel Lezcano In-Reply-To: <13414639.uLZWGnKmhe@kreacher> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 11 Dec 2023 08:28:54 -0800 (PST) On 08/12/2023 20:13, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki > > Make thermal_zone_device_unregister() wait until all of the references > to the given thermal zone object have been dropped and free it before > returning. > > This guarantees that when thermal_zone_device_unregister() returns, > there is no leftover activity regarding the thermal zone in question > which is required by some of its callers (for instance, modular driver > code that wants to know when it is safe to let the module go away). > > Subsequently, this will allow some confusing device_is_registered() > checks to be dropped from the thermal sysfs and core code. > > Signed-off-by: Rafael J. Wysocki > --- Definitively agree on the change Acked-by: Daniel Lezcano Would it make sense to use kref_get/put ? > drivers/thermal/thermal_core.c | 6 +++++- > include/linux/thermal.h | 2 ++ > 2 files changed, 7 insertions(+), 1 deletion(-) > > Index: linux-pm/drivers/thermal/thermal_core.c > =================================================================== > --- linux-pm.orig/drivers/thermal/thermal_core.c > +++ linux-pm/drivers/thermal/thermal_core.c > @@ -822,7 +822,7 @@ static void thermal_release(struct devic > tz = to_thermal_zone(dev); > thermal_zone_destroy_device_groups(tz); > mutex_destroy(&tz->lock); > - kfree(tz); > + complete(&tz->removal); > } else if (!strncmp(dev_name(dev), "cooling_device", > sizeof("cooling_device") - 1)) { > cdev = to_cooling_device(dev); > @@ -1315,6 +1315,7 @@ thermal_zone_device_register_with_trips( > INIT_LIST_HEAD(&tz->thermal_instances); > ida_init(&tz->ida); > mutex_init(&tz->lock); > + init_completion(&tz->removal); > id = ida_alloc(&thermal_tz_ida, GFP_KERNEL); > if (id < 0) { > result = id; > @@ -1494,6 +1495,9 @@ void thermal_zone_device_unregister(stru > put_device(&tz->device); > > thermal_notify_tz_delete(tz_id); > + > + wait_for_completion(&tz->removal); > + kfree(tz); > } > EXPORT_SYMBOL_GPL(thermal_zone_device_unregister); > > Index: linux-pm/include/linux/thermal.h > =================================================================== > --- linux-pm.orig/include/linux/thermal.h > +++ linux-pm/include/linux/thermal.h > @@ -117,6 +117,7 @@ struct thermal_cooling_device { > * @id: unique id number for each thermal zone > * @type: the thermal zone device type > * @device: &struct device for this thermal zone > + * @removal: removal completion > * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature > * @trip_type_attrs: attributes for trip points for sysfs: trip type > * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis > @@ -156,6 +157,7 @@ struct thermal_zone_device { > int id; > char type[THERMAL_NAME_LENGTH]; > struct device device; > + struct completion removal; > struct attribute_group trips_attribute_group; > struct thermal_attr *trip_temp_attrs; > struct thermal_attr *trip_type_attrs; > > > -- Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog