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); }