From patchwork Mon Jan 23 15:27:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 47223 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1674706wrn; Mon, 23 Jan 2023 07:41:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXsmheC+caZGkPKOeaaXkLV4w2GFhHDMZirMRoREFbPaSMa9osS2pybtNXgZPD2SlSo4zjEl X-Received: by 2002:aa7:db8b:0:b0:49b:b274:b816 with SMTP id u11-20020aa7db8b000000b0049bb274b816mr26408126edt.37.1674488489577; Mon, 23 Jan 2023 07:41:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674488489; cv=none; d=google.com; s=arc-20160816; b=ZYg77Iw2V5gLY+JpgvF0SL2Ka7i/+ERYsjYlkvohHL3OOSNyYMBaI67Tv+J9cbNl/6 n45VFLIHKeoopAS2gT5OQtj8a6YP0QFqEPvfsLoebcMPIzJtoc6CVjr+xBDe1svfSRyt HAuY3MAps5vDSpRdOcV/r0AKSz5RvTAvU42Nzgl+85/g7Xc+exEI+jpV39UN/Zz/UctJ FCuBqIEMCrI/H6eOKtTe12d6xdAB652lNO7A1Ytczgj1J0Ac8Fcpq+oDwhQ7hZZ9B3sM 3BG9wT6xmDGPEHKzhTy3uVJCA/KZevpYUQXSjiigfr37ON+mt3H2hnQI7aywvEFUlt9A BpwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OIWV5/U3aD1TS48D9ejtlC9TCaF31IO7b6c4b9EuDIo=; b=hkgQ4vjXQ0EMxzvmExD6ND5MDwyrd3pi6J5UUmhcL/xBjAtx8SyaDGU+jgvmTKrt1/ Znm2JZxohixdLPK6GM4VPdwye4ARnfeX2n6TJpH4zBhQCM0UivqyZSpU/UG8vo71RF3v 0UF0VLDJCq1qTijJt02jkFxVB5itBON/MVBLBTIz0bg6L7c7hNz5yh16BYkRNXO3AFFa 5G+cDk3bZEE2OgY/n8lMGfuTOvV2CWp/u21WeDHX17hYlPXtSax5gxiAa4MgV4lx4WPS z0wscHMBGh9OLK9dMtWlFDByJlMyz7iurwehZDRg6p7NQD6O/r23SCF5GC/6eahDuxTR 8nyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=olV4vJ06; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m8-20020a056402510800b0048ea96d245asi18188896edd.267.2023.01.23.07.41.06; Mon, 23 Jan 2023 07:41:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=olV4vJ06; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232089AbjAWP2X (ORCPT + 99 others); Mon, 23 Jan 2023 10:28:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232012AbjAWP2U (ORCPT ); Mon, 23 Jan 2023 10:28:20 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79BEB1F4BC for ; Mon, 23 Jan 2023 07:28:18 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id o17-20020a05600c511100b003db021ef437so8835284wms.4 for ; Mon, 23 Jan 2023 07:28:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=OIWV5/U3aD1TS48D9ejtlC9TCaF31IO7b6c4b9EuDIo=; b=olV4vJ064212iGgO5jY7yyTvCfRLgc3Q515NIOQqAVJlywstBPrpDpKx9JF5R5CM6l WqDXjoSTyewV2vMJDur1Rk5xUTdRqx1sW7kR0Qadtln5Boyyc0N1Kzy5gKiXud3Rc/T0 R0pVpjCQjjNuoFzom8pnoFVzFnbG5BfuJmJNHPLxqbmd0LRJq1FiB4TWJDxlPElzifVj ELLDg5WS+0zzl+RvJsgtUa0fSbDJ0Lokw6ymExUBgftIQvvMMKxOUXUu8bWXi/ZYybH2 VOcM/kxTkEJvsaYeQCcGMgws6g6nesnLEcOtGWdOMiiCFfIRU7ax6gPx+4SgbvSSr430 H3Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OIWV5/U3aD1TS48D9ejtlC9TCaF31IO7b6c4b9EuDIo=; b=WeWxu+p1k4HMsu2trv5yOwwzDiesIi7+Y42DwIgBwCn3No+RGmRxw5kpqoxjH/Uivo Q9QXteT/YC6dx8Z+i02O7QgzzfR1JYCj2TTS/hcC0TP1qmyzPF0grUogvLxPGgeuoIQT IhwieVqcFUZ246VGGwZuPN4/gsGadcFgnCYqn2F268nsr3gOpFpafzldyA3kU96RzqLv bivaddB1Y26pVeede8eAJXq0Ig2DNOBxZi+4n7kiC3KGo9f/yMAeGMcm5cnJvPHduph0 YbIKOlLPLXVxOddZTh4vUznr5R7FkEDRlTN/tCaF5qBYSH8f5kAOXq82/64SmRaoAHCO N6vQ== X-Gm-Message-State: AFqh2koKOF9wRQBhlLhmxygZTtI9PtNnfWdfkpaT428SF8cdFEv48sZH 6tLov5R3+omEe43Fg0iMlfsX8w== X-Received: by 2002:a05:600c:2255:b0:3da:f950:8168 with SMTP id a21-20020a05600c225500b003daf9508168mr23235744wmm.35.1674487696977; Mon, 23 Jan 2023 07:28:16 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id t13-20020a1c770d000000b003db1ca20170sm10673096wmi.37.2023.01.23.07.28.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 07:28:16 -0800 (PST) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rui.zhang@intel.com, rafael@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Amit Kucheria Subject: [PATCH v2 1/3] thermal/core: Fix unregistering netlink at thermal init time Date: Mon, 23 Jan 2023 16:27:54 +0100 Message-Id: <20230123152756.4031574-2-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230123152756.4031574-1-daniel.lezcano@linaro.org> References: <20230123152756.4031574-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755828442774192652?= X-GMAIL-MSGID: =?utf-8?q?1755828442774192652?= The thermal subsystem initialization miss an netlink unregistering function in the error. Add it. Signed-off-by: Daniel Lezcano Reviewed-by: Zhang Rui --- drivers/thermal/thermal_core.c | 4 +++- drivers/thermal/thermal_netlink.c | 5 +++++ drivers/thermal/thermal_netlink.h | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index d9a3d9566d73..fddafcee5e6f 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1606,7 +1606,7 @@ static int __init thermal_init(void) result = thermal_register_governors(); if (result) - goto error; + goto unregister_netlink; result = class_register(&thermal_class); if (result) @@ -1621,6 +1621,8 @@ static int __init thermal_init(void) unregister_governors: thermal_unregister_governors(); +unregister_netlink: + thermal_netlink_exit(); error: ida_destroy(&thermal_tz_ida); ida_destroy(&thermal_cdev_ida); diff --git a/drivers/thermal/thermal_netlink.c b/drivers/thermal/thermal_netlink.c index 75943b06dbe7..08bc46c3ec7b 100644 --- a/drivers/thermal/thermal_netlink.c +++ b/drivers/thermal/thermal_netlink.c @@ -699,3 +699,8 @@ int __init thermal_netlink_init(void) { return genl_register_family(&thermal_gnl_family); } + +void __init thermal_netlink_exit(void) +{ + genl_unregister_family(&thermal_gnl_family); +} diff --git a/drivers/thermal/thermal_netlink.h b/drivers/thermal/thermal_netlink.h index 1052f523188d..0a9987c3bc57 100644 --- a/drivers/thermal/thermal_netlink.h +++ b/drivers/thermal/thermal_netlink.h @@ -13,6 +13,7 @@ struct thermal_genl_cpu_caps { /* Netlink notification function */ #ifdef CONFIG_THERMAL_NETLINK int __init thermal_netlink_init(void); +void __init thermal_netlink_exit(void); int thermal_notify_tz_create(int tz_id, const char *name); int thermal_notify_tz_delete(int tz_id); int thermal_notify_tz_enable(int tz_id); @@ -115,4 +116,6 @@ static inline int thermal_genl_cpu_capability_event(int count, struct thermal_ge return 0; } +static inline void __init thermal_netlink_exit(void) {} + #endif /* CONFIG_THERMAL_NETLINK */ From patchwork Mon Jan 23 15:27:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 47224 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1674723wrn; Mon, 23 Jan 2023 07:41:31 -0800 (PST) X-Google-Smtp-Source: AMrXdXujSVD40nX4wKa8MaVMOFJD/GMKqoglEXAxxl4VEuPZxFf3Wdxt47IHZzflg88r1seplDR3 X-Received: by 2002:a17:907:a056:b0:870:7e7d:97a2 with SMTP id gz22-20020a170907a05600b008707e7d97a2mr26288899ejc.66.1674488491124; Mon, 23 Jan 2023 07:41:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674488491; cv=none; d=google.com; s=arc-20160816; b=EKmZRUfOk9RIGH6ZICeOi7DQ9AuhNKoxHipUsUIGz5fAxWAwVYml00vYe78RaGIJLv uBZ5vwN5kZlaLZYkVQfAhWelufiokluUw3gjLcqJS0vwAGBfiJomEWTXcdE7K4wNAOMn eJf3anYvUAC0mL7uUTXmcu6wsZYaOYBk0iPjhJvZdB1kN5gc2ARui0U6Zg2BUmCGYuEt zNd2hCWNY3r0dESzX22aHeyCEzUIuPGfwfiatojw+1dARNHoyNBmsDNReavU+HhmQ7xc oCEnK42mD4iB1w7xpH7tLReNuZhdJl9Bux+KS07vCY9fPoLc1vyEXoCZcqme7Hqy8KhS OXNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hCSbK/tUS4YMZH0NcLQxGFkztwrDFcL8VnBPGZktFY8=; b=P5LNpQGK/p/j24GD3XpngNPZ3h6B8aOyOIyL4IAMdZSDuoMePKgJNuC7upfIDtOzO2 Wz9WAnFqHgD7kYUB5n8OQ7lV5VV0ZP6I1F0TSVrrXc+UzyiWdtE0wxvDjR9LVQYX73Ko FhkJOea5FIRW8NHM2PROvspLs+F8HwH1EaWu9HPXUmdt99y6lH/clUPn915fofdd9ba9 kEm0w4pF9h6ctAVsqotm0tJSI/FwD5XRUYp3EI0Bp6yO68bMoE8BhCzZCL/dPhXAgkgG Y+Y2+9agba7gOVthSx+RT/eJAHfjMfUjsjPn+rIpMUCJumouyU+tnN0ldFZbWoJLylH9 6PiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uyaRiBmI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hw9-20020a170907a0c900b008774ec3fe91si21453977ejc.647.2023.01.23.07.41.07; Mon, 23 Jan 2023 07:41:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uyaRiBmI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232251AbjAWP2Z (ORCPT + 99 others); Mon, 23 Jan 2023 10:28:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232168AbjAWP2V (ORCPT ); Mon, 23 Jan 2023 10:28:21 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A99975247 for ; Mon, 23 Jan 2023 07:28:19 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id l8so9308095wms.3 for ; Mon, 23 Jan 2023 07:28:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=hCSbK/tUS4YMZH0NcLQxGFkztwrDFcL8VnBPGZktFY8=; b=uyaRiBmICBscn5Hvad+35Hy9+6kvUZMcyuWmCN6ldtS0KNu7c9HY0LDYJ1AwewYgDM kb1h3iTr1di9kumeJgH/g/EPDztoTRFe1XSTlaVGtE2RJPmYA44NTD9n7wMpjq9YDi1Z in66J8z9Iyik0qM/+Om942KRYa9f51CJCwvtgz70+lSy1iLyjriGJ1JtYcub70DLj+eg 7ocU9iGyG7B6EaBa/T08NMVjCJbY1D3xRgceevr58wqeALKg5DC6vNoE7OTT4M3R+fGF kimqAwIxO8upbHfOXwxyy7Y7lr1OOONEItI/YFZiZH67Jr9flZoDYyTbQRhkO5x4hs60 464g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hCSbK/tUS4YMZH0NcLQxGFkztwrDFcL8VnBPGZktFY8=; b=BkzaeQ5cqgOUf8QpMoY+1SQYDoyZL6WjDkNrJTWvQpDvxaBESaFYrG+SGS3+Ua345d ej0zbVqXtoO1qkAxlkOG+09/tJEiHly8k8ZJdwBAkarhjHeCRZJH7Z0fIEevWChV2NXQ t2xBfv5OvHaCPV0kdi3s8ChP5d4O7r89z9btjZ4/U2iej0dCkPZeZDZgiC8qWOVAmiF5 Vq+XictTWYVWZYbjdqBW2nRxeRiqqixeCpUQthZYzjxH2zkyfKBPnI2e/5faWuS353lf vO6u3ZHPB+GO1QiY/wd+CKfGwlslZTC91AOB3OTQx2ME9QnEuaA5r7Rf6WbavOpD//mD 5D4Q== X-Gm-Message-State: AFqh2kpMKzS7fbcF+rW0o1V/zDGwJTBfvGLCUQlwsy1UpA9xglnjlCQ3 cJJgORIYRbWyFpNHoVRS+AC/qg== X-Received: by 2002:a05:600c:510d:b0:3da:f719:50cd with SMTP id o13-20020a05600c510d00b003daf71950cdmr23287652wms.18.1674487697983; Mon, 23 Jan 2023 07:28:17 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id t13-20020a1c770d000000b003db1ca20170sm10673096wmi.37.2023.01.23.07.28.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 07:28:17 -0800 (PST) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rui.zhang@intel.com, rafael@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Amit Kucheria Subject: [PATCH v2 2/3] thermal/core: Remove unneeded ida_destroy() Date: Mon, 23 Jan 2023 16:27:55 +0100 Message-Id: <20230123152756.4031574-3-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230123152756.4031574-1-daniel.lezcano@linaro.org> References: <20230123152756.4031574-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755828444124181219?= X-GMAIL-MSGID: =?utf-8?q?1755828444124181219?= As per documentation for the ida_destroy() function: "If the IDA is already empty, there is no need to call this function." The thermal framework is in the init sequence, so the ida was not yet used and consequently it is empty in case of error. There is no need to call ida_destroy(), let's remove the calls. Signed-off-by: Daniel Lezcano Reviewed-by: Zhang Rui --- drivers/thermal/thermal_core.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index fddafcee5e6f..fad0c4a07d16 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1624,8 +1624,6 @@ static int __init thermal_init(void) unregister_netlink: thermal_netlink_exit(); error: - ida_destroy(&thermal_tz_ida); - ida_destroy(&thermal_cdev_ida); mutex_destroy(&thermal_list_lock); mutex_destroy(&thermal_governor_lock); return result; From patchwork Mon Jan 23 15:27:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 47225 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1674838wrn; Mon, 23 Jan 2023 07:41:47 -0800 (PST) X-Google-Smtp-Source: AMrXdXsJwmpK2aX/gjq3rsBhVTkHdK4jenKXPkOHKw3KA3qA1V8hb6RBrjGmCGPF2GWJMvQGcd+o X-Received: by 2002:a05:6402:413:b0:498:b9ea:1894 with SMTP id q19-20020a056402041300b00498b9ea1894mr23516459edv.15.1674488507357; Mon, 23 Jan 2023 07:41:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674488507; cv=none; d=google.com; s=arc-20160816; b=fRn3S7FeozO7P/Mt/RfVFZ8gji/Sj3cbFZZDglzRyAApQnc/akjyQUEgpXCNx4YR06 qf9DUwbnrxd+79QJkWm+/mJZTFysTF6xuu590GwIDppk1XktWUx5A7xI1ACbb+SUtpbt 4PTyHAH2MjLEix6+XZi9BToVdiQGnpwnYdoqkc7aHhVWiQST20MIO59BIuZpPDnnqUw5 hEfWmLp+qxfAvMCEncM5aOSrF5CheIl/Ds9JnxkxwPODVnd6wxzuVtCWdYlhGuO5HTOi ZIzgPKG7xqTHJHf85nZ7HmYI64oFj9BmXZRjSG6UcqYdL5YP40x6esmL2U5D/+MJlfxj EKVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PODENPNbVWjL8xQyhgyl+t+P0w0tYfl3GahnpsmHGfc=; b=YMezZ17KmmNZHlLac/zQsLej54ktAgwcgLXXkRj4i9rLFMeQX4J8Ezdaw7GgMM9mGo /I5QKzA2iOyacVb+jYiVuVlFYXX1uQl4Dtj7kqBBMwarab4NZUkW4WE8DQQ4U337uDzA tIUf+vEwef1SU2QFDr6pJp3Q+6OK6owARHdI8GyJs7acEyKqdg/ubTPd0hH+ruL54LOZ qD/hd+fSblvQAtneOTE7AN7Vcuo1iWqcJ71FimzZojRa4jYnwPJY5H2wXxmX799YG/pN 7HSXYIQ4EKJHgwa38nqfTEP1C+jbrW3fGaeXDuPPkAEXY+KmcB2qg4BvLBU0zw4Ggrsy DXmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rBe6MWIu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i10-20020a50870a000000b0049b63f6cd51si37253969edb.182.2023.01.23.07.41.23; Mon, 23 Jan 2023 07:41:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rBe6MWIu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232369AbjAWP2e (ORCPT + 99 others); Mon, 23 Jan 2023 10:28:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232350AbjAWP2b (ORCPT ); Mon, 23 Jan 2023 10:28:31 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0BB22202A for ; Mon, 23 Jan 2023 07:28:21 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id m15so9309815wms.4 for ; Mon, 23 Jan 2023 07:28:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=PODENPNbVWjL8xQyhgyl+t+P0w0tYfl3GahnpsmHGfc=; b=rBe6MWIuBU4PCPosy8wmdLnAW+6r7YikSJA5xpfDvJzaopUx7GneUOOzFqT9WpC6Zm w6bQKEy7zRI/udwTUnkYPw96lYwXM8Pf67jtjjPSHaMNoboQrVuixb/HaIUgkhL8QFk4 7ZV4G2vh/5vzA2V6zwW7i/DItMiUA0UTkitFGhS8OxDvjgKob8yyTgPHmy6/WY8bpLuN mJzSVPvjqSreJ3jsdELvRgK+jG+6nJ483IsVpGRBUo0fvukuT07KQVenLCJAOuPb2RDk adjSfKfbqAYL/frRh3KkHsAkKTDll2XM0Q98sMey6w6wYQWfWtTBOVowWDup4NozKtoA 1cnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PODENPNbVWjL8xQyhgyl+t+P0w0tYfl3GahnpsmHGfc=; b=tmrIejEbEhtcTe7CbjZgHnQJkd2lS6dWDEUVSB4/0kLXsUKifbgJvbM8mRjh3r/E45 T1279CTAELNiuNcsz02x7xgXavZpYH9r0f4mQ/5ZcfZ8XAHiPLRtma1m7oI7nRIXHxTd 73WZUKId/BChzLeMJ31in9pnsElN9mOzRoIgpfehx92HKwk/UEBZ+LW3MsqKm0Bd+f6i QRJ2DU5DFNBVOS9YLvHYDyYLyJgr+XXHqO1XNIvquVvGoqVnzs5MTOrD8cr+qzMrQ7bg 4F9Nb7kWt0guxQhPpUq+2eeXIlqg6RBAlgIAwnGVQDDHV80XSO0paXXlKjOyY2GzHgCz 98lQ== X-Gm-Message-State: AFqh2kqvJWFgiXglACkXXrnbWP3eEe0uahH0cJrWQw0a3HlHSaaD3yU3 /6XvvH5O1XGuHX4Y1At+TphPsw== X-Received: by 2002:a05:600c:1c01:b0:3c6:e63e:23e9 with SMTP id j1-20020a05600c1c0100b003c6e63e23e9mr24804179wms.24.1674487700334; Mon, 23 Jan 2023 07:28:20 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id t13-20020a1c770d000000b003db1ca20170sm10673096wmi.37.2023.01.23.07.28.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 07:28:19 -0800 (PST) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rui.zhang@intel.com, rafael@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Amit Kucheria Subject: [PATCH v2 3/3] thermal/core: Move the thermal trip code to a dedicated file Date: Mon, 23 Jan 2023 16:27:56 +0100 Message-Id: <20230123152756.4031574-4-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230123152756.4031574-1-daniel.lezcano@linaro.org> References: <20230123152756.4031574-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755828461108927408?= X-GMAIL-MSGID: =?utf-8?q?1755828461108927408?= The thermal_core.c files contains a lot of functions handling different thermal components like the governors, the trip points, the cooling device, the OF cooling device, etc ... This organization does not help to migrate to a more sane code where there is a better self-encapsulation as all the components' internals can be directly accessed from a single file. For the sake of clarity, let's move the thermal trip points code in a dedicated thermal_trip.c file and add a function to browse all the trip points like we do with the thermal zones, the govenors and the cooling devices. The same can be done for the cooling devices and the governor code but that will come later as the current work in the thermal framework is to fix the trip point handling and use a generic trip point structure. No functional changes intended. Signed-off-by: Daniel Lezcano Reviewed-by: Zhang Rui --- drivers/thermal/Makefile | 4 +- drivers/thermal/thermal_core.c | 87 -------------- drivers/thermal/thermal_core.h | 4 + drivers/thermal/thermal_helpers.c | 62 ---------- drivers/thermal/thermal_trip.c | 182 ++++++++++++++++++++++++++++++ 5 files changed, 188 insertions(+), 151 deletions(-) create mode 100644 drivers/thermal/thermal_trip.c diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile index 2506c6c8ca83..2faf4651f34a 100644 --- a/drivers/thermal/Makefile +++ b/drivers/thermal/Makefile @@ -4,8 +4,8 @@ # obj-$(CONFIG_THERMAL) += thermal_sys.o -thermal_sys-y += thermal_core.o thermal_sysfs.o \ - thermal_helpers.o +thermal_sys-y += thermal_core.o thermal_sysfs.o +thermal_sys-y += thermal_trip.o thermal_helpers.o # netlink interface to manage the thermal framework thermal_sys-$(CONFIG_THERMAL_NETLINK) += thermal_netlink.o diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index fad0c4a07d16..4ee685043a3e 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1155,12 +1155,6 @@ static void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms *delay_jiffies = round_jiffies(*delay_jiffies); } -int thermal_zone_get_num_trips(struct thermal_zone_device *tz) -{ - return tz->num_trips; -} -EXPORT_SYMBOL_GPL(thermal_zone_get_num_trips); - int thermal_zone_get_crit_temp(struct thermal_zone_device *tz, int *temp) { int i, ret = -EINVAL; @@ -1187,87 +1181,6 @@ int thermal_zone_get_crit_temp(struct thermal_zone_device *tz, int *temp) } EXPORT_SYMBOL_GPL(thermal_zone_get_crit_temp); -int __thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id, - struct thermal_trip *trip) -{ - int ret; - - if (!tz || trip_id < 0 || trip_id >= tz->num_trips || !trip) - return -EINVAL; - - if (tz->trips) { - *trip = tz->trips[trip_id]; - return 0; - } - - if (tz->ops->get_trip_hyst) { - ret = tz->ops->get_trip_hyst(tz, trip_id, &trip->hysteresis); - if (ret) - return ret; - } else { - trip->hysteresis = 0; - } - - ret = tz->ops->get_trip_temp(tz, trip_id, &trip->temperature); - if (ret) - return ret; - - return tz->ops->get_trip_type(tz, trip_id, &trip->type); -} -EXPORT_SYMBOL_GPL(__thermal_zone_get_trip); - -int thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id, - struct thermal_trip *trip) -{ - int ret; - - mutex_lock(&tz->lock); - ret = __thermal_zone_get_trip(tz, trip_id, trip); - mutex_unlock(&tz->lock); - - return ret; -} -EXPORT_SYMBOL_GPL(thermal_zone_get_trip); - -int thermal_zone_set_trip(struct thermal_zone_device *tz, int trip_id, - const struct thermal_trip *trip) -{ - struct thermal_trip t; - int ret; - - if (!tz->ops->set_trip_temp && !tz->ops->set_trip_hyst && !tz->trips) - return -EINVAL; - - ret = __thermal_zone_get_trip(tz, trip_id, &t); - if (ret) - return ret; - - if (t.type != trip->type) - return -EINVAL; - - if (t.temperature != trip->temperature && tz->ops->set_trip_temp) { - ret = tz->ops->set_trip_temp(tz, trip_id, trip->temperature); - if (ret) - return ret; - } - - if (t.hysteresis != trip->hysteresis && tz->ops->set_trip_hyst) { - ret = tz->ops->set_trip_hyst(tz, trip_id, trip->hysteresis); - if (ret) - return ret; - } - - if (tz->trips && (t.temperature != trip->temperature || t.hysteresis != trip->hysteresis)) - tz->trips[trip_id] = *trip; - - thermal_notify_tz_trip_change(tz->id, trip_id, trip->type, - trip->temperature, trip->hysteresis); - - __thermal_zone_device_update(tz, THERMAL_TRIP_CHANGED); - - return 0; -} - /** * thermal_zone_device_register_with_trips() - register a new thermal zone device * @type: the thermal zone device type diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h index 26350206a98d..7af54382e915 100644 --- a/drivers/thermal/thermal_core.h +++ b/drivers/thermal/thermal_core.h @@ -52,6 +52,10 @@ int for_each_thermal_cooling_device(int (*cb)(struct thermal_cooling_device *, int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *), void *thermal_governor); +int __for_each_thermal_trip(struct thermal_zone_device *, + int (*cb)(struct thermal_trip *, void *), + void *); + struct thermal_zone_device *thermal_zone_get_by_id(int id); struct thermal_attr { diff --git a/drivers/thermal/thermal_helpers.c b/drivers/thermal/thermal_helpers.c index 8977d5ddc23c..0f648131b0b5 100644 --- a/drivers/thermal/thermal_helpers.c +++ b/drivers/thermal/thermal_helpers.c @@ -146,68 +146,6 @@ int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp) } EXPORT_SYMBOL_GPL(thermal_zone_get_temp); -/** - * __thermal_zone_set_trips - Computes the next trip points for the driver - * @tz: a pointer to a thermal zone device structure - * - * The function computes the next temperature boundaries by browsing - * the trip points. The result is the closer low and high trip points - * to the current temperature. These values are passed to the backend - * driver to let it set its own notification mechanism (usually an - * interrupt). - * - * This function must be called with tz->lock held. Both tz and tz->ops - * must be valid pointers. - * - * It does not return a value - */ -void __thermal_zone_set_trips(struct thermal_zone_device *tz) -{ - struct thermal_trip trip; - int low = -INT_MAX, high = INT_MAX; - int i, ret; - - lockdep_assert_held(&tz->lock); - - if (!tz->ops->set_trips) - return; - - for (i = 0; i < tz->num_trips; i++) { - int trip_low; - - ret = __thermal_zone_get_trip(tz, i , &trip); - if (ret) - return; - - trip_low = trip.temperature - trip.hysteresis; - - if (trip_low < tz->temperature && trip_low > low) - low = trip_low; - - if (trip.temperature > tz->temperature && - trip.temperature < high) - high = trip.temperature; - } - - /* No need to change trip points */ - if (tz->prev_low_trip == low && tz->prev_high_trip == high) - return; - - tz->prev_low_trip = low; - tz->prev_high_trip = high; - - dev_dbg(&tz->device, - "new temperature boundaries: %d < x < %d\n", low, high); - - /* - * Set a temperature window. When this window is left the driver - * must inform the thermal core via thermal_zone_device_update. - */ - ret = tz->ops->set_trips(tz, low, high); - if (ret) - dev_err(&tz->device, "Failed to set trips: %d\n", ret); -} - static void thermal_cdev_set_cur_state(struct thermal_cooling_device *cdev, int target) { diff --git a/drivers/thermal/thermal_trip.c b/drivers/thermal/thermal_trip.c new file mode 100644 index 000000000000..5ce71f1cb1ba --- /dev/null +++ b/drivers/thermal/thermal_trip.c @@ -0,0 +1,182 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2008 Intel Corp + * Copyright (C) 2008 Zhang Rui + * Copyright (C) 2008 Sujith Thomas + * Copyright 2022 Linaro Limited + * + * Thermal trips handling + */ +#include "thermal_core.h" + +int __for_each_thermal_trip(struct thermal_zone_device *tz, + int (*cb)(struct thermal_trip *, void *), + void *data) +{ + int i, ret; + struct thermal_trip trip; + + lockdep_assert_held(&tz->lock); + + for (i = 0; i < tz->num_trips; i++) { + + ret = __thermal_zone_get_trip(tz, i, &trip); + if (ret) + return ret; + + ret = cb(&trip, data); + if (ret) + return ret; + } + + return 0; +} + +int thermal_zone_get_num_trips(struct thermal_zone_device *tz) +{ + return tz->num_trips; +} +EXPORT_SYMBOL_GPL(thermal_zone_get_num_trips); + +/** + * __thermal_zone_set_trips - Computes the next trip points for the driver + * @tz: a pointer to a thermal zone device structure + * + * The function computes the next temperature boundaries by browsing + * the trip points. The result is the closer low and high trip points + * to the current temperature. These values are passed to the backend + * driver to let it set its own notification mechanism (usually an + * interrupt). + * + * This function must be called with tz->lock held. Both tz and tz->ops + * must be valid pointers. + * + * It does not return a value + */ +void __thermal_zone_set_trips(struct thermal_zone_device *tz) +{ + struct thermal_trip trip; + int low = -INT_MAX, high = INT_MAX; + int i, ret; + + lockdep_assert_held(&tz->lock); + + if (!tz->ops->set_trips) + return; + + for (i = 0; i < tz->num_trips; i++) { + int trip_low; + + ret = __thermal_zone_get_trip(tz, i , &trip); + if (ret) + return; + + trip_low = trip.temperature - trip.hysteresis; + + if (trip_low < tz->temperature && trip_low > low) + low = trip_low; + + if (trip.temperature > tz->temperature && + trip.temperature < high) + high = trip.temperature; + } + + /* No need to change trip points */ + if (tz->prev_low_trip == low && tz->prev_high_trip == high) + return; + + tz->prev_low_trip = low; + tz->prev_high_trip = high; + + dev_dbg(&tz->device, + "new temperature boundaries: %d < x < %d\n", low, high); + + /* + * Set a temperature window. When this window is left the driver + * must inform the thermal core via thermal_zone_device_update. + */ + ret = tz->ops->set_trips(tz, low, high); + if (ret) + dev_err(&tz->device, "Failed to set trips: %d\n", ret); +} + +int __thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id, + struct thermal_trip *trip) +{ + int ret; + + if (!tz || trip_id < 0 || trip_id >= tz->num_trips || !trip) + return -EINVAL; + + if (tz->trips) { + *trip = tz->trips[trip_id]; + return 0; + } + + if (tz->ops->get_trip_hyst) { + ret = tz->ops->get_trip_hyst(tz, trip_id, &trip->hysteresis); + if (ret) + return ret; + } else { + trip->hysteresis = 0; + } + + ret = tz->ops->get_trip_temp(tz, trip_id, &trip->temperature); + if (ret) + return ret; + + return tz->ops->get_trip_type(tz, trip_id, &trip->type); +} +EXPORT_SYMBOL_GPL(__thermal_zone_get_trip); + +int thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id, + struct thermal_trip *trip) +{ + int ret; + + mutex_lock(&tz->lock); + ret = __thermal_zone_get_trip(tz, trip_id, trip); + mutex_unlock(&tz->lock); + + return ret; +} +EXPORT_SYMBOL_GPL(thermal_zone_get_trip); + +int thermal_zone_set_trip(struct thermal_zone_device *tz, int trip_id, + const struct thermal_trip *trip) +{ + struct thermal_trip t; + int ret; + + if (!tz->ops->set_trip_temp && !tz->ops->set_trip_hyst && !tz->trips) + return -EINVAL; + + ret = __thermal_zone_get_trip(tz, trip_id, &t); + if (ret) + return ret; + + if (t.type != trip->type) + return -EINVAL; + + if (t.temperature != trip->temperature && tz->ops->set_trip_temp) { + ret = tz->ops->set_trip_temp(tz, trip_id, trip->temperature); + if (ret) + return ret; + } + + if (t.hysteresis != trip->hysteresis && tz->ops->set_trip_hyst) { + ret = tz->ops->set_trip_hyst(tz, trip_id, trip->hysteresis); + if (ret) + return ret; + } + + if (tz->trips && (t.temperature != trip->temperature || t.hysteresis != trip->hysteresis)) + tz->trips[trip_id] = *trip; + + thermal_notify_tz_trip_change(tz->id, trip_id, trip->type, + trip->temperature, trip->hysteresis); + + __thermal_zone_device_update(tz, THERMAL_TRIP_CHANGED); + + return 0; +}