From patchwork Wed Jan 18 21:11:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 45502 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2566033wrn; Wed, 18 Jan 2023 13:13:46 -0800 (PST) X-Google-Smtp-Source: AMrXdXsckR5Rui0yn0wEf33/njnEvGHk9xQju9zPTiTyRZS0xCpF5Mlqx6JuG81Wb0lu9SUfPbDo X-Received: by 2002:a05:6402:380b:b0:499:e665:8683 with SMTP id es11-20020a056402380b00b00499e6658683mr9847069edb.2.1674076425892; Wed, 18 Jan 2023 13:13:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674076425; cv=none; d=google.com; s=arc-20160816; b=NzPXNgHqGGoLa+UyhDIQY27LAvCJQckLBaoiQMTRKuaFyoNZSA13rqnjwsM3WnSzLD ZDu/ni1E/tBCGnBezi0RGO6nH3qS0FTKGrJNrlUrGnvBiQBFoVSIoXGb/UeH4uoLZ0qq U/icN9s+A2QNnxIASx0L+MNPPRwFRZJe/Dgd3UplSnyYF5L3Fqw1WW43pWdnGKLlFONZ fWtUrNPSIwEiU/eRsQVpTcPt2SpsP2tll0e4JIJdhvnpVmfig0zAtXLPAylJQOaCaj7o oNBa/lPA+1ZF5bZrlBBuypHFpMiJ7HdJU+sMWp4M66Tu2e0tMa+RSVGouPAxwR/Agysu jflw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=OIWV5/U3aD1TS48D9ejtlC9TCaF31IO7b6c4b9EuDIo=; b=QqIPyOMWzZXcc6YGSv8ChW/V3iND/ugF1wKBB71/oQwz8B1bJzFeI+kIG4sTb3ZBZI tapCxO6OxU4RvJBE7K45wyr74Ffjn41WGGueWbnNuJM1P4qZvTBrtOMF2JZecwBa07pJ kxryMWUVqkDIukzIa6kR0fJSAPhsJ99+0PnhZk3tks0Mwnxd85nz/CaL5GX1MXIZJmzh mFglaV9Y2bTask2ToUb7uegVK1C22dFSpJLcTJ5O+jY9apbuTMeDW/d1+GLYyZ7xxUd1 u/6FjNti+OHcanh5FUO9gougI1QzDM+8wJGW1DYD6E7Y05MLQNjIiGSNwVlHwdLZWYt6 rrog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=t2fk2cgG; 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 m19-20020a056402431300b0049e1788de1fsi12920058edc.236.2023.01.18.13.13.22; Wed, 18 Jan 2023 13:13:45 -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=t2fk2cgG; 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 S230407AbjARVMm (ORCPT + 99 others); Wed, 18 Jan 2023 16:12:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230436AbjARVMT (ORCPT ); Wed, 18 Jan 2023 16:12:19 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADD79611CA for ; Wed, 18 Jan 2023 13:11:32 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id e19-20020a05600c439300b003db1cac0c1fso806158wmn.5 for ; Wed, 18 Jan 2023 13:11:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=OIWV5/U3aD1TS48D9ejtlC9TCaF31IO7b6c4b9EuDIo=; b=t2fk2cgG7M8bLDNWGKnT74AMDXx9E7iJEn9H+QmUp0+M0KACJvTvbTetxbS1f1oUd3 9jw5nLahBjhiptCacAmD/eFVtuLZGCAug65HWqH1hKtev9u9Y7ClMJ2P2ryogs8y5COz J4COS/80Luf8tEiCAeyVTEOmyPLJljb5zHOmr0/PoI45uddUhg5h55DpEnr6o9s+O/4K l2/WxJFKOFyFJq0t4kxEuR4ylykxgWq4HNXl4EW2vDbAWr8EL9c1eIVfIGXNAYhrC7i3 sywuHTSDuLMFj6VyDEDPXKOZSmbCY0DKoQjOT03XENss5p/WBLc1fKKhLJQSYL2lw2bS aLrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=OIWV5/U3aD1TS48D9ejtlC9TCaF31IO7b6c4b9EuDIo=; b=yqwVT2FOcB02qufc4AJ/tBvBVSJjlsIcS0pshbjiB0L1JAOTXkuu3SokebOEXh1xSQ Gu9lfLiTxDfymE4geTR4eMCPLFvz6U6m+aGqdYOu1HZ00iCBzki0hNk5gtr+FznoLqgW QR5UOe4f1ECZ5ptPNej5k2IvxRM6LtNulEcAnWt/XN3j3a9xKFHVDYWy8J1i8ULzoAyY AoMi9ab8FzJFFaTl/XxZ9qgA6Hr5/asKAl9idCxQSYoqlcRPUMeXHd5TsD8J1DxjVpa6 R+yJTRcw+iuu1xnd7Dhq52pa5mBsuABQBynmxKUvOOBY+H8vi8QPSWbJK158BRtGu3ki vUWw== X-Gm-Message-State: AFqh2kpqwC6YErg0l8i+bG06SDc0CavH15eKPKTP8Irt1p5km6Gfh17f Hn9JSk9VuBuOe6Qt+jgXpme++sCP5b2K1BLh X-Received: by 2002:a05:600c:35c1:b0:3db:1424:e781 with SMTP id r1-20020a05600c35c100b003db1424e781mr3207421wmq.23.1674076291099; Wed, 18 Jan 2023 13:11:31 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id l27-20020a05600c2cdb00b003d99da8d30asm3198835wmc.46.2023.01.18.13.11.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 13:11:30 -0800 (PST) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: linux-pm@vger.kernel.org, Amit Kucheria , Zhang Rui , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 1/5] thermal/core: Fix unregistering netlink at thermal init time Date: Wed, 18 Jan 2023 22:11:19 +0100 Message-Id: <20230118211123.111493-1-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 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?1755396362588232369?= X-GMAIL-MSGID: =?utf-8?q?1755396362588232369?= The thermal subsystem initialization miss an netlink unregistering function in the error. Add it. Signed-off-by: Daniel Lezcano --- 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 Wed Jan 18 21:11:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 45504 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2566379wrn; Wed, 18 Jan 2023 13:14:36 -0800 (PST) X-Google-Smtp-Source: AMrXdXt4N5Hwot6isjn7JqPDSALG2KA29stAg2+jnivTx353Hy6ZfYM4r8dJxOWT1TjyZTvS1WfO X-Received: by 2002:aa7:cb55:0:b0:499:c2c7:1534 with SMTP id w21-20020aa7cb55000000b00499c2c71534mr19076386edt.24.1674076475946; Wed, 18 Jan 2023 13:14:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674076475; cv=none; d=google.com; s=arc-20160816; b=VjMm0vbh2TWRhKE8b8H837Bqd3CgxiyhHFhmYYQdLPdqQN82t4ZWD/TQg4UC8Qdomz UIXjUHwRmWwVXi3FwmxDW1za0wCm7LZwdv1uu6RdolQheuuoTSjvSei0UXlEpMTSdC0s WwQoyopI9u37A36qKzVpOXUXUZAwUFqCZrx6Z5ErFOQK6N8YbGDWAJa6NIl5/R0a2ajS PYBlGzyj3BE1ZFs+Q50L83jcvif1ScsLNdmiZUvsBqrMB+NTGSh9C7imEFYeKT+ZDiMO Pf0pDXQADPduDkLIgncBHRs6NQGsABvEZbymit5GOcUSKqhciVZvTeJH77j1n27RPLAD R+gw== 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=x1YgCO8PxA4QpCkw3QOu225Jsl3xb82uW0n/TtQQ8Q50ZfF7EBxvjnABN+2dHwFX7Z BXbakI+TU6kl8Z9u2WPQbr6NPOURRzfJQJd5Weoa4ADzsQFLGvklqCAyZFQv4wq4SVdv cUmyfknuV92gKJWPLo758MS5V7o3EIp411wcaXh3h41GXbpy93vdCZDatF6MJFTvYwvG xZw0nE4TzecfxW5ZWtv2jCs5pleE0QpsDx0Bqi3KQKJ3PwgGA18eAsnXut4O0wcFSRsR w7YkXah55MgwK7e7QavMkKhqvwYuir/nDIdGtt54vNUrZsUJvyKwCLxP6tVGEzCV5oZX Eh3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="xPY9/cO5"; 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 t23-20020aa7d717000000b004534c6c4bd7si34061742edq.433.2023.01.18.13.14.12; Wed, 18 Jan 2023 13:14:35 -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="xPY9/cO5"; 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 S230373AbjARVMu (ORCPT + 99 others); Wed, 18 Jan 2023 16:12:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230342AbjARVMU (ORCPT ); Wed, 18 Jan 2023 16:12:20 -0500 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A29B5613E7 for ; Wed, 18 Jan 2023 13:11:33 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id d4-20020a05600c3ac400b003db1de2aef0so199584wms.2 for ; Wed, 18 Jan 2023 13:11:33 -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=xPY9/cO5/EuIVs4Cgywdqilx19aJ2ZwAnPWfnirCJG4lFggV0Tb+b9mheTBTeC6huW uUahlnhzRxpClnTTBHinSMDk8vc1ykObxIGduJ4/Bi5J9Zt657ed7U0HW7Ln7DFnQ8TU v5UUYzT2+UZjx8Phie1RHQaUQdNvQGfvHwklMMnhTgOKNPLBRcBtE3oGWHh5SovVdl43 2a+ZAKuaCoS1UViHY+ljukwjO7xdJAJ2Eiy3xf/Fnh7/F8pLfJTEJUFtcD58xXujdbFj SNAX3QrB8xX2svHYV/FINCWrt02JyzknaHIVgJMVFRTXA8HWKugswWxff4psoameKk93 zbBg== 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=GzPyZqtmZj2eczsLqy0iFALV/2UhhONrIfakNyBtJnkzuKGWW4ziaJ5q1duPKvjZcr YqW3VeoEJ2D530LQEO736RGIZmL3tB1lh8QPyPOfMpKiB0KUPi9Uca8DpN0PxLwNEKSI IPGJrUD8v934O1ZrY0IjY96Mij+kqU+7cUjWH7sl4NPk7cEkGfssxEWpyplFpBtjFkks f6hSlRxBaCW+tw3FzOsfG8L1TZKkjC3i3K59/4kmufvVmCmsqVgZ43I8KDCKAnexJ9kD QxlmF6JhfLpA1OLAFB+xZUNLGZrbQppUF2XroB1z8H15EOqhFKlP667qYVw3qLkMypTO Auxg== X-Gm-Message-State: AFqh2krrDVO1DH3DqHLbOytcI/IBLsjde2qPqrEhfs5Vm/O8YikNuncW Pq5GW781/7z3zY8vlayYoEvEsg== X-Received: by 2002:a05:600c:3ba9:b0:3da:b40f:7a55 with SMTP id n41-20020a05600c3ba900b003dab40f7a55mr14931741wms.6.1674076292174; Wed, 18 Jan 2023 13:11:32 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id l27-20020a05600c2cdb00b003d99da8d30asm3198835wmc.46.2023.01.18.13.11.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 13:11:31 -0800 (PST) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: linux-pm@vger.kernel.org, Amit Kucheria , Zhang Rui , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 2/5] thermal/core: Remove unneeded ida_destroy() Date: Wed, 18 Jan 2023 22:11:20 +0100 Message-Id: <20230118211123.111493-2-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230118211123.111493-1-daniel.lezcano@linaro.org> References: <20230118211123.111493-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?1755396414966490630?= X-GMAIL-MSGID: =?utf-8?q?1755396414966490630?= 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 --- 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 Wed Jan 18 21:11:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 45503 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2566368wrn; Wed, 18 Jan 2023 13:14:35 -0800 (PST) X-Google-Smtp-Source: AMrXdXuU0soLKCcczJbh7+WkTMkUKEPo8pJ+AAnE77zFA+zIwVmq0csxqULJvigm4g49K28LnlEt X-Received: by 2002:a17:906:a28c:b0:7c1:540c:e214 with SMTP id i12-20020a170906a28c00b007c1540ce214mr4499617ejz.47.1674076475124; Wed, 18 Jan 2023 13:14:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674076475; cv=none; d=google.com; s=arc-20160816; b=fmNiY1wr3wOJdIqjYXT1cQjEZS8GzxKNUEMzbVTDaqETASzP7JEmqiz3rkM9CCpO49 8DPbZWscb4LOdKx/ThibOYwdpFCJfpCjhbbF7W6d3P4BI0U3LCS9YcMPCxJ8x7lq22Sg WMwrAfyzGJaNC62ZrjOA+Xtmih+KVBggK70wujn7g7u6Y/UkzrjU/0KOKUUmehWG58tf biv+j/KtvJCseHHeNfMKUDT9eAf/mZEMgzb2LWw+ZqPqQcqe8Y1TpC0wtVTuPMiW9W6f yCTl7Y5dJyeJNQe2webyp5veaBXpP2SFBOUD+L2ZjdaoAF+2KoY0HDQ3BC4VxDP4bnFv aS3g== 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=mv1QMfQ8+R0tx+YAwMOp8de+sCeOb8qyTorZfg+2pN8=; b=U3TfS/ywOTFa4cEeq18greIHZyetrbR4WONE6GUCk5i7QXo3poMlk5wjHms6zzwDUM 5NrLLYeiAgDHfuJWac7YoWy1A9Oru0UHr/EACFiJnN2oEeZuzkqOsfSW0lroDPY5i/RT PmYPz5KHS7TvbK9hpDVsisRBEtGSE8TvjpyyWCSCfHgY9eVDZrJxPlzRdJxPpZgEElU/ AuwNWXHJBiumRGNAV1MkafA7vPZvDTkHjy/AiJPEN78fJ0OdeYZ266hrs0e2MDNcr9PS WRfkegeCz0qBxcb8FSf8d4TGWr+fWkVvrBidA2V9RAVSjmcs1nw740TqBOOkko6gb5nt KpBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=k3WuuZ1F; 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 wu2-20020a170906eec200b0078e1d213831si36257463ejb.122.2023.01.18.13.14.09; Wed, 18 Jan 2023 13:14:35 -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=k3WuuZ1F; 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 S230477AbjARVMq (ORCPT + 99 others); Wed, 18 Jan 2023 16:12:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230443AbjARVMU (ORCPT ); Wed, 18 Jan 2023 16:12:20 -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 AF76E611EA for ; Wed, 18 Jan 2023 13:11:34 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id g10so130171wmo.1 for ; Wed, 18 Jan 2023 13:11:34 -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=mv1QMfQ8+R0tx+YAwMOp8de+sCeOb8qyTorZfg+2pN8=; b=k3WuuZ1FdgzBGZGuHPHyrzGbvPMvuhO1xbq16DV12VumlZUanpXElBkLHbk1HgCpb4 aFrLqQWwlzFyRm+M+Qx/60pZpfyzcU0Y4FXOUMT69WH+Zyfmy7JzETS8/6KQjLjMjya4 XZAIpvHFciPB4c64lEGldGgwAGcTX+/fOYWm/dljxxi85sIixRnIOqPsG3WrcOOoVR8+ b1kZyGVe0UQszOg9JNtyyJl3bjU0T9gvIlH8mHfrQxrbVtqUvo9/n8AbRRFS2AM7VrIG SvDBw4S1ziev2Ikm8/45YhUS3pVxs/mjU/97pm22BoPfUgpOqpbEq4t/Dct6t3aM5ncu i0IQ== 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=mv1QMfQ8+R0tx+YAwMOp8de+sCeOb8qyTorZfg+2pN8=; b=SzBSY5GCtDPIQ0knD6geDsgYA+up+H/p0bIItXg6PI46pG00MNzn4b2mmSad4qEs6U k6qBj4VX+kU3Atohnk9UxsRrPv/Ietfc0/tH1EC6KKDxDAeneZI84H3MuujyqNbTM0YA LYkOtgU/owHV5w/Q0cBDBNYcJFIrCmkz2I/8MBXB+0oDN9BxqBfhGjoIMGM+RdBBi1YO v2NI+cSWRs7FsHmZDF72Flels+cZ7AknQe8h8dzptGTNWoBdysQB8RAyhx2ZsiM98EK8 feryTk7aOgGkXLFBpYpt+CUoKxQ/mNdlISj5BwIqHK9EI3/YFfJmLp7slcAx/a4qtOJz nEEg== X-Gm-Message-State: AFqh2krHEQ+JIcgWHJ7oK0mp9d08omRo6iNYPSqypaR9WY3BKOyCm3SL BnSmziP4CmXcbjdZ5+t9rUDqOA== X-Received: by 2002:a05:600c:4f8d:b0:3d3:3d1b:6354 with SMTP id n13-20020a05600c4f8d00b003d33d1b6354mr4129660wmq.3.1674076293181; Wed, 18 Jan 2023 13:11:33 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id l27-20020a05600c2cdb00b003d99da8d30asm3198835wmc.46.2023.01.18.13.11.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 13:11:32 -0800 (PST) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: linux-pm@vger.kernel.org, Amit Kucheria , Zhang Rui , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 3/5] thermal/core: Remove unneeded mutex_destroy() Date: Wed, 18 Jan 2023 22:11:21 +0100 Message-Id: <20230118211123.111493-3-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230118211123.111493-1-daniel.lezcano@linaro.org> References: <20230118211123.111493-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?1755396414215086331?= X-GMAIL-MSGID: =?utf-8?q?1755396414215086331?= If the thermal framework fails to initialize, the mutex can be used by the different functions registering a thermal zone anyway. We should not destroy the mutexes as other components may use them. Signed-off-by: Daniel Lezcano --- drivers/thermal/thermal_core.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index fad0c4a07d16..ea78c93277be 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1602,7 +1602,7 @@ static int __init thermal_init(void) result = thermal_netlink_init(); if (result) - goto error; + return result; result = thermal_register_governors(); if (result) @@ -1623,9 +1623,7 @@ static int __init thermal_init(void) thermal_unregister_governors(); unregister_netlink: thermal_netlink_exit(); -error: - mutex_destroy(&thermal_list_lock); - mutex_destroy(&thermal_governor_lock); + return result; } postcore_initcall(thermal_init); From patchwork Wed Jan 18 21:11:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 45506 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2567020wrn; Wed, 18 Jan 2023 13:15:51 -0800 (PST) X-Google-Smtp-Source: AMrXdXslkG1opM0VY8mYN0d2YHxrNzPesECpV6Qg0IpTgCMSTfR9TNycWHkVeV6yOHAi5FsPh1yp X-Received: by 2002:a17:906:68d3:b0:84d:2d75:5fa7 with SMTP id y19-20020a17090668d300b0084d2d755fa7mr8071340ejr.50.1674076551386; Wed, 18 Jan 2023 13:15:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674076551; cv=none; d=google.com; s=arc-20160816; b=fvY7wfJzVO2dY+X/peCsQclK/yvTMG5622F4tmLXoHUgS45/b54OY/veDMVt9V4HmR wOvKhFlJUtxlpbN7ZoUQnxiBNR6eVhz50oH+sseqJZVeHcNMGytX7mQyw4PIanh4sHd5 PqYGUooC28lJHVBg/zhJsVKAqR7Gt0L/AmhXao76JMdKgvacIaB3OmWpOPfgBUbQT0tx D1FyzC5JqLDOPFk8lq9tQvSENFSuMY97mZCYRl3pAnXzZqCNaWagGDYfScgJwNNWKu3F M9KBwTaCO8Eet/V4/7Cyy7vE3OtzpkWFBXENIJvnOFsKVPpycGMfcViLxTOmwyvDJaoD Lxow== 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=czMzL6kIhV4Lb2a6vI6vNG2OVDMVswqlGOcmWeG9QLs=; b=MQq67+JzgQtheh1rTv2irtToYvlHR8/wtPdVsKsgo3zBIAAuawMkUYPzilpNpdkRSj iQms82iJ0HcLAN0o9NaXozTrJ5vydnaZg8uopft6oDg98YQ5MuE4N+0ut5UHlmlEzsuZ spCL8o23ptOh3/LmNROdN+y0y4+C3WkvOXOU0UJRUUnv+p5ntK5Ja35z0ym5UF0kvbMs K7xv097CX53sjz4Rd+nQS4Ko9HVj6CYpX8PkrCsaUUL+GqgWmEd1jQ4vfaHLMhAfI6X/ SwmZCngNGUpEDUydSzK7MPiUKQ4rBf1s4GJngSSgleKjaUlLz0RXK3Hz6FTcen5yp9yY V7IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="n/f8AV81"; 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 hq15-20020a1709073f0f00b008728cb7cdd2si6810511ejc.30.2023.01.18.13.15.02; Wed, 18 Jan 2023 13:15:51 -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="n/f8AV81"; 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 S231124AbjARVMx (ORCPT + 99 others); Wed, 18 Jan 2023 16:12:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230403AbjARVMW (ORCPT ); Wed, 18 Jan 2023 16:12:22 -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 6BADF58991 for ; Wed, 18 Jan 2023 13:11:36 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id f25-20020a1c6a19000000b003da221fbf48so2540922wmc.1 for ; Wed, 18 Jan 2023 13:11:36 -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=czMzL6kIhV4Lb2a6vI6vNG2OVDMVswqlGOcmWeG9QLs=; b=n/f8AV81ZpzXzkzaTO4afge6ISxxEQ2AbSsPn1xhklXQ9QLzKXQuZe8WONSK3MEs6w vc/QjUf1OTJZ/e/zO5E0Z7AW+XPIizJPhIIF9XM+VwI74czCVmPVA35y7eVvKaNSjNGT t5AlXqEOEB4x7mSKCJCFriPOwXUWgfNyAnOJvu4cEwwjtRuN6VahJ741q7pbSU+qYPvN jqGfFq6K1QajXTYF+hrtnRzqjUTO4pE+GJ9OfFioQMIcgcLqkSGlRzT0AwvY/wykL2SD HaX4Km+H6vjtRxLmKMR3A+7xE6BiPxwZQ1i4LTZ7qAsQWSf7QixL45Cd0i93AZyiuE8H Vj+w== 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=czMzL6kIhV4Lb2a6vI6vNG2OVDMVswqlGOcmWeG9QLs=; b=MXPl3+wtb0zivZIs7IZtDyGBDCT7pYVORKpxTvFEx9KI+ui0QDv+1HQO4xwPgCqeuU VZTsrCp1+k10XwKNvEszqfzOoYMp/SL7n7FxzRu9PMspozsrIpIERp0od+NzAWwR5ux7 V8Lg+vtCzZFNPr9s2pEbTRsCPoJoQTSVPghk1gYxIsEc/MDbbdCn69NUolj+sIoYBffK 5mb5redB10FnJ279QGfAS9yrhFQV90M4tvsXCCoav6f85QaZ5adOP8PQAllxItBfG6WN cGMsToWIel18VUOWUVG+eYZb12rNpK+AKyMvFns+SH6JAQrSV0KBzZMPfsM05x2plxSB 23IQ== X-Gm-Message-State: AFqh2kqSfoG/yFyfI/XaTlj3NcyFZBtJs1UEsl6sQZzfDAXuR3CT67Du LaRux/G2DvOYvabgPlTyPS5Pmk0lD4bCs9tp X-Received: by 2002:a7b:c4d0:0:b0:3d1:f6b3:2ce3 with SMTP id g16-20020a7bc4d0000000b003d1f6b32ce3mr8297143wmk.35.1674076294839; Wed, 18 Jan 2023 13:11:34 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id l27-20020a05600c2cdb00b003d99da8d30asm3198835wmc.46.2023.01.18.13.11.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 13:11:34 -0800 (PST) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: linux-pm@vger.kernel.org, Amit Kucheria , Zhang Rui , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 4/5] thermal/core: Move the thermal trip code to a dedicated file Date: Wed, 18 Jan 2023 22:11:22 +0100 Message-Id: <20230118211123.111493-4-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230118211123.111493-1-daniel.lezcano@linaro.org> References: <20230118211123.111493-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?1755396494132172389?= X-GMAIL-MSGID: =?utf-8?q?1755396494132172389?= 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. Signed-off-by: Daniel Lezcano --- drivers/thermal/Makefile | 4 +- drivers/thermal/thermal_core.c | 87 -------------- drivers/thermal/thermal_helpers.c | 62 ---------- drivers/thermal/thermal_trip.c | 181 ++++++++++++++++++++++++++++++ 4 files changed, 183 insertions(+), 151 deletions(-) create mode 100644 drivers/thermal/thermal_trip.c diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile index 60f0dfa9aae2..2f0db88240b5 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 ea78c93277be..d0577685085a 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_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..2ef61ff7ffc3 --- /dev/null +++ b/drivers/thermal/thermal_trip.c @@ -0,0 +1,181 @@ +// 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 *, + int trip_id, void *), + void *data) +{ + int i, ret; + struct thermal_trip trip; + + for (i = 0; i < tz->num_trips; i++) { + + ret = __thermal_zone_get_trip(tz, i, &trip); + if (ret) + return ret; + + ret = cb(&trip, i, 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; +} From patchwork Wed Jan 18 21:11:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 45505 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2567021wrn; Wed, 18 Jan 2023 13:15:51 -0800 (PST) X-Google-Smtp-Source: AMrXdXsGcEJsQYKeUNUFzrLIB5mg/fyxsQsPALZZ+y1vtq14Heb1dZT9GxTqnaSAXRCmVL9j9Oee X-Received: by 2002:a17:907:3a83:b0:84d:2f2a:b158 with SMTP id fh3-20020a1709073a8300b0084d2f2ab158mr18715679ejc.11.1674076551537; Wed, 18 Jan 2023 13:15:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674076551; cv=none; d=google.com; s=arc-20160816; b=Rutxn052dvAhRWuu9hKTlj4mwYx1czXvzSC9Z6freBlcGyB7HGbOxnkRFV89f15JAU g+e8Sm+JtOXGCkiFCPmdWcJdumMIIoy3QTqXngqmEcaesmje6wULhuvvSmzxigOFlHDe rbVKCZQUoIn2S9IMcEjsv05u+2m1pkzM+GPdt9X4C8DHRWE9fxGQClqEyniCJjUlxlHP VvgvNbCM0nS0D1kcDGZ9FuGmXJHoKaK7VS2Ig+dV7qZhOISuUycNpYddpOBD+37Dsjn0 yMeJ0Q/GV51s6DjQg4HERmnHg+2QSRHuy6LpEFNQz8wO990Dzz0yj1tNWjskfwcANJrV wUGw== 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=MbZTt1nKV5Kzktb6N/J9c4cwx0dyU8TgWnYTyorPexI=; b=WyEWTfsPstYHAg7cOEFDedQ7McN4pYgn7q77DDtVO4KmSRAICnT9+7ZjZb0W6CBgCr HspbQz87dEIhvNEwXvYaqpA4MAuw8LHLavbTzYceWQSjTupMointKzSYdWUbPRHbCkiN Yj4Dj9dFYF74SGlRmk83YVOW6BtZs0N12+1ZA2mN1H5rWnHAUc1tEd2r23d3qX3n4uiW mz6PyfTQRywnZUvuMTxkpV9T698kgdmAJgck00qzJ90uIvSpEWT4LRdogr8kvzryOsfu nRHFAo8iC2w0lmAQGdXnMorZiX7Av+z7bYe396vHIU0mfB6vQixsyXQPtpx9cQauwCMF 1NAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XJ8fx8qg; 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 eg27-20020a056402289b00b0049e0aafc4ecsi10902910edb.154.2023.01.18.13.15.05; Wed, 18 Jan 2023 13:15:51 -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=XJ8fx8qg; 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 S231130AbjARVM6 (ORCPT + 99 others); Wed, 18 Jan 2023 16:12:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230444AbjARVMW (ORCPT ); Wed, 18 Jan 2023 16:12:22 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BB75604AE for ; Wed, 18 Jan 2023 13:11:37 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id c10-20020a05600c0a4a00b003db0636ff84so2568069wmq.0 for ; Wed, 18 Jan 2023 13:11:37 -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=MbZTt1nKV5Kzktb6N/J9c4cwx0dyU8TgWnYTyorPexI=; b=XJ8fx8qgbtpA2yj0y7FDGXBOtSmezFrHxGnXGFlbiODLkUf1IVM49rmBXyp0rn47tv HBh/kgCib3lMDyYaGvUIyBbK612QqakthrpNqxNgXaF8M1e6rdQt4cTXFpHn+d9ns7GD GQjd2CJnXol3dlHTZI1jBhzMbsjA4pYvqya5yxSNTpakqnenN4jbnrA0vwtGtQ9SHe3G wJtD7Jto/KRbAfrjcRGSVGwlG7irYUy0hiZmuuYwvIFH7Ih+N/uBA4Q/Z212ZZMD0EUW H8aRUWUREmRNjm0KcPY8jFdZ8wA/BeFCNVRZ3AeDYXK5A7HyejQrWrZR1mEFD+UQa8oE yHnQ== 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=MbZTt1nKV5Kzktb6N/J9c4cwx0dyU8TgWnYTyorPexI=; b=jAeRbCrTUV9BS2oCs/HGzqTu9RPPGixw+MJ7G4+znQ230WU0fCgvBrjwTAzOkbcN09 hxl610rkULPQmLONoQ8I3ecU8HnXG1n40KkbdpqioO37DxjHaLKOzkPBJ5uBgErkCTDt deilxXHPVhabPlCCowvTBAQ2W4HVtUC3x+BQBC3M4Le/fNZEJO5YhEzO2NdUHUSXOWIm /OiGeRkOobeqPcappCRNxS4fg8dXds0ymPSVXvnk9tcQdfrz1DBn5s1qIPy6P4vPohDO UYFZeuSg5fGk5uZ8DP6rYWGGKWmAx1yFxT151CxIL7JgHJRA70CDhBcEEYBkBeGsAsF7 gFAQ== X-Gm-Message-State: AFqh2kowGkYWh3F/pKuRL7hWA0xFYJeMkqaP3FSR8DQ3y81UIRVneayC PvsWn1/Do3eGK4cR5+BvTpOmkA== X-Received: by 2002:a05:600c:6014:b0:3da:2032:6c0f with SMTP id az20-20020a05600c601400b003da20326c0fmr16523812wmb.31.1674076295926; Wed, 18 Jan 2023 13:11:35 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id l27-20020a05600c2cdb00b003d99da8d30asm3198835wmc.46.2023.01.18.13.11.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 13:11:35 -0800 (PST) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: linux-pm@vger.kernel.org, Amit Kucheria , Zhang Rui , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 5/5] thermal/core: Sort the trip points when registering a thermal zone Date: Wed, 18 Jan 2023 22:11:23 +0100 Message-Id: <20230118211123.111493-5-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230118211123.111493-1-daniel.lezcano@linaro.org> References: <20230118211123.111493-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?1755396493945027823?= X-GMAIL-MSGID: =?utf-8?q?1755396493945027823?= Most of the drivers are converted to use the generic thermal trip points. They register a thermal zone with an array of trip points. However, we don't have the guarantee the trip points are ordered. The main goal of moving to the generic trip points is to provide a common structure, ordered, so we can fix sanely how the trip points are crossed. As a reminder, the detection is fuzzy when the trip points are defined with hysteresis values, we can have duplicated or inconsistent trip events. This change sorts the trip points array when it is registered with the thermal zone. The direction of the ordering is descending because when we browse the trip points, we want to check the highest trip points first as they are higher in temperature, thus higher in priority. A pr_info() trace tells the trip points have been ordered if it appears they are not sorted initially. Signed-off-by: Daniel Lezcano --- drivers/thermal/thermal_core.c | 3 +++ drivers/thermal/thermal_core.h | 1 + drivers/thermal/thermal_trip.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index d0577685085a..394770591771 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1255,6 +1255,9 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t if (num_trips > 0 && (!ops->get_trip_type || !ops->get_trip_temp) && !trips) return ERR_PTR(-EINVAL); + if (trips && thermal_trip_sort(trips, num_trips)) + pr_info("Thermal trips sorted for thermal zone '%s'\n", type); + tz = kzalloc(sizeof(*tz), GFP_KERNEL); if (!tz) return ERR_PTR(-ENOMEM); diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h index 26350206a98d..4688107fda1d 100644 --- a/drivers/thermal/thermal_core.h +++ b/drivers/thermal/thermal_core.h @@ -117,6 +117,7 @@ void __thermal_zone_set_trips(struct thermal_zone_device *tz); int __thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id, struct thermal_trip *trip); int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp); +int thermal_trip_sort(struct thermal_trip *trips, int num_trips); /* sysfs I/F */ int thermal_zone_create_device_groups(struct thermal_zone_device *, int); diff --git a/drivers/thermal/thermal_trip.c b/drivers/thermal/thermal_trip.c index 2ef61ff7ffc3..924998f09a5a 100644 --- a/drivers/thermal/thermal_trip.c +++ b/drivers/thermal/thermal_trip.c @@ -9,6 +9,34 @@ */ #include "thermal_core.h" +/* + * The trip points must be ordered in the descending order so when we + * browse the trip points we will hit the critical, hot and then the + * passive/active trip points. The critical trip point being the first + * one to be handled. + */ +int thermal_trip_sort(struct thermal_trip *trips, int num_trips) +{ + struct thermal_trip tt; + int sorted = 0; + int i, j; + + for (i = 0; i < num_trips; i++) { + + for (j = i + 1; j < num_trips; j++) { + + if (trips[i].temperature < trips[j].temperature) { + tt = trips[i]; + trips[i] = trips[j]; + trips[j] = tt; + sorted++; + } + } + } + + return sorted; +} + int __for_each_thermal_trip(struct thermal_zone_device *tz, int (*cb)(struct thermal_trip *, int trip_id, void *),