From patchwork Wed Feb 14 12:28:57 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: 200950 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1191526dyb; Wed, 14 Feb 2024 05:00:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUW0Iiwo/W37Yscg7irVXS7VmXUzLoXt6jCZGA3c8UTgAvMLwYyFuhejlD5MU9CYu2dw82xbryFAB2BUO5B9KsjJSNaAg== X-Google-Smtp-Source: AGHT+IGMkkZ+B7iFMjVEDjxbGRR1HRP2HY0yogINtL73f3+gj36YhUyE8MYq6yGC8ouG2m+VhHpx X-Received: by 2002:a17:90a:fe88:b0:298:9d89:fc08 with SMTP id co8-20020a17090afe8800b002989d89fc08mr2382392pjb.14.1707915631177; Wed, 14 Feb 2024 05:00:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707915631; cv=pass; d=google.com; s=arc-20160816; b=Rc8a1UDyMnwkIVSVNX2NSTD6pxv6oF84+PwkAgD2C9cjYRuErZzjijHWBUuliSBAgL 8v969qJRCvhFpwtFVH4LmOxg7isqzPICesGSCqjgZyw2GBrk88kvwqnjTt1poWqPE3Jf YO4AwF35u5sd0oG0pTrxB7JeZ78sgJccZXBOm61WEY+HT7mecDAw0ySC2jx26KGca1rl 842bUA5huOHTs7Ho5x+oBUPzaq+yzWn9W8i7GcPBDqyiIs+fvxfUPxUwgLra7GO4KTh8 z9EKdK/TwT2RXJvK+rGdW01/c5ufaefWbrQyRIAxCao1MqOnU6er58aseEobxvurISvy vsvw== 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=jw/MWVCeRk6nB/i/EXQxJX8vINANph1ajVRFyiozxqk=; fh=ocTZfm0t5AHOfDhi2edZiXz4dCiMY1aTa5L0CnIgPjo=; b=rSJXSVer/0Alg2PWFyO+GPvVcwu16YbJjqKZrEprfvgMKjUo17ztidLnJOeeEh/P4P bSVGKo8AkYflfetgDJaZFCEoKvJeZICk7ajPcaNb6sw4Pn7q2QpZst8yRKvQ5xfrmd17 ONqwx0wxE55lhFDEcIp0SQMs/nA7V52VKnQCJiEG7EjmdmvlZZeraM5g+VKkmwUlO7WV JO1AP2qzfwshHPsZ/D1irCUyfIXFD0D1B+Je9Ysamv2u2uq0kRas0pfu0I48mbsrV0BX b+3SPvbVHuTDreBmiM7wszpFyu9y6mru/884II4tvmTvs/vSIe0ZuyJZHIBgmxZBZk8i msjA==; 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-65216-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65216-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id b9-20020a17090ae38900b00298c3b85759si1130338pjz.146.2024.02.14.05.00.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 05:00:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65216-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-65216-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65216-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 440B1B23D8B for ; Wed, 14 Feb 2024 12:51:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E526D54F90; Wed, 14 Feb 2024 12:50:10 +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 BBA105337E; Wed, 14 Feb 2024 12:50:05 +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=1707915008; cv=none; b=f/CTy2rNuzNrYJMH3JNVask6Fhs32U8mQcXLgrbg9yUG0Os6ogfbPClNmGKLIx73voJUnLJU3JHksWRM39by+yYoL24fixxxS7TcmCYMAZc2z5ou2GidTnldV0+LN96r/OKB+KomhwAs8nOh+DKSCor710r8ma/eLGHAyZixisc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707915008; c=relaxed/simple; bh=qxJhbOKvEv1aOswKgO4WuniZESROcDNZKcfH2VkqaSQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=na/7HGvLSsIw19P2s97yz3KdSn8K6WToMqfPvxpGXG5WQvzk2327oD34heAD5PWlFRxuGETESZdN0G0SWTXwx/lxehQHnbCgsJCEHKS/Q+OnChnolyXmfz6wq5w8pe8z/qSrkZ0x42tEnbt4euDGwakitp1SrxG5JnOb8Go0Zmk= 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 d5b3f5452e748b4f; Wed, 14 Feb 2024 13:49:58 +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 D3880669DB7; Wed, 14 Feb 2024 13:49:57 +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 , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team Subject: [PATCH v2 1/6] thermal: core: Store zone trips table in struct thermal_zone_device Date: Wed, 14 Feb 2024 13:28:57 +0100 Message-ID: <1883976.tdWV9SEqCh@kreacher> In-Reply-To: <4551531.LvFx2qVVIh@kreacher> References: <4551531.LvFx2qVVIh@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: gggruggvucftvghtrhhoucdtuddrgedvledrudejgdeggecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopedugedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=14 Fuz1=14 Fuz2=14 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790879341082682564 X-GMAIL-MSGID: 1790879341082682564 From: Rafael J. Wysocki The current code expects 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 expected to access 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, which will allow the callers of thermal_zone_device_register_with_trips() to drop their trip tables right after the zone registration. This requires the imx thermal driver to be adjusted to store the new temperature in its internal trips table in imx_set_trip_temp(), because it will be separate from the core's trips table now and it has to be explicitly kept in sync with the latter. Signed-off-by: Rafael J. Wysocki Reviewed-by: Stanislaw Gruszka Reviewed-by: Daniel Lezcano --- v1 -> v2: * Rebase. * Drop all of the redundant trips[] checks against NULL. * Add imx change to still allow it to use its local trips table. * Add R-by from Stanislaw (which is still applicable IMV). --- drivers/thermal/imx_thermal.c | 1 + drivers/thermal/thermal_core.c | 17 ++++++++--------- drivers/thermal/thermal_trip.c | 2 +- include/linux/thermal.h | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) Index: linux-pm/include/linux/thermal.h =================================================================== --- linux-pm.orig/include/linux/thermal.h +++ linux-pm/include/linux/thermal.h @@ -137,7 +137,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. @@ -167,6 +166,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; @@ -179,7 +179,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; @@ -200,10 +199,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); }; /** @@ -322,7 +322,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, void *devdata, struct thermal_zone_device_ops *ops, const struct thermal_zone_params *tzp, @@ -381,7 +381,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, void *devdata, struct thermal_zone_device_ops *ops, const struct thermal_zone_params *tzp, Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -1227,9 +1227,6 @@ int thermal_zone_get_crit_temp(struct th if (tz->ops->get_crit_temp) return tz->ops->get_crit_temp(tz, temp); - if (!tz->trips) - return -EINVAL; - mutex_lock(&tz->lock); for (i = 0; i < tz->num_trips; i++) { @@ -1271,10 +1268,12 @@ 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, - 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, 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; @@ -1308,7 +1307,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); @@ -1340,7 +1339,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)); tz->num_trips = num_trips; thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay); Index: linux-pm/drivers/thermal/imx_thermal.c =================================================================== --- linux-pm.orig/drivers/thermal/imx_thermal.c +++ linux-pm/drivers/thermal/imx_thermal.c @@ -355,6 +355,7 @@ static int imx_set_trip_temp(struct ther return -EINVAL; imx_set_alarm_temp(data, temp); + trips[IMX_TRIP_PASSIVE].temperature = temp; pm_runtime_put(data->dev); Index: linux-pm/drivers/thermal/thermal_trip.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_trip.c +++ linux-pm/drivers/thermal/thermal_trip.c @@ -122,7 +122,7 @@ void __thermal_zone_set_trips(struct the int __thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id, struct thermal_trip *trip) { - if (!tz || !tz->trips || trip_id < 0 || trip_id >= tz->num_trips || !trip) + if (!tz || trip_id < 0 || trip_id >= tz->num_trips || !trip) return -EINVAL; *trip = tz->trips[trip_id]; From patchwork Wed Feb 14 12:30:23 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: 200945 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1187492dyb; Wed, 14 Feb 2024 04:52:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUc4u/K17Fm3WX6pCiy0X3oAcNGzr0Qy1gANPDrM/4vVZpwkALqM5jvHf5HF5Q48r4aaLdqP3pYOHXMqVvkPzunPPsDzg== X-Google-Smtp-Source: AGHT+IED2uGlex4FZWQbHjfAHwUD//v5GXlM0e2cT5tQZTFZVxj/lshKUDkOZS1WIJO6lQjyH4DR X-Received: by 2002:a05:6a00:10c5:b0:6e0:536a:a5d0 with SMTP id d5-20020a056a0010c500b006e0536aa5d0mr2971334pfu.30.1707915138076; Wed, 14 Feb 2024 04:52:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707915138; cv=pass; d=google.com; s=arc-20160816; b=ztBJkYf0ymwJtVU+kzMnGpsat/xifJUUaLfrHFXO8Tr3m8HDx+sWPbvHyXXFrVjxU/ xHQhkpfvjrPcNy/beXfV6O/VXVLnOoE98es24bhq1yg4dVqeOkzI1l9/CfN5O9zkJGAy REg/LKZcU5dkDqOGvx+zeH/kscp0XOz/BJVpJYqJ4C1GzUHTlddzGsqbD9yXL+yVo7yn ch56LrmX6wjF8wki0RWmPNf7I2TAjJmLZEHdwupAZSPGFp9xyrDXoyBAv94O98ZjvE7E TfXZQ6Xx4+j1VRAGo9qiTKCrLMTt7T3lDIJQvI6Hsd5kk24c+POvoffeKZYKIKjCl1f0 oxMw== 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=wQy6qGdz8CUujU07DPMFI8FglHgBewdLYpIqyucj7F8=; fh=MLTvhHL55PKVVOGsgzKyzHmCuvvN3fWv28thHB9phrE=; b=lBAYgZYrNH8Nf0YsMakTOItggIOifU1VhX1YbFrve3jHpfAYV3tHU63mCybfwkZ2kn EE9cZbM0dXtmd9ov62rI2vurYS2tWWKqS86TU7H7WWyjh6+2yrtkY74nu0OhUPDGLTa6 9ZBbQ9IkNKn8xpY3IBpMJ64O33V0wJBL3E6bXrz/9AbI7VsK0hXKmoIlLHJn/340u+mA oCh5f54s9E1IWCZ65Q0gMNZbigl9UnoufkKsfcqKxryB1ymE+dJi4KcSC+pIpp8mdchd cvKNi1atNtpBi1oEQjaD2koyJO4gzvslvqb0q95w0lKANTBnQwrBnqSu+bc305KyUS8m D+Ew==; 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-65213-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65213-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCXptKvLmCxuVY+nr4Y6hb98WcyZkzbQcSDrDw0eAVqDuJ+Fq/3PGZ4sDMe3w4WGl9W/69jzmUVsXsFEbMJNW8X4EkKnxQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id b5-20020a6567c5000000b005dbcf612461si3753619pgs.416.2024.02.14.04.52.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 04:52:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65213-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-65213-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65213-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 984AB28CD91 for ; Wed, 14 Feb 2024 12:51:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6D30754746; Wed, 14 Feb 2024 12:50:09 +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 A2E5D52F72; Wed, 14 Feb 2024 12:50:04 +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=1707915007; cv=none; b=k7QGPg0oihQshW5Q8ISbYq2h68jpRHD25AKc1KWJCKHlsgh0azaWwgmrpEn2E1fHB4pNtvMQWlhxFa4gDfVfrSssMMli6H+8Gx7C3PGPBQ7W4nFtd39g1Nlyn0/hCT1fK0DvI5/AOoZDHvnGoDKPzXUNFPFVPVnANOIr2JF2ddY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707915007; c=relaxed/simple; bh=JaHBeuuIG5uZZoaEPSZ2sPa9jXgVOE0rd93vNNIckrg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pFuqHO9Iko6r4jhon+5ceY/o7nwX1p1KzZT3bY4IykbdFPB8CFVdixEnTQQkySMeDhWfh5mon5tFbpOS4dLRhWMBmAne7tHYRkkp13wzKrWT5UBmeFrJaUfqS5j3yibjsoLx56m+XJlBtSTRMQ9OCv/TwJ/3+h4HLcksx8o6Py4= 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 88be413aea02551f; Wed, 14 Feb 2024 13:49:57 +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 F0A62669DCB; Wed, 14 Feb 2024 13:49:56 +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 , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team Subject: [PATCH v2 2/6] thermal: ACPI: Discard trips table after zone registration Date: Wed, 14 Feb 2024 13:30:23 +0100 Message-ID: <13457348.uLZWGnKmhe@kreacher> In-Reply-To: <4551531.LvFx2qVVIh@kreacher> References: <4551531.LvFx2qVVIh@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: gggruggvucftvghtrhhoucdtuddrgedvledrudejgdeggecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopedugedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=14 Fuz1=14 Fuz2=14 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790878824305729969 X-GMAIL-MSGID: 1790878824305729969 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 when acpi_thermal_add() returns to its caller. Also make some additional code simplifications unlocked by the above change. Signed-off-by: Rafael J. Wysocki Reviewed-by: Stanislaw Gruszka Acked-by: Daniel Lezcano --- v1 -> v2: Add R-by from Stanislaw. --- 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, 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 Wed Feb 14 12:45:23 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: 200944 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1187471dyb; Wed, 14 Feb 2024 04:52:15 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWPoZpk5Zpw9NTQ/cIfPUuvpmC/vh8Alp7WWvtDYVIYyEjsHdxwaY6S6CBEMakBmEo+j6qGYXk9aoL4UWa3F5r5bK4Iyw== X-Google-Smtp-Source: AGHT+IEXDfozztUtXZyWhnAI9QtHDFYwvf+UfpZkrqJ/TCeuHVFht+j8VByLEVD1H4OWZibgKRy6 X-Received: by 2002:aa7:cc8c:0:b0:560:58f:7148 with SMTP id p12-20020aa7cc8c000000b00560058f7148mr2026721edt.34.1707915135575; Wed, 14 Feb 2024 04:52:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707915135; cv=pass; d=google.com; s=arc-20160816; b=ZLrxZi6KGk+lVgeil8q1VPRlZQMtD8NWuBxZK1vwiZa6tuTW75fAEE/cat7a4cIEgM CfZocnprj/qGy1gpLpjXkRYhJVmlTbrPGdJNeVlxU40FmJRj8xW2VlngEMPGkPkV5iwg k2wsnGljVPPf/KmKc6JfzjFqDqtJZBRylW62xAAXX9bf0Tfhfusf8dEj98N6YgCyDj5s TWB9CzhqMB81Pl60eK1qMjhDK7SEIfSrdOKzpHVS7/iQ+ZH+HeXxjUwz1Ihad7VYAAYi pJn5YuvXBiglzUo+4KlrKk83RuP1Fwd3tGtcp71r2x93lN2YBdSMfZSylqRhR99oJJot 6/9g== 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=2y5cpUg7Rd9t1gMFW/svFjArED7F5KijP5v83cvikeU=; fh=N6UirPeexEMrFDILjnNWX/mPhcfNMMDoXScOUJAIIYI=; b=h+psfBVCiLj5qJXKVce7W5UyvIlVVcrxMRlR4B5tCWSI7ceUuxecuyo8Kos+BvjAMj vw5p6pBvJQthuW4UtLuPjVZsXtyqNVLJQpoTDp2C8xXSPSEmFCcFSSAU+aKqbHO7s/qx rucTYgA96ZOMgY5oPp+5tf0oxWCFD8QChrwFYlzzOwNa/MGGtnua72APDj0fyAZwaLSp dohGhVRMoMbUkAQBn4heMF6HEPqhjWjtfFzVX1EuD2i0rKN8UaKRjeKwLKP1vwJkBx90 4TUwK4ec86NCofeawV8SDBjN5UIn7lKIrUd5baFHIj+w5oPWzKoBa+j+tIhEQfk1t06B Fw7g==; 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-65215-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65215-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCVWZ7Zr/d69GG5QrxuPZrnFu8orrz4qt+VPrUOK4Y67zG0NB4kYOuF8v28PjRsAQOIIJJ4FlPIfYsMz4iBE7qtJL7yJIw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id g22-20020a0564021ed600b00561cb3c8c20si2653019edg.246.2024.02.14.04.52.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 04:52:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65215-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-65215-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65215-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 01A271F2371D for ; Wed, 14 Feb 2024 12:52:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1A3A755763; Wed, 14 Feb 2024 12:50:12 +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 BF3881A731; Wed, 14 Feb 2024 12:50:03 +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=1707915008; cv=none; b=g7rn+r3f01zvoLYcX5PahCEGaiZHk56Holn1rclsqDNnTelSrEE5wErcXDwWTX4jMO3APFG31xk78HydNGHlP+RJstKK7M1JVbYahHDmGHWA1RPeCES9GCq0HIA9ytUiMFoU2q7UhTKwIMVUV3L7logUZzqsPMAnho/JJ51nqVQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707915008; c=relaxed/simple; bh=B/ujohE3qiBVLmi+Jpy5fRBSCruD6diBDw5p9EMxt8w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EGuDPUuSTxshgFp18NoHs+7Wio196Qf4qPXPYte6QhLV99BKISfYJmVY7vZGtRSq4BgLEEG+NKVbeDXwRVdl5YSTBoqIhNyuzvYr+MCFWleCFEPolKwSCfCyjyMBIPFeDoOQV4dX3wVpX1T9+2xeOV2eld0zCZ8BzR/b4RE456I= 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 798074c4873750b2; Wed, 14 Feb 2024 13:49:55 +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 48C0A669DB7; Wed, 14 Feb 2024 13:49:55 +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 , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team Subject: [PATCH v2 4/6] thermal: core: Store zone ops in struct thermal_zone_device Date: Wed, 14 Feb 2024 13:45:23 +0100 Message-ID: <2262393.iZASKD2KPV@kreacher> In-Reply-To: <4551531.LvFx2qVVIh@kreacher> References: <4551531.LvFx2qVVIh@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: gggruggvucftvghtrhhoucdtuddrgedvledrudejgdeggecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopedugedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=14 Fuz1=14 Fuz2=14 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790878821619806034 X-GMAIL-MSGID: 1790878821619806034 From: Rafael J. Wysocki The current code requires thermal zone creators to pass pointers to writable ops structures 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 and modify thermal_of_zone_register() to use a local ops variable during thermal zone registration so ops do not need to be freed in thermal_of_zone_unregister() any more. Signed-off-by: Rafael J. Wysocki Reviewed-by: Stanislaw Gruszka Reviewed-by: Daniel Lezcano --- v1 -> v2: * Rebase. * Add thermal_of modifications. * Add R-by from Stanislaw (still applicable IMV). --- drivers/thermal/thermal_core.c | 40 +++++++++++++++++++------------------- drivers/thermal/thermal_helpers.c | 10 ++++----- drivers/thermal/thermal_hwmon.c | 4 +-- drivers/thermal/thermal_of.c | 26 +++++++----------------- drivers/thermal/thermal_sysfs.c | 8 +++---- drivers/thermal/thermal_trip.c | 4 +-- include/linux/thermal.h | 6 ++--- 7 files changed, 44 insertions(+), 54 deletions(-) Index: linux-pm/include/linux/thermal.h =================================================================== --- linux-pm.orig/include/linux/thermal.h +++ linux-pm/include/linux/thermal.h @@ -189,7 +189,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; @@ -324,14 +324,14 @@ struct thermal_zone_device *thermal_zone const char *type, const struct thermal_trip *trips, int num_trips, 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); mutex_lock(&tz->lock); @@ -1271,7 +1271,7 @@ struct thermal_zone_device * thermal_zone_device_register_with_trips(const char *type, const struct thermal_trip *trips, int num_trips, 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) { @@ -1333,10 +1333,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)); @@ -1422,7 +1422,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, devdata, @@ -1484,8 +1484,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 @@ -128,8 +128,8 @@ trip_point_temp_store(struct device *dev } 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; } @@ -254,10 +254,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) Index: linux-pm/drivers/thermal/thermal_of.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_of.c +++ linux-pm/drivers/thermal/thermal_of.c @@ -441,12 +441,10 @@ static int thermal_of_unbind(struct ther static void thermal_of_zone_unregister(struct thermal_zone_device *tz) { struct thermal_trip *trips = tz->trips; - struct thermal_zone_device_ops *ops = tz->ops; thermal_zone_device_disable(tz); thermal_zone_device_unregister(tz); kfree(trips); - kfree(ops); } /** @@ -472,33 +470,27 @@ static void thermal_of_zone_unregister(s static struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor, int id, void *data, const struct thermal_zone_device_ops *ops) { + struct thermal_zone_device_ops of_ops = *ops; struct thermal_zone_device *tz; struct thermal_trip *trips; struct thermal_zone_params tzp = {}; - struct thermal_zone_device_ops *of_ops; struct device_node *np; const char *action; int delay, pdelay; int ntrips; int ret; - of_ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL); - if (!of_ops) - return ERR_PTR(-ENOMEM); - np = of_thermal_zone_find(sensor, id); if (IS_ERR(np)) { if (PTR_ERR(np) != -ENODEV) pr_err("Failed to find thermal zone for %pOFn id=%d\n", sensor, id); - ret = PTR_ERR(np); - goto out_kfree_of_ops; + return ERR_CAST(np); } trips = thermal_of_trips_init(np, &ntrips); if (IS_ERR(trips)) { pr_err("Failed to find trip points for %pOFn id=%d\n", sensor, id); - ret = PTR_ERR(trips); - goto out_kfree_of_ops; + return ERR_CAST(trips); } ret = thermal_of_monitor_init(np, &delay, &pdelay); @@ -509,16 +501,16 @@ static struct thermal_zone_device *therm thermal_of_parameters_init(np, &tzp); - of_ops->bind = thermal_of_bind; - of_ops->unbind = thermal_of_unbind; + of_ops.bind = thermal_of_bind; + of_ops.unbind = thermal_of_unbind; ret = of_property_read_string(np, "critical-action", &action); if (!ret) - if (!of_ops->critical && !strcasecmp(action, "reboot")) - of_ops->critical = thermal_zone_device_critical_reboot; + if (!of_ops.critical && !strcasecmp(action, "reboot")) + of_ops.critical = thermal_zone_device_critical_reboot; tz = thermal_zone_device_register_with_trips(np->name, trips, ntrips, - data, of_ops, &tzp, + data, &of_ops, &tzp, pdelay, delay); if (IS_ERR(tz)) { ret = PTR_ERR(tz); @@ -538,8 +530,6 @@ static struct thermal_zone_device *therm out_kfree_trips: kfree(trips); -out_kfree_of_ops: - kfree(of_ops); return ERR_PTR(ret); } From patchwork Wed Feb 14 12:48:34 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: 200942 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1186754dyb; Wed, 14 Feb 2024 04:50:47 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXbe82YeYLWN1cQw4OSSP3tBZIY+PgIQ+BmLCdzTLXb+yyUXi5Erj+ujwv2OoXt37Mzbn+3/rFjvNHUhu7zBr4RkiMl6A== X-Google-Smtp-Source: AGHT+IGbvHPIrzWAprXZJMDeFTQSKYsEqEtrc87yXLlStNcq+F/Wlhn7sClXoYrNqRElVWypXojj X-Received: by 2002:a05:622a:2d6:b0:42c:7037:4f02 with SMTP id a22-20020a05622a02d600b0042c70374f02mr2596413qtx.53.1707915047197; Wed, 14 Feb 2024 04:50:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707915047; cv=pass; d=google.com; s=arc-20160816; b=n0dmV2ErGYt7nO+jEIpbmPX+2gJhq/Cm6ocXgMorflzvzXASUkKthIFID1ttsrq0tS mFSLM/CpKaz0Mf4awIhGfTWvigY1VqZr3JzzLgHYyltDgiLZMKo1IpOl9IqgLdfoRTjr TPvzjNKWocHlvZBh5Da8ugBR7l5w7xDKIQnERqDfdpexDhEgKXv8S0QPlpddKiPA21E/ nm016oPWo+qyxgv7KXvbQ2Y8hfTzpMI4Db42AmZcPLpSqOngpY2H6HqyZHDVbCRs/85P Ngqmg69yR2nGR9VC+GnxY4ywYHIcv88pVVb/lzUzTAdYp/2iYqYeKt6zpCh0vcWIkXlj VIbg== 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=z2m20k/l1U6wDvo55Kv5ZPzJ1c4W2L9HgRsaJFwJado=; fh=mL0zJ4DfB9JXOfNKVSgwO6wr2i/51GvDaFD59k5Pkcg=; b=UUkeQ1PxthaBSpYtZKttcWQivF1UwgE2l97Dfeilu3Y/WSEdWYwcJi4MUPtcdHpkA2 kX3KMSCoi3oJZHd3hSfyJnWPHDqe24aik0/j+4uEE76F7yg+XqOomjMJiXxvgM9YSd9i Napa8fZKgrKI4ZNny4sYwumHUWH/Q+H1q1T6mn5u+ERS/33V2ugLFeVFoaQj8GgBbRuz IcoG7uUdbk4iiIaAuasK0FN/t8nmP2phnwvLrRfxgIaskRRv6AyYnykQ3OIC5Pvto+iF q8N0W720UrPyg9I6OPwf/w6zTYQTW3rc2rDi033A7iWKVePC0/mQditzcYdQ8GUjU3zU Sq0Q==; 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-65212-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65212-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCVvcZ7hLxOPaYfjm2jVUWoTb47dIEs2qQI5x2E9oVYBoYQm78ClJoSEa9NcJ/1YC6DmJQBi4expDd3Vgt64WRqha8GvNg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 16-20020ac85750000000b0042c6b54bff2si5512813qtx.426.2024.02.14.04.50.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 04:50:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65212-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-65212-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65212-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 66CB31C21C13 for ; Wed, 14 Feb 2024 12:50:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 021ED535A3; Wed, 14 Feb 2024 12:50:07 +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 CBE4352F6D; Wed, 14 Feb 2024 12:50:02 +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=1707915005; cv=none; b=k2uUm9par7v1TQbHxbQ5RY4RL8scmHhGP9BKq18FuRnLBYbazYJPqAzVS7/d9zcayewpni6yXrx7B4rXmx1uG24qLL2JZazronN7KsXcMUUqv+B16c00hC8R/CSdUE5ixChNn3EjyOHg1eW4F286AsZUoc8PBEByk5sBk9KT4BI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707915005; c=relaxed/simple; bh=I5fEFYQhaHQyljtvj0e+0/ehCmqsqbtUCsJyrH6AmLM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WLo+Y6AqRsg+W3blJYMjjYeZjVRGyGipbw1cUAoJv3/4+3e2A2e46NI8WV1NHxlqbzBm8kPoqgTDewNR9sCMh85ZZVuaLe+OnAis8G49d5+iFE5M20VLNutNe9F2vNsEcYqVnwKlV8ROhxCCzqRFvA1rD7Tovzv4444R4ZbhiAA= 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 a060be3b8950e4e4; Wed, 14 Feb 2024 13:49:55 +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 84EA6669DB7; Wed, 14 Feb 2024 13:49:54 +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 , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team Subject: [PATCH v2 5/6] thermal: ACPI: Constify acpi_thermal_zone_ops Date: Wed, 14 Feb 2024 13:48:34 +0100 Message-ID: <3552599.iIbC2pHGDl@kreacher> In-Reply-To: <4551531.LvFx2qVVIh@kreacher> References: <4551531.LvFx2qVVIh@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: gggruggvucftvghtrhhoucdtuddrgedvledrudejgdeggecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopedugedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=14 Fuz1=14 Fuz2=14 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790878728249927184 X-GMAIL-MSGID: 1790878728249927184 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 Acked-by: Daniel Lezcano --- v1 -> v2: No changes. --- 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 Wed Feb 14 12:49:41 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: 200943 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1186775dyb; Wed, 14 Feb 2024 04:50:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXoumYpnt8SCBZKb1M/Vq/kwppo3laaUF8XY1r3xMpWgH7qnz49fPi96u1WYuAGOHWQu/A4w39UINBiumw1/GJGoSfOvA== X-Google-Smtp-Source: AGHT+IG/CN7OMIMZjnFvQQzh1CHOXWAtFcmZAwovH8DxZS/8BM/dEAUsTsL9cK3QhZLelT1TDanJ X-Received: by 2002:aa7:c49a:0:b0:55f:e432:4cac with SMTP id m26-20020aa7c49a000000b0055fe4324cacmr1992747edq.37.1707915049476; Wed, 14 Feb 2024 04:50:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707915049; cv=pass; d=google.com; s=arc-20160816; b=aKRzZ/20nHTDNAwa9EJe4TU7VMqpxM7R1CfXawgifkz5FBjPNshbwrAd2F/QnrJasA m3W53JU75c8uwbAPiJElt/t0e8PYjcomCq5gLcoIJ1SE2KXTPYUszpH/NS4BT18/z6u5 WSmFKiPGKJTMOrHmFlarhjFOg/PCTVEfPoLDmfvvCH1ym73hnVAMXSIrT0PtrPWoCt3+ YgBbX+I/NSMPNR+ZABEBSHE8GHH7C/CrCxk12PD3AU5Uy4ap5b0qrvte8vlwk+nGvpPX CXq/LNvAlDcaj445WcWcH3l1dRQJUJCsMp0S4qvcXe0Rl44NhXu8bEZO73OiXABRrkQR AVVA== 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=iUZTodKVA52Vjsv9kNxNTimiNhjdZICQZS234+ltTJI=; fh=Qkb6z78RwxsRriWClPGD2fkvfW0/uKCak2HztzyaX8Y=; b=SOllr40kweK5Nc15B2iajkYXnp19FcrV+iDK8DsUIsP9ipzOCm4mWhMZvUzzy9qazz BI5nHQdzo5ndLo0Y/YECwEoj/rCqqJjzk5E6AM/eJvz5PRSyypyL/HSjN4GYiE/7rwYJ DOcVO/cDJCNCXgzGB0XozV3LkMt6AbA/T02EpTklZopnl1nmlI2bnTvQUzwgRFWXBSGJ OyYBQUBnZcbZI9VnhTzPpHBYVQivGQR+rFpu1PZLqEJkmUKJjZWr6uIbUr7g1+M3L9BT SNtTSAxHE078VDULAkOwwYXB9p7Dyn5GcffYkn26i5KKkh1Wv1x+LLRCIqi4pG9edHOT 8vLg==; 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-65211-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65211-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCVp4y37zjm+oUK9LpINzag0EgLKAEfBKOq22l6iTBegRpiVdmXo2A/MaWHfR1d34AEDDmSMlfV1ZnI+TuvlGKm9RvgSJw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id bf1-20020a0564021a4100b005606d7dc1fdsi4834531edb.33.2024.02.14.04.50.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 04:50:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65211-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-65211-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65211-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 E604E1F24A58 for ; Wed, 14 Feb 2024 12:50:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9BD87537EC; Wed, 14 Feb 2024 12:50:07 +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 D0023487BC; Wed, 14 Feb 2024 12:50:01 +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=1707915004; cv=none; b=DjwXiE1Ih2UQgSoCZWinVgrS76wa2NzpShiXmzVfV05H1B42xQr6dKf5Js5cnvG+DdcTrsvH6sjZNcaM3SRVsL1IpqtDV35T9/kq3FASbkDfsxldWIzOHwPwJhm1gaUqRu1/6ywvrxRwVzi85vOfDMnr7MTvu+79HB5bVOrnydw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707915004; c=relaxed/simple; bh=025zc1LDVoUvaWbk7sNmJUJz5pu2gGD8HXd5JAmh5sw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EVUX/bmBImivwZs7AxGGajJ3+uvxlgW0jeLGwqXH1ebk8l9aKIWmwJxeZXmPUWhqBB4m3S1Ms+lN8yZM7da4TxPH+B06OzQQfFdDcsgVpV4YgYybu21hOuHCP4OqweoOai43CEa/d0g6UM+blHXUFuOrY1SOw0tYiGxf08SOgts= 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 43f8bf5cd5d58855; Wed, 14 Feb 2024 13:49:54 +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 B9BB4669DCB; Wed, 14 Feb 2024 13:49:53 +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 , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team Subject: [PATCH v2 6/6] thermal: intel: Adjust ops handling during thermal zone registration Date: Wed, 14 Feb 2024 13:49:41 +0100 Message-ID: <3213551.5fSG56mABF@kreacher> In-Reply-To: <4551531.LvFx2qVVIh@kreacher> References: <4551531.LvFx2qVVIh@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: gggruggvucftvghtrhhoucdtuddrgedvledrudejgdeggecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopedugedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=14 Fuz1=14 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790878730404325311 X-GMAIL-MSGID: 1790878730404325311 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 Reviewed-by: Daniel Lezcano --- v1 -> v2: * Rebase. * Add R-by from Stanislaw. --- 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; @@ -139,16 +138,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; @@ -183,7 +172,7 @@ struct int34x_thermal_zone *int340x_ther acpi_device_bid(adev), zone_trips, trip_cnt, int34x_zone, - int34x_zone->ops, + &zone_ops, &int340x_thermal_params, 0, 0); kfree(zone_trips); @@ -203,8 +192,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); } @@ -214,7 +201,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 @@ -132,7 +132,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 @@ -288,7 +288,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, };