From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4F243FE367 for ; Tue, 26 May 2026 14:08:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779804530; cv=none; b=YU0zEIcWLmSW+sh3esaUrxqdJ9MWzOCbj0NKoxIcRITAOSmJE70uJDmudfccyvKpc1OrzsO7fa/nRx3MNAHmYaC82gyz5yN3/WvbO/ZiCVOc8Ne0QdBhoWt4D9LYJq4rk8A4LzyLBZ0zPs2PV+WCsxJHcROz2jFAXiU9XOF5Nck= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779804530; c=relaxed/simple; bh=k8cNf6pQ9FgDrZOTphnMGI85hDwnR2f4A1GS/R7x154=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TJ6JBmxL+IRu37xB8iWnrDAd0xkiHBQEy4HvtrGKWVe8S00Tw8P5RbLtC1bzCX4Bx1o4cOANjbDK4UknKZeWvNxlqwV2e1E1R7kCYyzLo69K8RQZfOqCGfqvGB+xtnrm3n08LSkrntOQgTRN+2tEii4xjuSzGGAFswI+7ELvcjU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=Wn1vNEZE; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=ge0X9H6z; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="Wn1vNEZE"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="ge0X9H6z" Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 64QDhrkR2528461 for ; Tue, 26 May 2026 14:08:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=gNIUoFMWInZ GWGk42JVKNlbIGQZZPpc24UB5yZQypFY=; b=Wn1vNEZEsjdL+v5SX9/0N8w70QV 3rBavCADHitOhm9o5L9FKHfsLkLQvR5E17kwgFHeEbUSYjVp4IYdYSsK1Ujhv39U vIa0hGw1628hHNr51guhV5hO/X2iCt9NP2i2MnuPztSZFp8qg/WvsaLAyVjx3llC oVkSZp/NuAhH1j+oOBJi4QeGnt6oi8tVf2N+DNqxwI57s6e09KAIzWjBUw/u2zKS rtAVwZbhKeI7PlZeU39hFIiqUikHHDilsIhLImrFzQN26LXA195ma55jrSNcUAVM IyfUuoc7582g8mYjFGZRys29hQv9nKjAq3yalzVIoveVuJPE0INWaejWTKg== Received: from mail-oo1-f70.google.com (mail-oo1-f70.google.com [209.85.161.70]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4edcnnr3w6-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 26 May 2026 14:08:44 +0000 (GMT) Received: by mail-oo1-f70.google.com with SMTP id 006d021491bc7-69d94704126so3642824eaf.0 for ; Tue, 26 May 2026 07:08:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1779804524; x=1780409324; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gNIUoFMWInZGWGk42JVKNlbIGQZZPpc24UB5yZQypFY=; b=ge0X9H6z/5B9I/Bv6r5zPfDHCYZXmYpTzd7Wo79N0YXD1qAdfDZQtN8MHDfdWxql8P 9nA8fhCnmyJuZU1+D1olwG+6cAncbzp3YxFS0navb0u5+M41gOtsl36f22gOLCqaH9Qx HOyUSc2sl1l6f/C8J42EG3dCEgDGUaThvn/edAKUNOXDWZy0usRmw9e9YBuBAt9Vo9tG zAxf4njDv1If4pm1pqzFcburUbDx3sdhan5UPKsSJbERhrhoyvM+LD8fCelfLaWmIIwt iqMasWf2x69paEInZkzMg1TR7GWA8WmTVRoanXfcjRgfVa1BnCOIXJJezdZ33IrangEF Jq9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779804524; x=1780409324; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=gNIUoFMWInZGWGk42JVKNlbIGQZZPpc24UB5yZQypFY=; b=Qm/NINZxfAc4e/Qo2eJF8SqDtZmrTjekC4SLcnvPkao0D6OYcg09wAd/RPMIX4AN9m QUVQaqVbkl+9a3T3AeCFKgMTJMtG6qKJG+d10/4L1rnM3zGEUfuYEc93xDWI7LLGiKkV xdQEClkKetfZvUH+NaCAiH0StR5QMlTOuvhzW9queh5txawWxecdz/LhgR9vLIHwxQaE /2IVaUobr5waTJIPK110X7Vc1BoSc8st0jrVETcVojViKARPB5OUFA+hHAnZOWfdqc0Z fXjQgNDQGU1B+CaZo+gSi+Rlr8rrcQkELSW8ml9dtaSU0jc1KMDIAaQCFliWX08L650g FQ8A== X-Forwarded-Encrypted: i=1; AFNElJ8YCdm1m1I/gcQjmac4qXjQeBt32C6IdtdqRGIIVcrQxyWdvxERewgXqyWuQqYkNeMVkz9casMqUgwSFz0=@vger.kernel.org X-Gm-Message-State: AOJu0YwW1gq29CYa2xrUV2HkYgKBVOfjhyXPU2erko2WZIQiZRrnOLKk pfPv5yTGp8HLxRezLh2gQVTHXpV1BUwmXOk2q6YLMu+qXJtEOJToUORTQoYsuTEuUQxV6m+MEF6 RxsvHf3MGwqe1g+LQneORn3wx4J5DWush6Z3rtbKWdy15ErGU/+gx6vR6qbuwpGKS+Y8= X-Gm-Gg: Acq92OEf7pl4pKziLKSXVYrC6swncI3nM1IFQAhOygrf8cEouHd2OvAoeYgPOXTnjJR q/1bP5IpcdhVkEW4HlwB9N3lJmRasKCg+cO/HDsU4HMpoWgjKdMHbU3VhO6Ca7a6kgiKZVsFCgK S4GAN3AHeQZoRwiS+KMfUWF0qhZGcCm4/x4KUKVp3JFCB5xeYOz50DH6ynqmKEq5aQD1DLB5nZe mJla+G/2mFVzSKJoATzt7eXnXl4rZIquBadxZooIzuFWVQBk9+ud2Za8eAwS6ujm+GDKZT3g5Lh 596bLVNro2a7yzEntCBSWnC4SVPtmWccfWLeBr46mWwrFihdwpRLKGzn2Nsbqx09qDC/2M5qHGK QUzx+7O4Ibu7kHzWDne83KjvlUPQF2kwmPJJ8W6fBDd427N11 X-Received: by 2002:a05:6820:4dc4:b0:69d:d95e:773e with SMTP id 006d021491bc7-69dd95ee464mr765721eaf.8.1779804523984; Tue, 26 May 2026 07:08:43 -0700 (PDT) X-Received: by 2002:a05:6820:4dc4:b0:69d:d95e:773e with SMTP id 006d021491bc7-69dd95ee464mr765671eaf.8.1779804523504; Tue, 26 May 2026 07:08:43 -0700 (PDT) Received: from mai.box.freepro.com ([2a05:6e02:1041:c10:9e9:6f8d:9f1c:61e1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490424aa561sm156266605e9.5.2026.05.26.07.08.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2026 07:08:42 -0700 (PDT) From: Daniel Lezcano To: rafael@kernel.org, daniel.lezcano@kernel.org Cc: Zhang Rui , Lukasz Luba , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Simona Vetter , Guenter Roeck , Joel Stanley , Andrew Jeffery , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Benson Leung , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Avi Fishman , Tomer Maimon , Tali Perry , Patrick Venture , Nancy Yuen , Benjamin Fair , Heiko Stuebner , Thierry Reding , Jonathan Hunter , Bjorn Andersson , Konrad Dybcio , Amit Daniel Kachhap , Viresh Kumar , Neil Armstrong , Amit Kucheria , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org Subject: [PATCH v4 02/10] thermal/core: Add devm_thermal_cooling_device_register() Date: Tue, 26 May 2026 16:08:03 +0200 Message-ID: <20260526140802.1059293-14-daniel.lezcano@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526140802.1059293-12-daniel.lezcano@oss.qualcomm.com> References: <20260526140802.1059293-12-daniel.lezcano@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3551; i=daniel.lezcano@oss.qualcomm.com; h=from:subject; bh=k8cNf6pQ9FgDrZOTphnMGI85hDwnR2f4A1GS/R7x154=; b=owEBbQGS/pANAwAIAagyI4oqT+hPAcsmYgBqFalFjOu/Eupq0yeBqZgLiBN5RiMieKlkrkVaa mvJy6hAKNCJATMEAAEIAB0WIQQafc3hhXPRY1XIeySoMiOKKk/oTwUCahWpRQAKCRCoMiOKKk/o T2beB/0Skz8U9R4RpW/ZwuLg1Msk6E/CpxJVCNrxGtGCA1yAUTVsrxnGSwTJNdKTK9GQteR9xJn wfFhAJsjSemve5Zv2+JenlljY99q8+Lj6e5Z+pRg+lGAkKY4RXt8T+OLui3+L+moEU6nYqMpKFX 37XcK36B3TOST1QIPD+whdavFLB/obSCz+EcmjevyxXYy9D9Yvdyr6i9iKzvsSfyy2jxAPOFues k8geiSjPdDUA4Vj7o5nf51lgZ3Y/AqZpn2qD4JWU1JvUgu4dwVHY3e/OYoNAveqr4+y0c6ldSwZ 4n0l0fPWHGTVYZ/7yRgbNblviqnGVyRiBhB2Rauoifw7S1zV X-Developer-Key: i=daniel.lezcano@oss.qualcomm.com; a=openpgp; fpr=24D626F253BE9E87E6CE5BF48FF4B8D271675527 Content-Transfer-Encoding: 8bit X-Proofpoint-GUID: rVKfRVq3fQC9AuKq3FoYt9GtPNIybvjW X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTI2MDEyMSBTYWx0ZWRfXxh83WKMtqbVZ q66mt4JNjmKp8d8gpubWnbkRW1DxSB7Ee9YO1ry3HP2Q0AduiNS2wp5PFjyWYLmogxTbdXQe/fY 3NDeVlzwPEEKMb0UmNs4rStuTK7BcrPSd4exhNLSdGsZEJHO0UGYDvxUC/S3QKmw4dMOWlvhq8s 9sVeO6iL+rp+Fa2R/N4TKXMbLkdsllLV/Ac2Oa7piH1d6Hk+NgCeUwgj4tHEpB9r8nhl3fTpItI b7Y8Job7bCPvc0mmQwJYJ26yURNOJ8uHjz1oYaKhjGqpXHg5JZSa7Sc1ND7COEXlPLD6aMOfFca sq3kbpW97JLRRIIwoaecjVwPjdD9LY8E8IAueXpQ1jrbl8PsYtdAWc1QzdrElNVCnih382Ds+I0 r0rZdP3SghMrLl8FQgMckdfglZS8sQnujddEDNLY+fBGFAt6g3DxG2I4FZYeoh9PFUEXnyOiOwp qKgX7K2sHrkzulSG45A== X-Authority-Analysis: v=2.4 cv=VPHtWdPX c=1 sm=1 tr=0 ts=6a15a96c cx=c_pps a=lkkFf9KBb43tY3aOjL++dA==:117 a=xqWC_Br6kY4A:10 a=NGcC8JguVDcA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=3WHJM1ZQz_JShphwDgj5:22 a=EUspDBNiAAAA:8 a=SnQRsxpfvtI8DkFpaL8A:9 a=k4UEASGLJojhI9HsvVT1:22 X-Proofpoint-ORIG-GUID: rVKfRVq3fQC9AuKq3FoYt9GtPNIybvjW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.125,FMLib:17.12.100.49 definitions=2026-05-26_03,2026-05-26_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 spamscore=0 clxscore=1015 impostorscore=0 lowpriorityscore=0 adultscore=0 malwarescore=0 priorityscore=1501 bulkscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2605130000 definitions=main-2605260121 Introduce a device-managed variant of the non-OF cooling device registration API. This complements devm_thermal_of_cooling_device_register() and allows non-device-tree users to register cooling devices with automatic cleanup tied to the device lifecycle. The helper relies on devm_add_action_or_reset() to release the cooling device via thermal_cooling_device_release() on driver detach or probe failure. This keeps the API consistent across OF and non-OF users and avoids manual cleanup in error paths. Signed-off-by: Daniel Lezcano --- drivers/thermal/thermal_core.c | 35 ++++++++++++++++++++++++++++++++++ include/linux/thermal.h | 7 +++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 0b3db889d60d..bb4fc3ff2ad5 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1173,6 +1173,41 @@ devm_thermal_of_cooling_device_register(struct device *dev, } EXPORT_SYMBOL_GPL(devm_thermal_of_cooling_device_register); +/** + * devm_thermal_cooling_device_register() - register a thermal cooling device + * + * @dev: a valid struct device pointer of a sensor device. + * @type: the thermal cooling device type. + * @devdata: device private data. + * @ops: standard thermal cooling devices callbacks. + * + * This function will register a cooling device. This interface + * function adds a new thermal cooling device (fan/processor/...) to + * /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind + * itself to all the thermal zone devices registered at the same time. + * + * Return: a pointer to the created struct thermal_cooling_device or an + * ERR_PTR. Caller must check return value with IS_ERR*() helpers. + */ +struct thermal_cooling_device * +devm_thermal_cooling_device_register(struct device *dev, const char *type, void *devdata, + const struct thermal_cooling_device_ops *ops) +{ + struct thermal_cooling_device *cdev; + int ret; + + cdev = thermal_cooling_device_register(type, devdata, ops); + if (IS_ERR(cdev)) + return cdev; + + ret = devm_add_action_or_reset(dev, thermal_cooling_device_release, cdev); + if (ret) + return ERR_PTR(ret); + + return cdev; +} +EXPORT_SYMBOL_GPL(devm_thermal_cooling_device_register); + static bool thermal_cooling_device_present(struct thermal_cooling_device *cdev) { struct thermal_cooling_device *pos = NULL; diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 0ddc77aeeca2..fc3f4a098370 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -253,8 +253,11 @@ void thermal_zone_device_update(struct thermal_zone_device *, struct thermal_cooling_device *thermal_cooling_device_register(const char *, void *, const struct thermal_cooling_device_ops *); struct thermal_cooling_device * -thermal_of_cooling_device_register(struct device_node *np, const char *, void *, - const struct thermal_cooling_device_ops *); +devm_thermal_cooling_device_register(struct device *dev, const char *type, void *devdata, + const struct thermal_cooling_device_ops *ops); +struct thermal_cooling_device * +thermal_of_cooling_device_register(struct device_node *np, const char *type, void *devdata, + const struct thermal_cooling_device_ops *ops); struct thermal_cooling_device * devm_thermal_of_cooling_device_register(struct device *dev, struct device_node *np, -- 2.43.0