From patchwork Mon Feb 5 21:14:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 197062 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1174633dyb; Mon, 5 Feb 2024 14:07:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IFiNntBij0+pVT45jVrsjl7Oe0VOPMTA9pQOdKpDhnQga2Ng5xcBuRYbMYbmIc4qUqDfjGZ X-Received: by 2002:a05:6402:b2f:b0:560:8f9:4f61 with SMTP id bo15-20020a0564020b2f00b0056008f94f61mr397479edb.35.1707170876761; Mon, 05 Feb 2024 14:07:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707170876; cv=pass; d=google.com; s=arc-20160816; b=NnmEsAMxDWERJsSGkkTN8KYd0boQF4Sllo9ot8Ns/5rqFzQMR4NY1oLaGzTJwss4C5 d0hVWkuK8VDFmnjIn//Vl1RBMkrLvenT9uSx4yUNGb4lzloCb8j82UdVaZ80U2EvPwVy p5FiZTvGMwj/hedVfwNEPKxuhp31ppKlYVpZWZDLMd1Eaf62S3k6kb5MtJ1Fz3pAxDLq ENB07jEh6Mr3YW0Ja2EQGS0IYTiPGXIj+p/lKuFM01mNDKJU4vp2c3mkEj0yKefAkmA5 kKaHxyZBpakW38yB46s/q7rpCG0PDCKnwnxV1LK3Es98ZZEAX/yikICTbN14HzjSWJRd /wUg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=HmwN93XMvO0jzcSJJkFz1X+KRhd6LvRahxmQvSMr3Lg=; fh=oqLQbW1Q052vb3cg0/IUzOV5/XCECMiNgyyq+L/iF2s=; b=vaXXl35s3QVFX3rTXgcL367f66XeGEcVbT9oCftPk6M3PIGNWWA6izMTSTrjIZriMw zrnyI0lOLE6gbrCKzr/hkhm3DDrcxhp7X8MSk+FE6HFj5+bdtI6hyl9InfA1YM8UEcB3 VASIMpOr3fLjBGaam/ci8sa1CsnsDNdnvY4+dqwd5ftOfztvyQryuZEnnIUcb5vClVtP 3I+Fl94Xj3dWXRCT9lqdt6zRo5g5Tc1kCYGlIQbZMbC7NHMXO7thFGs9OPQnBbI/p3u6 d5gogpPYcUX7A24BPbpsCzv+wZIehL4CG3qhVuhvEbUbe7ODsTaVMghDLvRFWCNwwiTw m7dg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-53973-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53973-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUtY+Jndwqc7P5ZnBfu/HRPwz1flAd/vgym+ive98HY7h+76ceCHswUHNiY9QchuGKbdJO8ViOR84HKzMnZp4Zllvg2aA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id w24-20020a50d798000000b0056016c58691si329625edi.142.2024.02.05.14.07.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 14:07:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53973-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-53973-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53973-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 32A321F2ACDE for ; Mon, 5 Feb 2024 22:07:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F01AE54BCA; Mon, 5 Feb 2024 21:21:22 +0000 (UTC) Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (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 E66BB50246; Mon, 5 Feb 2024 21:21:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707168080; cv=none; b=U5hGBVAG6qeqoNHzUziILs7JKd4REm79Z4h3b5D0D5bQabbQhf4oKncOIdBs4+PkmRwzip8MgZz0bM5J0EUFu2wz82SPbvHJFTR6n3NJwD9FMJKXQ6Cd0ai7BOwCS0bLYD5/Rb82VmdEMnxkW5LLNs2PsCBKAWkbJUwLd7J/UX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707168080; c=relaxed/simple; bh=av3tnbxbDoQCPJZmNhCPyBdCwso6X1qrV0D//DxT7HQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kKrkRN/2GS29ozipooyeS53MeBpFPiV0kY6DooUh9ciKwaoXf8yafCsu5Rt5a7htlUxq5LWCnKpEvZrTeBOtDCpy3MIK+l2ZPcrSax5+Z9gHT/cCMiEzqYK7ChIJXnXezTbHyiFkbPcko8fOba0v2HMOVNeQ2wWrtoby76NU0eU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.4.0) id e244b6757259a813; Mon, 5 Feb 2024 22:21:10 +0100 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id A7E0E669A1B; Mon, 5 Feb 2024 22:21:09 +0100 (CET) From: "Rafael J. Wysocki" To: Linux PM Cc: Daniel Lezcano , LKML , Linux ACPI , Lukasz Luba , Zhang Rui , Srinivas Pandruvada , Stanislaw Gruszka , AngeloGioacchino Del Regno Subject: [PATCH v1 1/6] thermal: core: Store zone trips table in struct thermal_zone_device Date: Mon, 05 Feb 2024 22:14:31 +0100 Message-ID: <5762433.DvuYhMxLoT@kreacher> In-Reply-To: <2728491.mvXUDI8C0e@kreacher> References: <2728491.mvXUDI8C0e@kreacher> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrfedvuddgheehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepledprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=9 Fuz1=9 Fuz2=9 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790098409249185057 X-GMAIL-MSGID: 1790098409249185057 From: Rafael J. Wysocki The current code requires thermal zone creators to pass a pointer to a writable trips table to thermal_zone_device_register_with_trips() and that trips table is then used by the thermal core going forward. Consequently, the callers of thermal_zone_device_register_with_trips() are required to hold on to the trips table passed to it until the given thermal zone is unregistered, at which point the trips table can be freed, but at the same time they are not allowed to access the cells in that table directly. This is both error prone and confusing. To address it, turn the trips table pointer in struct thermal_zone_device into a flex array (counted by its num_trips field), allocate it during thermal zone device allocation and copy the contents of the trips table supplied by the zone creator (which can be const now) into it. This allows the callers of thermal_zone_device_register_with_trips() to drop their trip tables right after the zone registration. Signed-off-by: Rafael J. Wysocki Reviewed-by: Stanislaw Gruszka --- drivers/thermal/thermal_core.c | 16 +++++++++------- include/linux/thermal.h | 10 +++++----- 2 files changed, 14 insertions(+), 12 deletions(-) Index: linux-pm/include/linux/thermal.h =================================================================== --- linux-pm.orig/include/linux/thermal.h +++ linux-pm/include/linux/thermal.h @@ -130,7 +130,6 @@ struct thermal_cooling_device { * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis * @mode: current mode of this thermal zone * @devdata: private pointer for device private data - * @trips: an array of struct thermal_trip * @num_trips: number of trip points the thermal zone supports * @passive_delay_jiffies: number of jiffies to wait between polls when * performing passive cooling. @@ -160,6 +159,7 @@ struct thermal_cooling_device { * @poll_queue: delayed work for polling * @notify_event: Last notification event * @suspended: thermal zone suspend indicator + * @trips: array of struct thermal_trip objects */ struct thermal_zone_device { int id; @@ -172,7 +172,6 @@ struct thermal_zone_device { struct thermal_attr *trip_hyst_attrs; enum thermal_device_mode mode; void *devdata; - struct thermal_trip *trips; int num_trips; unsigned long passive_delay_jiffies; unsigned long polling_delay_jiffies; @@ -193,10 +192,11 @@ struct thermal_zone_device { struct list_head node; struct delayed_work poll_queue; enum thermal_notify_event notify_event; + bool suspended; #ifdef CONFIG_THERMAL_DEBUGFS struct thermal_debugfs *debugfs; #endif - bool suspended; + struct thermal_trip trips[] __counted_by(num_trips); }; /** @@ -315,7 +315,7 @@ int thermal_zone_get_crit_temp(struct th #ifdef CONFIG_THERMAL struct thermal_zone_device *thermal_zone_device_register_with_trips( const char *type, - struct thermal_trip *trips, + const struct thermal_trip *trips, int num_trips, int mask, void *devdata, struct thermal_zone_device_ops *ops, @@ -375,7 +375,7 @@ void thermal_zone_device_critical(struct #else static inline struct thermal_zone_device *thermal_zone_device_register_with_trips( const char *type, - struct thermal_trip *trips, + const struct thermal_trip *trips, int num_trips, int mask, void *devdata, struct thermal_zone_device_ops *ops, Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -1272,10 +1272,13 @@ EXPORT_SYMBOL_GPL(thermal_zone_get_crit_ * IS_ERR*() helpers. */ struct thermal_zone_device * -thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *trips, int num_trips, int mask, - void *devdata, struct thermal_zone_device_ops *ops, - const struct thermal_zone_params *tzp, int passive_delay, - int polling_delay) +thermal_zone_device_register_with_trips(const char *type, + const struct thermal_trip *trips, + int num_trips, int mask, + void *devdata, + struct thermal_zone_device_ops *ops, + const struct thermal_zone_params *tzp, + int passive_delay, int polling_delay) { struct thermal_zone_device *tz; int id; @@ -1322,7 +1325,7 @@ thermal_zone_device_register_with_trips( if (!thermal_class) return ERR_PTR(-ENODEV); - tz = kzalloc(sizeof(*tz), GFP_KERNEL); + tz = kzalloc(struct_size(tz, trips, num_trips), GFP_KERNEL); if (!tz) return ERR_PTR(-ENOMEM); @@ -1344,7 +1347,6 @@ thermal_zone_device_register_with_trips( result = id; goto free_tzp; } - tz->id = id; strscpy(tz->type, type, sizeof(tz->type)); @@ -1354,7 +1356,7 @@ thermal_zone_device_register_with_trips( tz->ops = ops; tz->device.class = thermal_class; tz->devdata = devdata; - tz->trips = trips; + memcpy(tz->trips, trips, num_trips * sizeof(trips[0])); tz->num_trips = num_trips; thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay); From patchwork Mon Feb 5 21:15:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 197060 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1174452dyb; Mon, 5 Feb 2024 14:07:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IHhLWOehK/+wQIcL+xCntKV2XJCobCugvIhK9Ml0wSCRlHD1AYX5PlGxE6O0BAzsDqHukRL X-Received: by 2002:a17:906:5291:b0:a31:7dc1:c7c1 with SMTP id c17-20020a170906529100b00a317dc1c7c1mr497631ejm.65.1707170863143; Mon, 05 Feb 2024 14:07:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707170863; cv=pass; d=google.com; s=arc-20160816; b=Re48evF6rCcT8Pmqgb12vbW794zNj6oO9qCHovY89ofHr/t7oyIyfP9JgmThWHvVph qUGUpRpfqpKctCY2FrN53ZuV29HcAzrUCJqytD1ENaiAxkPnNr5xZTMDCmdOMQttB9Nl HsNFcqADkpZrlXX1iO759eSdZ/H3YOTmNpJFQZfPsHNEOc5D5tcH/qz/FivjQAzoIaqm LwbpiAY6IxMIvtSO803wg62ZBJo3RQ+Nhk1PQ1cAf7u8bmPvSwY+r4sjo5VyvqaDY/F2 Oq2+t2RkLPSIfqT41bSOZHH7rm5l4hnLVkzJXx459msdvFxWXubAHtYXTRLZUcSlzxDh A1GQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=PxpTOlZYCTtPArAaaVNPJGaov3dj9WCuGBlXFSWemgA=; fh=a0vAe0jzNqu58ppITfHe+KvGLhn7bcweyeSm+DZBgtk=; b=wGaNBOLbVTeeH7CFLIjLFVvbzJMt+7MUTlQMHKPt/Iw6as/xQLK1uyTwLXG3Ah2F2C 9QQWgVastWC+86kYacEHfMTp0jnzb93TXdJaq2B1gzZPqbUIEWELstunQhiltYW0KyWI gNSEy7to1Tsl7+ZKl6B2LqYeDPTyohMZICIXbpLMb/+wb4wXr64R0plXQYO9EggWZonI AsII4uoe2B4H3GEcSMmzp8fAYI8E6lSPjBmqnnv77sElOIy/bchIItjW2RIavOAsFmjy ujL2uAFgfhB+yQq/+jvxHgUFHNpl9vLtoy5y80IB+dzPWpyJTEFmfmkXhSCqdRe12hHX +U9w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-53972-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53972-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCX9Q6p1GE8Rxt/OUsZzQ0ZzTDcrhSITYO4LYgJGKvioCuxnDUchEsGPimizgOFNA0uMJkKzoQp6cv1VnksTxLV9QfgkLQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id b26-20020a170906039a00b00a374a28c88dsi283153eja.140.2024.02.05.14.07.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 14:07:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53972-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-53972-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53972-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 88E9D1F26F08 for ; Mon, 5 Feb 2024 22:07:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4E8B353E15; Mon, 5 Feb 2024 21:21:22 +0000 (UTC) Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (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 075CD4F898; Mon, 5 Feb 2024 21:21:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707168079; cv=none; b=J7nNoSBWLTB1BfxaxGGVqo+3/Ucu6NYBDIiBlR3OwqmEohRrtLAt1EdQR83BnoCGYpDCzit+V+0Vs16VPRot0FI0hgqwUdfL50HzNInAIxELOnt+suF58jUroY+alQtnt7RNSteolyUVSl9T8oDpBsEfV3fN531+Ak7Hg1C7XbI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707168079; c=relaxed/simple; bh=DicFjbK0KyRbyqfwIeZfHbnCpPLrOKK0Q5P+e2M32j0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EGUmVsoJ4oVli5Skg2mvkkBlkcxhQe43AOx7BF2E2z8fio+75IWJa63NI7vP+CZmgntNcEa1L1R5lOkXls7IQzX+CZdGmBjZu4tugUuWhGicXkzBN5G/W8oUk8pSEIOPXs46zJag+UNctdTr7gWLjfT4KimZGThlODmZbK07QJU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.4.0) id fc8446dbc483e72d; Mon, 5 Feb 2024 22:21:09 +0100 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id C1FA9669A1B; Mon, 5 Feb 2024 22:21:08 +0100 (CET) From: "Rafael J. Wysocki" To: Linux PM Cc: Daniel Lezcano , LKML , Linux ACPI , Lukasz Luba , Zhang Rui , Srinivas Pandruvada , Stanislaw Gruszka , AngeloGioacchino Del Regno Subject: [PATCH v1 2/6] thermal: ACPI: Discard trip table after zone registration Date: Mon, 05 Feb 2024 22:15:50 +0100 Message-ID: <4905992.31r3eYUQgx@kreacher> In-Reply-To: <2728491.mvXUDI8C0e@kreacher> References: <2728491.mvXUDI8C0e@kreacher> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrfedvuddgheehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepledprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=9 Fuz1=9 Fuz2=9 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790098395273128360 X-GMAIL-MSGID: 1790098395273128360 From: Rafael J. Wysocki Because the thermal core creates and uses its own copy of the trips table passed to thermal_zone_device_register_with_trips(), it is not necessary to hold on to a local copy of it any more after the given thermal zone has been registered. Accordingly, modify the ACPI thermal driver to store the trips table passed to thermal_zone_device_register_with_trips() in a local variable which is automatically discarded after the zone registration. Also make some additional code simplifications unlocked by the above change. Signed-off-by: Rafael J. Wysocki Reviewed-by: Stanislaw Gruszka --- drivers/acpi/thermal.c | 57 +++++++++++++++++-------------------------------- 1 file changed, 20 insertions(+), 37 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -47,6 +47,8 @@ #define ACPI_THERMAL_TRIP_PASSIVE (-1) +#define ACPI_THERMAL_MAX_NR_TRIPS (ACPI_THERMAL_MAX_ACTIVE + 3) + /* * This exception is thrown out in two cases: * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid @@ -112,7 +114,6 @@ struct acpi_thermal { unsigned long polling_frequency; volatile u8 zombie; struct acpi_thermal_trips trips; - struct thermal_trip *trip_table; struct thermal_zone_device *thermal_zone; int kelvin_offset; /* in millidegrees */ struct work_struct thermal_check_work; @@ -451,26 +452,19 @@ fail: return false; } -static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) +static void acpi_thermal_get_trip_points(struct acpi_thermal *tz) { - unsigned int count = 0; int i; - if (acpi_thermal_init_trip(tz, ACPI_THERMAL_TRIP_PASSIVE)) - count++; + acpi_thermal_init_trip(tz, ACPI_THERMAL_TRIP_PASSIVE); for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { - if (acpi_thermal_init_trip(tz, i)) - count++; - else + if (!acpi_thermal_init_trip(tz, i)) break; - } while (++i < ACPI_THERMAL_MAX_ACTIVE) tz->trips.active[i].trip.temp_dk = THERMAL_TEMP_INVALID; - - return count; } /* sys I/F for generic thermal sysfs support */ @@ -662,13 +656,14 @@ static void acpi_thermal_zone_sysfs_remo } static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz, + const struct thermal_trip *trip_table, unsigned int trip_count, int passive_delay) { int result; tz->thermal_zone = thermal_zone_device_register_with_trips("acpitz", - tz->trip_table, + trip_table, trip_count, 0, tz, &acpi_thermal_zone_ops, @@ -823,10 +818,10 @@ static void acpi_thermal_free_thermal_zo static int acpi_thermal_add(struct acpi_device *device) { + struct thermal_trip trip_table[ACPI_THERMAL_MAX_NR_TRIPS] = { 0 }; struct acpi_thermal_trip *acpi_trip; struct thermal_trip *trip; struct acpi_thermal *tz; - unsigned int trip_count; int crit_temp, hot_temp; int passive_delay = 0; int result; @@ -848,21 +843,10 @@ static int acpi_thermal_add(struct acpi_ acpi_thermal_aml_dependency_fix(tz); /* Get trip points [_CRT, _PSV, etc.] (required). */ - trip_count = acpi_thermal_get_trip_points(tz); + acpi_thermal_get_trip_points(tz); crit_temp = acpi_thermal_get_critical_trip(tz); - if (crit_temp != THERMAL_TEMP_INVALID) - trip_count++; - hot_temp = acpi_thermal_get_hot_trip(tz); - if (hot_temp != THERMAL_TEMP_INVALID) - trip_count++; - - if (!trip_count) { - pr_warn(FW_BUG "No valid trip points!\n"); - result = -ENODEV; - goto free_memory; - } /* Get temperature [_TMP] (required). */ result = acpi_thermal_get_temperature(tz); @@ -881,13 +865,7 @@ static int acpi_thermal_add(struct acpi_ acpi_thermal_guess_offset(tz, crit_temp); - trip = kcalloc(trip_count, sizeof(*trip), GFP_KERNEL); - if (!trip) { - result = -ENOMEM; - goto free_memory; - } - - tz->trip_table = trip; + trip = trip_table; if (crit_temp != THERMAL_TEMP_INVALID) { trip->type = THERMAL_TRIP_CRITICAL; @@ -923,9 +901,17 @@ static int acpi_thermal_add(struct acpi_ trip++; } - result = acpi_thermal_register_thermal_zone(tz, trip_count, passive_delay); + if (trip == trip_table) { + pr_warn(FW_BUG "No valid trip points!\n"); + result = -ENODEV; + goto free_memory; + } + + result = acpi_thermal_register_thermal_zone(tz, trip_table, + trip - trip_table, + passive_delay); if (result) - goto free_trips; + goto free_memory; refcount_set(&tz->thermal_check_count, 3); mutex_init(&tz->thermal_check_lock); @@ -944,8 +930,6 @@ static int acpi_thermal_add(struct acpi_ flush_wq: flush_workqueue(acpi_thermal_pm_queue); acpi_thermal_unregister_thermal_zone(tz); -free_trips: - kfree(tz->trip_table); free_memory: acpi_thermal_free_thermal_zone(tz); @@ -966,7 +950,6 @@ static void acpi_thermal_remove(struct a flush_workqueue(acpi_thermal_pm_queue); acpi_thermal_unregister_thermal_zone(tz); - kfree(tz->trip_table); acpi_thermal_free_thermal_zone(tz); } From patchwork Mon Feb 5 21:18:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 197061 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1174530dyb; Mon, 5 Feb 2024 14:07:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IF+arxBjSm3RQzS/n3PcKT7BZPgFOAG8VO0GDDfvkAxhB/5Z99bwRToTrfowkb3/x77gpEQ X-Received: by 2002:a50:ef0d:0:b0:560:965b:d7bd with SMTP id m13-20020a50ef0d000000b00560965bd7bdmr381914eds.35.1707170869540; Mon, 05 Feb 2024 14:07:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707170869; cv=pass; d=google.com; s=arc-20160816; b=vT00G8KYR+WEWo4KWos9qoK4ar8LuNDI9iqB8d32obuKo7KTBaLYCFQ5w6e8mir6Ge ve4pxEYHZ96KEGdyYaxtJ9DBSLknRMMRxyIOTu6dxU5Zs11f41xElRy9ApUALRx2MfL1 2j1zxlevEDQh9hHMDgxIcW27arxhU/Feaz5brlvNwUIDNrzm9wC4eOHc3X+tZibMiQtE 185iTF2/SmZE75SD1Hmkfg+klPqeEESKIjqm0yphCgrLnhR3bDASj+cqPQvGjHBVAgOs nSplyLWf0laUu72z+zPQsjnJiK8bQvsqMzetdoLiisAukanD8/E6sYVUSEj2v/84MrQb rfCg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=y8UGCTsmd0YVHmfNMFFGPG4XW71L1u6H+zR/Q3ZVRSM=; fh=N5/q4kb5vytBFOFIGee6U743KEmdvKqDBD9ZrV/5uEg=; b=xuDyx+wwUq6HxUaLE+yfX8PPWn7IZJsimQKdBdwemdcmsvVACiPlC1uEiYL+d2aIpY PbQpSh0M4JPU4mRSr1e8Exuntzc6DmkgsDmiOgoSA3sO5S+rQ1F+5jc7cCd5gKKQEkP1 RP+3ZQrS4c0NjynvHJKZhPjEbVY2D0M4/R4CgQKZAiTd1ZC6yl5S1E3fJQAl5OIHYKde IJ70/MJEjK3dsdfJlwfTNu8E4b+fqi8ggXw1M3Fw2dkYR65NCwy7HEeZp/zxH//fsnJN bUdTl1HHJvV6l3R9US6k6Ozn63bP9MbAsOYWWntvdMBBySpOIhV+MA2QFrdTVwvs0WSy BMuA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-53970-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53970-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWW4+OYZWCPP9OcIH1dORyG/wP50EMvojorLTKpltyYk1eW/TSIMb8XU9cu24rkHr5YkxitSEemsqWXqhhCTYiNLiJz7Q== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id b25-20020aa7cd19000000b0056023591f8dsi341212edw.318.2024.02.05.14.07.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 14:07:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53970-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-53970-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53970-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E970F1F27A4E for ; Mon, 5 Feb 2024 22:07:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 83E1D53E33; Mon, 5 Feb 2024 21:21:22 +0000 (UTC) Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (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 C09184F8AB; Mon, 5 Feb 2024 21:21:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707168078; cv=none; b=Zyv6N0WSOvmUBdmORiY+DoyELm8jWIKvNdPZjJCtWbjEQsc2WT2xaTZ4NqkxF8XBKLsp9e+deF8oQYMqWwIUdP6vzfugAuzJ55UGKvZsarYh528wc0S9oKYW6ZXKmXBwildXNDuxgFjtyabsFQZOaqHKfV3cedkhsPDiB/yF6Dk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707168078; c=relaxed/simple; bh=nrtyd9qrnjDa31ew4XMhQisV5sxzFmovIBdXrZTqY4c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Orsuk8v0NxnkFRQRCZR3Ed+hcIkUPtJMviMnpRCUjpdQ6+yMJFFsrZ4Mspq58rvLgFd3qqU4Vnv5F5eSx+9UuPFOViNTO21TDVdLC40ZXNRwhhS3/AAc1fkrsSFEt/NUNb37BdcD7mnha9Pmt+KIolvZHnTn2K+DjOQu4tsYZBo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.4.0) id 4a2c3c8163b1cc38; Mon, 5 Feb 2024 22:21:07 +0100 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 1DE03669A1B; Mon, 5 Feb 2024 22:21:07 +0100 (CET) From: "Rafael J. Wysocki" To: Linux PM Cc: Daniel Lezcano , LKML , Linux ACPI , Lukasz Luba , Zhang Rui , Srinivas Pandruvada , Stanislaw Gruszka , AngeloGioacchino Del Regno Subject: [PATCH v1 4/6] thermal: core: Store zone ops in struct thermal_zone_device Date: Mon, 05 Feb 2024 22:18:02 +0100 Message-ID: <1888343.tdWV9SEqCh@kreacher> In-Reply-To: <2728491.mvXUDI8C0e@kreacher> References: <2728491.mvXUDI8C0e@kreacher> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrfedvuddgheehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepledprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=9 Fuz1=9 Fuz2=9 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790098401885100756 X-GMAIL-MSGID: 1790098401885100756 From: Rafael J. Wysocki The current code requires thermal zone creators to pass pointers to writable ops to thermal_zone_device_register_with_trips() which needs to modify the target struct thermal_zone_device_ops object if the "critical" operation in it is NULL. Moreover, the callers of thermal_zone_device_register_with_trips() are required to hold on to the struct thermal_zone_device_ops object passed to it until the given thermal zone is unregistered. Both of these requirements are quite inconvenient, so modify struct thermal_zone_device to contain struct thermal_zone_device_ops as field and make thermal_zone_device_register_with_trips() copy the contents of the struct thermal_zone_device_ops passed to it via a pointer (which can be const now) to that field. Also adjust the code using thermal zone ops accordingly. Signed-off-by: Rafael J. Wysocki Reviewed-by: Stanislaw Gruszka --- drivers/thermal/thermal_core.c | 40 +++++++++++++++++++------------------- drivers/thermal/thermal_helpers.c | 10 ++++----- drivers/thermal/thermal_hwmon.c | 4 +-- drivers/thermal/thermal_sysfs.c | 12 +++++------ drivers/thermal/thermal_trip.c | 4 +-- include/linux/thermal.h | 6 ++--- 6 files changed, 38 insertions(+), 38 deletions(-) Index: linux-pm/include/linux/thermal.h =================================================================== --- linux-pm.orig/include/linux/thermal.h +++ linux-pm/include/linux/thermal.h @@ -182,7 +182,7 @@ struct thermal_zone_device { int prev_low_trip; int prev_high_trip; atomic_t need_update; - struct thermal_zone_device_ops *ops; + struct thermal_zone_device_ops ops; struct thermal_zone_params *tzp; struct thermal_governor *governor; void *governor_data; @@ -318,14 +318,14 @@ struct thermal_zone_device *thermal_zone const struct thermal_trip *trips, int num_trips, int mask, void *devdata, - struct thermal_zone_device_ops *ops, + const struct thermal_zone_device_ops *ops, const struct thermal_zone_params *tzp, int passive_delay, int polling_delay); struct thermal_zone_device *thermal_tripless_zone_device_register( const char *type, void *devdata, - struct thermal_zone_device_ops *ops, + const struct thermal_zone_device_ops *ops, const struct thermal_zone_params *tzp); void thermal_zone_device_unregister(struct thermal_zone_device *tz); Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -356,9 +356,9 @@ static void handle_critical_trips(struct trace_thermal_zone_trip(tz, thermal_zone_trip_id(tz, trip), trip->type); if (trip->type == THERMAL_TRIP_CRITICAL) - tz->ops->critical(tz); - else if (tz->ops->hot) - tz->ops->hot(tz); + tz->ops.critical(tz); + else if (tz->ops.hot) + tz->ops.hot(tz); } static void handle_thermal_trip(struct thermal_zone_device *tz, @@ -493,8 +493,8 @@ static int thermal_zone_device_set_mode( return ret; } - if (tz->ops->change_mode) - ret = tz->ops->change_mode(tz, mode); + if (tz->ops.change_mode) + ret = tz->ops.change_mode(tz, mode); if (!ret) tz->mode = mode; @@ -867,8 +867,8 @@ static void bind_cdev(struct thermal_coo struct thermal_zone_device *pos = NULL; list_for_each_entry(pos, &thermal_tz_list, node) { - if (pos->ops->bind) { - ret = pos->ops->bind(pos, cdev); + if (pos->ops.bind) { + ret = pos->ops.bind(pos, cdev); if (ret) print_bind_err_msg(pos, cdev, ret); } @@ -1184,8 +1184,8 @@ void thermal_cooling_device_unregister(s /* Unbind all thermal zones associated with 'this' cdev */ list_for_each_entry(tz, &thermal_tz_list, node) { - if (tz->ops->unbind) - tz->ops->unbind(tz, cdev); + if (tz->ops.unbind) + tz->ops.unbind(tz, cdev); } mutex_unlock(&thermal_list_lock); @@ -1199,13 +1199,13 @@ static void bind_tz(struct thermal_zone_ int ret; struct thermal_cooling_device *pos = NULL; - if (!tz->ops->bind) + if (!tz->ops.bind) return; mutex_lock(&thermal_list_lock); list_for_each_entry(pos, &thermal_cdev_list, node) { - ret = tz->ops->bind(tz, pos); + ret = tz->ops.bind(tz, pos); if (ret) print_bind_err_msg(tz, pos, ret); } @@ -1224,8 +1224,8 @@ int thermal_zone_get_crit_temp(struct th { int i, ret = -EINVAL; - if (tz->ops->get_crit_temp) - return tz->ops->get_crit_temp(tz, temp); + if (tz->ops.get_crit_temp) + return tz->ops.get_crit_temp(tz, temp); if (!tz->trips) return -EINVAL; @@ -1276,7 +1276,7 @@ thermal_zone_device_register_with_trips( const struct thermal_trip *trips, int num_trips, int mask, void *devdata, - struct thermal_zone_device_ops *ops, + const struct thermal_zone_device_ops *ops, const struct thermal_zone_params *tzp, int passive_delay, int polling_delay) { @@ -1350,10 +1350,10 @@ thermal_zone_device_register_with_trips( tz->id = id; strscpy(tz->type, type, sizeof(tz->type)); - if (!ops->critical) - ops->critical = thermal_zone_device_critical; + tz->ops = *ops; + if (!tz->ops.critical) + tz->ops.critical = thermal_zone_device_critical; - tz->ops = ops; tz->device.class = thermal_class; tz->devdata = devdata; memcpy(tz->trips, trips, num_trips * sizeof(trips[0])); @@ -1439,7 +1439,7 @@ EXPORT_SYMBOL_GPL(thermal_zone_device_re struct thermal_zone_device *thermal_tripless_zone_device_register( const char *type, void *devdata, - struct thermal_zone_device_ops *ops, + const struct thermal_zone_device_ops *ops, const struct thermal_zone_params *tzp) { return thermal_zone_device_register_with_trips(type, NULL, 0, 0, devdata, @@ -1501,8 +1501,8 @@ void thermal_zone_device_unregister(stru /* Unbind all cdevs associated with 'this' thermal zone */ list_for_each_entry(cdev, &thermal_cdev_list, node) - if (tz->ops->unbind) - tz->ops->unbind(tz, cdev); + if (tz->ops.unbind) + tz->ops.unbind(tz, cdev); mutex_unlock(&thermal_list_lock); Index: linux-pm/drivers/thermal/thermal_sysfs.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_sysfs.c +++ linux-pm/drivers/thermal/thermal_sysfs.c @@ -123,8 +123,8 @@ trip_point_temp_store(struct device *dev trip = &tz->trips[trip_id]; if (temp != trip->temperature) { - if (tz->ops->set_trip_temp) { - ret = tz->ops->set_trip_temp(tz, trip_id, temp); + if (tz->ops.set_trip_temp) { + ret = tz->ops.set_trip_temp(tz, trip_id, temp); if (ret) goto unlock; } @@ -174,8 +174,8 @@ trip_point_hyst_store(struct device *dev trip = &tz->trips[trip_id]; if (hyst != trip->hysteresis) { - if (tz->ops->set_trip_hyst) { - ret = tz->ops->set_trip_hyst(tz, trip_id, hyst); + if (tz->ops.set_trip_hyst) { + ret = tz->ops.set_trip_hyst(tz, trip_id, hyst); if (ret) goto unlock; } @@ -250,10 +250,10 @@ emul_temp_store(struct device *dev, stru mutex_lock(&tz->lock); - if (!tz->ops->set_emul_temp) + if (!tz->ops.set_emul_temp) tz->emul_temperature = temperature; else - ret = tz->ops->set_emul_temp(tz, temperature); + ret = tz->ops.set_emul_temp(tz, temperature); if (!ret) __thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); Index: linux-pm/drivers/thermal/thermal_helpers.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_helpers.c +++ linux-pm/drivers/thermal/thermal_helpers.c @@ -26,8 +26,8 @@ int get_tz_trend(struct thermal_zone_dev { enum thermal_trend trend; - if (tz->emul_temperature || !tz->ops->get_trend || - tz->ops->get_trend(tz, trip, &trend)) { + if (tz->emul_temperature || !tz->ops.get_trend || + tz->ops.get_trend(tz, trip, &trend)) { if (tz->temperature > tz->last_temperature) trend = THERMAL_TREND_RAISING; else if (tz->temperature < tz->last_temperature) @@ -75,7 +75,7 @@ EXPORT_SYMBOL(get_thermal_instance); * temperature and fill @temp. * * Both tz and tz->ops must be valid pointers when calling this function, - * and the tz->ops->get_temp callback must be provided. + * and the tz->ops.get_temp callback must be provided. * The function must be called under tz->lock. * * Return: On success returns 0, an error code otherwise @@ -88,7 +88,7 @@ int __thermal_zone_get_temp(struct therm lockdep_assert_held(&tz->lock); - ret = tz->ops->get_temp(tz, temp); + ret = tz->ops.get_temp(tz, temp); if (IS_ENABLED(CONFIG_THERMAL_EMULATION) && tz->emul_temperature) { for_each_trip(tz, trip) { @@ -132,7 +132,7 @@ int thermal_zone_get_temp(struct thermal mutex_lock(&tz->lock); - if (!tz->ops->get_temp) { + if (!tz->ops.get_temp) { ret = -EINVAL; goto unlock; } Index: linux-pm/drivers/thermal/thermal_trip.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_trip.c +++ linux-pm/drivers/thermal/thermal_trip.c @@ -70,7 +70,7 @@ void __thermal_zone_set_trips(struct the lockdep_assert_held(&tz->lock); - if (!tz->ops->set_trips) + if (!tz->ops.set_trips) return; for_each_trip(tz, trip) { @@ -114,7 +114,7 @@ void __thermal_zone_set_trips(struct the * 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); + ret = tz->ops.set_trips(tz, low, high); if (ret) dev_err(&tz->device, "Failed to set trips: %d\n", ret); } Index: linux-pm/drivers/thermal/thermal_hwmon.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_hwmon.c +++ linux-pm/drivers/thermal/thermal_hwmon.c @@ -80,7 +80,7 @@ temp_crit_show(struct device *dev, struc mutex_lock(&tz->lock); - ret = tz->ops->get_crit_temp(tz, &temperature); + ret = tz->ops.get_crit_temp(tz, &temperature); mutex_unlock(&tz->lock); @@ -132,7 +132,7 @@ thermal_hwmon_lookup_temp(const struct t static bool thermal_zone_crit_temp_valid(struct thermal_zone_device *tz) { int temp; - return tz->ops->get_crit_temp && !tz->ops->get_crit_temp(tz, &temp); + return tz->ops.get_crit_temp && !tz->ops.get_crit_temp(tz, &temp); } int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz) From patchwork Mon Feb 5 21:18:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 197072 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1181359dyb; Mon, 5 Feb 2024 14:18:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IG8thpERlheFIAhRibLToNB746TJc4zu5RH/lz9Ac9I9N5Xemm9ITEvB/DLgOVsZZLTYeDa X-Received: by 2002:a05:6a20:268f:b0:19c:8a24:82e1 with SMTP id h15-20020a056a20268f00b0019c8a2482e1mr815986pze.17.1707171537510; Mon, 05 Feb 2024 14:18:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707171537; cv=pass; d=google.com; s=arc-20160816; b=Wwwn1hCz9ml1RzF0G77kjlPTsKEC7LOU8ZrtuyMDJIzlfD7RblmmC9SVQgSLRd/xtk OUsET4el7iSImWrg35bhB3OMPP/EZR5QgHf9D5LEii7RPKzalx67PKPxvFRXwV8DQTnh wOHQmxJkLyNy0B/jhsLpvYmQ894VclVdRiplVPjK6tOKg4om1oE8cztMCJJb8dEe5jTB HiHpPW8DnpoERq/BrdG1dYQL2f4/fUP0te9OiC+hxhwOJo9wX2wekP3XyNo0ZQTQQYO0 amapitOYUycmgPINo86esjalGfFqFrY6SKWxrmmY4yS1t3qPfLAWpRFtyGUjnNv1t5le 3n+g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=RXpWUYEECXs4Z+KxSSiJVxuNvEbaC7VJlSrBRYDoNyg=; fh=UJBVGkRf20miicPtgAUwdP6QKdM5pEyqQewMvctvc60=; b=pKh1WDRad+tpvoy2GbfX5RxdH2PCFiNvk4JSebaZ4EYbYjOpFnz7W1ydPazggDVNAV DmgcudQjNKCklILySaPUoWPmQfGO0RTrath0jOWPWLRa4cnDjd3gCmK5307d3IiHGz56 GS5NW04DmCAC9vLvdoAzwo7lUlcy5vlp9GQhiqXEcmWAygSe0dxBxNS4dflmddiNM4Kw ve0FgXz2vBGli6sggz1osirz7dhO2V942KCnkHooS9AwkjV/5614NtBZ3RAfuzbqFiXF Oed/NS7X2UdV3xgFO9UvaMyyDpjACCvno8T/F3I0YfMPI0593e1X6yI364OebBDe0dRt Icxw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-53969-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53969-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVjOqWNZblugS9rtpsI0s9aGaIv303aAPl183+1UxBCjW1lzmebo86IhNbyTxqbUBGtpFm032vfQIl0g10T/N7rVQY4jw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id m20-20020aa78a14000000b006e04a93e530si431136pfa.293.2024.02.05.14.18.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 14:18:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53969-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-53969-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53969-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id BB1B3298510 for ; Mon, 5 Feb 2024 22:06:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 13DB25103D; Mon, 5 Feb 2024 21:21:20 +0000 (UTC) Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (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 7D69645953; Mon, 5 Feb 2024 21:21:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707168078; cv=none; b=PA81vih3oonVIEzzrjorR4npD+utpYG3IP+ufCGbz3a3EbxcNFJxdDZGqF+ZRhExqu3wTHujELES3fvyMGEgTecUXY5h2eH90SUNy3Erzr16sH5q2RNn/KAUA3EMZSnYAj/EiYLZJ2UMyuXZPNCE4p8R3JqY26bCOtY8rAiuwu0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707168078; c=relaxed/simple; bh=uXW4hfcLlYSYBRzaasWV9Z+OWE7NVuFqC2y1YHfVNro=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GP+GEA0l0NEjzVg+9IfM2Uv25sMNNagVBfYbmvW5aaXcbtJMVXZgOnR8WocipyTSsLZGw7YH+Ury3luesosXu4ct+zk6m6fOeZrS/h4fVkRPZ1RBrhL49hwvYYudeKJXhEldDK7bIpXjfWGhWWIKvZLa8Tl8SgOlCFcKNaH+w4k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.4.0) id 15d0f90479fa4dac; Mon, 5 Feb 2024 22:21:06 +0100 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 4FFE2669A1B; Mon, 5 Feb 2024 22:21:06 +0100 (CET) From: "Rafael J. Wysocki" To: Linux PM Cc: Daniel Lezcano , LKML , Linux ACPI , Lukasz Luba , Zhang Rui , Srinivas Pandruvada , Stanislaw Gruszka , AngeloGioacchino Del Regno Subject: [PATCH v1 5/6] thermal: ACPI: Constify acpi_thermal_zone_ops Date: Mon, 05 Feb 2024 22:18:50 +0100 Message-ID: <13456661.uLZWGnKmhe@kreacher> In-Reply-To: <2728491.mvXUDI8C0e@kreacher> References: <2728491.mvXUDI8C0e@kreacher> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrfedvuddgheehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepledprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=9 Fuz1=9 Fuz2=9 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790099102273203768 X-GMAIL-MSGID: 1790099102273203768 From: Rafael J. Wysocki Because thermal zone operations are now stored directly in struct thermal_zone_device, acpi_thermal_zone_ops need not be modified by the thermal core and so it can be const. Adjust the code accordingly. No functional impact. Signed-off-by: Rafael J. Wysocki Reviewed-by: Stanislaw Gruszka --- drivers/acpi/thermal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -620,7 +620,7 @@ acpi_thermal_unbind_cooling_device(struc return acpi_thermal_bind_unbind_cdev(thermal, cdev, false); } -static struct thermal_zone_device_ops acpi_thermal_zone_ops = { +static const struct thermal_zone_device_ops acpi_thermal_zone_ops = { .bind = acpi_thermal_bind_cooling_device, .unbind = acpi_thermal_unbind_cooling_device, .get_temp = thermal_get_temp, From patchwork Mon Feb 5 21:20:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 197059 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1174008dyb; Mon, 5 Feb 2024 14:07:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IEzNcmWE5dCy3H4+kVz7yDpn567MUpfMGbaWxG8BLS3bG9kdG5UDB4Z/0QLJwDLoOXmATvO X-Received: by 2002:a17:906:4a56:b0:a37:f8dd:ba4 with SMTP id a22-20020a1709064a5600b00a37f8dd0ba4mr526816ejv.41.1707170828744; Mon, 05 Feb 2024 14:07:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707170828; cv=pass; d=google.com; s=arc-20160816; b=BmNLv3n7DR1grZLB8120/DN16VVtweLQ3RCIpbnR2ZSX8G2ZDtRjsnl3f0iP6hI2nz NsFy0FCdjzHsX0asbEfxFcpuqPrCJddyOxZTsxqwHSMOB3o2NKBUVLIrdyWGIMrrNzC3 ucdDKyfz6s7hH70cbAPKsSZYtVq5NfNxz/z7PgsiiZIs9loWnCBQEqYKWV5pISUIu4Rg n+jiWarABiPzDoDLxfeFvyChc4ptiSQu4b+6NPxD3mMONNxcGDejSBI0F5DykiqC44AX PnyXra+Z9Ir4ASlDzNv20saRFtcWK+kIq8OwAedS9SA3e0iD9JVE3G9mdiPn1b08jtTn STnw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=5nm08A9cUU8TPlzqUIdmfiiJPqf+vqKDDi2Gl6D9oDU=; fh=pl239mE91eJB/JuSHooEtzPTD14L46r5CKSqNdl39Z4=; b=UgvoQ64o5VHUhgQ/z1Y9zWP6uJIaOvH6ui+xU/9g9ky10JuKZMLP8npN5G5rzPTP8W UH9F+/hvnXifSU53APD2IMDG9RCrE96BycQK6EcYpBb7hNdRqyflz8xDU1oHrkDuHXL3 K1Yv/pxnMk3wIocGKXcsI1S44ghMqyux2dqA4OV7DBPzNpcfO8F6QlkV2pLk3GxO5jVG 5YEKMOBoczsKcbImXyRbqlCSLiJT0h/hGFbJEJSZ8QUImMP6LGUyMZxtxydkNoNuAFa5 5qCrMDqHSrCIroh8JU/3v9rBIaP8OKRBXMnkEwt3AqQLj/npu/pf42fgpImjIOjbUphI IJmg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-53968-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53968-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUkCpnvVDoTMZ4JG/EolVDpVJHRW+wzRqznrvGL9Vyy4RGdMFGVQKEa0usNpWIgN+cP9j3xhvlNSmNFbq0InDZLGhqosA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id j20-20020a170906255400b00a372f681e53si298272ejb.45.2024.02.05.14.07.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 14:07:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53968-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-53968-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53968-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 94DAB1F27E39 for ; Mon, 5 Feb 2024 22:06:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B9FC951005; Mon, 5 Feb 2024 21:21:19 +0000 (UTC) Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (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 0F4BC4F889; Mon, 5 Feb 2024 21:21:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707168077; cv=none; b=CKR8lsruKGpTsYue9s3m6qJyzE2wQ9ZaBgajIHGv0E7kd7gXLSm4HR6LzeHM0mXaNQMr80WjUos5MfR6D022Ej7/NLZf2e3/lUjiG2YmgpnzUYl0S3zyxQIOUBomaW5ZZitCtuQZgNkfZcediHd0SAvRAoJ+FiRit58KudhR1R8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707168077; c=relaxed/simple; bh=jZ9uXCD64qH50wsZKP5sbI/TyNCKkopgUzIG8xh5LwI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=N5KOEVUbz041YPOYJ+YC9lEd2eFAGqH3ukxaQ1fGMki/24j4bbWGbvNlBns4+a+N6UyxH9WM/Se0ag3u7Fjwc3Oorg90JneEaoLmNf+O/gPkeTFJmqXJm0/W5qDRVwoxeP74LOzVOtfXfynYT3I2UuIRMjfPuKVNJzg4kLSnoY0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.4.0) id a17c3d19a7b546d0; Mon, 5 Feb 2024 22:21:06 +0100 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 60918669A1B; Mon, 5 Feb 2024 22:21:05 +0100 (CET) From: "Rafael J. Wysocki" To: Linux PM Cc: Daniel Lezcano , LKML , Linux ACPI , Lukasz Luba , Zhang Rui , Srinivas Pandruvada , Stanislaw Gruszka , AngeloGioacchino Del Regno Subject: [PATCH v1 6/6] thermal: intel: Adjust ops handling during thermal zone registration Date: Mon, 05 Feb 2024 22:20:32 +0100 Message-ID: <3284830.aeNJFYEL58@kreacher> In-Reply-To: <2728491.mvXUDI8C0e@kreacher> References: <2728491.mvXUDI8C0e@kreacher> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrfedvuddgheehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepledprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=9 Fuz1=9 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790098358889225802 X-GMAIL-MSGID: 1790098358889225802 From: Rafael J. Wysocki Because thermal zone operations are now stored directly in struct thermal_zone_device, thermal zone creators can discard the operations structure after the zone registration is complete, or it can be made read-only. Accordingly, make int340x_thermal_zone_add() use a local variable to represent thermal zone operations, so it is freed automatically upon the function exit, and make the other Intel thermal drivers use const zone operations structures. Signed-off-by: Rafael J. Wysocki Reviewed-by: Stanislaw Gruszka --- drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c | 26 ++-------- drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h | 1 drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c | 2 drivers/thermal/intel/intel_pch_thermal.c | 2 drivers/thermal/intel/intel_quark_dts_thermal.c | 2 drivers/thermal/intel/intel_soc_dts_iosf.c | 2 drivers/thermal/intel/x86_pkg_temp_thermal.c | 2 7 files changed, 11 insertions(+), 26 deletions(-) Index: linux-pm/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c =================================================================== --- linux-pm.orig/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c +++ linux-pm/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c @@ -61,12 +61,6 @@ static void int340x_thermal_critical(str dev_dbg(&zone->device, "%s: critical temperature reached\n", zone->type); } -static struct thermal_zone_device_ops int340x_thermal_zone_ops = { - .get_temp = int340x_thermal_get_zone_temp, - .set_trip_temp = int340x_thermal_set_trip_temp, - .critical = int340x_thermal_critical, -}; - static inline void *int_to_trip_priv(int i) { return (void *)(long)i; @@ -126,6 +120,11 @@ static struct thermal_zone_params int340 struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev, int (*get_temp) (struct thermal_zone_device *, int *)) { + const struct thermal_zone_device_ops zone_ops = { + .set_trip_temp = int340x_thermal_set_trip_temp, + .critical = int340x_thermal_critical, + .get_temp = get_temp ? get_temp : int340x_thermal_get_zone_temp, + }; struct int34x_thermal_zone *int34x_zone; struct thermal_trip *zone_trips; unsigned long long trip_cnt = 0; @@ -140,16 +139,6 @@ struct int34x_thermal_zone *int340x_ther int34x_zone->adev = adev; - int34x_zone->ops = kmemdup(&int340x_thermal_zone_ops, - sizeof(int340x_thermal_zone_ops), GFP_KERNEL); - if (!int34x_zone->ops) { - ret = -ENOMEM; - goto err_ops_alloc; - } - - if (get_temp) - int34x_zone->ops->get_temp = get_temp; - status = acpi_evaluate_integer(adev->handle, "PATC", NULL, &trip_cnt); if (ACPI_SUCCESS(status)) { int34x_zone->aux_trip_nr = trip_cnt; @@ -185,7 +174,7 @@ struct int34x_thermal_zone *int340x_ther acpi_device_bid(adev), zone_trips, trip_cnt, trip_mask, int34x_zone, - int34x_zone->ops, + &zone_ops, &int340x_thermal_params, 0, 0); kfree(zone_trips); @@ -205,8 +194,6 @@ err_enable: err_thermal_zone: acpi_lpat_free_conversion_table(int34x_zone->lpat_table); err_trips_alloc: - kfree(int34x_zone->ops); -err_ops_alloc: kfree(int34x_zone); return ERR_PTR(ret); } @@ -216,7 +203,6 @@ void int340x_thermal_zone_remove(struct { thermal_zone_device_unregister(int34x_zone->zone); acpi_lpat_free_conversion_table(int34x_zone->lpat_table); - kfree(int34x_zone->ops); kfree(int34x_zone); } EXPORT_SYMBOL_GPL(int340x_thermal_zone_remove); Index: linux-pm/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h =================================================================== --- linux-pm.orig/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h +++ linux-pm/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h @@ -22,7 +22,6 @@ struct int34x_thermal_zone { struct acpi_device *adev; int aux_trip_nr; struct thermal_zone_device *zone; - struct thermal_zone_device_ops *ops; void *priv_data; struct acpi_lpat_conversion_table *lpat_table; }; Index: linux-pm/drivers/thermal/intel/intel_pch_thermal.c =================================================================== --- linux-pm.orig/drivers/thermal/intel/intel_pch_thermal.c +++ linux-pm/drivers/thermal/intel/intel_pch_thermal.c @@ -131,7 +131,7 @@ static void pch_critical(struct thermal_ thermal_zone_device_type(tzd)); } -static struct thermal_zone_device_ops tzd_ops = { +static const struct thermal_zone_device_ops tzd_ops = { .get_temp = pch_thermal_get_temp, .critical = pch_critical, }; Index: linux-pm/drivers/thermal/intel/intel_quark_dts_thermal.c =================================================================== --- linux-pm.orig/drivers/thermal/intel/intel_quark_dts_thermal.c +++ linux-pm/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -292,7 +292,7 @@ static int sys_change_mode(struct therma return ret; } -static struct thermal_zone_device_ops tzone_ops = { +static const struct thermal_zone_device_ops tzone_ops = { .get_temp = sys_get_curr_temp, .set_trip_temp = sys_set_trip_temp, .change_mode = sys_change_mode, Index: linux-pm/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c =================================================================== --- linux-pm.orig/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c +++ linux-pm/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c @@ -233,7 +233,7 @@ static int get_trip_temp(struct proc_the return temp; } -static struct thermal_zone_device_ops tzone_ops = { +static const struct thermal_zone_device_ops tzone_ops = { .get_temp = sys_get_curr_temp, .set_trip_temp = sys_set_trip_temp, }; Index: linux-pm/drivers/thermal/intel/intel_soc_dts_iosf.c =================================================================== --- linux-pm.orig/drivers/thermal/intel/intel_soc_dts_iosf.c +++ linux-pm/drivers/thermal/intel/intel_soc_dts_iosf.c @@ -168,7 +168,7 @@ static int sys_get_curr_temp(struct ther return 0; } -static struct thermal_zone_device_ops tzone_ops = { +static const struct thermal_zone_device_ops tzone_ops = { .get_temp = sys_get_curr_temp, .set_trip_temp = sys_set_trip_temp, }; Index: linux-pm/drivers/thermal/intel/x86_pkg_temp_thermal.c =================================================================== --- linux-pm.orig/drivers/thermal/intel/x86_pkg_temp_thermal.c +++ linux-pm/drivers/thermal/intel/x86_pkg_temp_thermal.c @@ -166,7 +166,7 @@ sys_set_trip_temp(struct thermal_zone_de } /* Thermal zone callback registry */ -static struct thermal_zone_device_ops tzone_ops = { +static const struct thermal_zone_device_ops tzone_ops = { .get_temp = sys_get_curr_temp, .set_trip_temp = sys_set_trip_temp, };