From patchwork Tue Sep 12 18:37:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 138761 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp1029190vqx; Wed, 13 Sep 2023 04:59:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhFs3C0skwCkJGcvYUdVHw58lVBNyDRNmAzDzrfNFfi9NfZtTqN6SZ8h+Vv/8NbX7GG8BI X-Received: by 2002:a05:6808:157:b0:3a7:60f7:c9ad with SMTP id h23-20020a056808015700b003a760f7c9admr2294815oie.13.1694606353518; Wed, 13 Sep 2023 04:59:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694606353; cv=none; d=google.com; s=arc-20160816; b=nr7bK71STMfbyt+VhNVm+LnYdt0DJmjsZHz6EIdtcgKhbw7MOqPwQ4vHy/jkJoHN2x C/bRzWKrJvPp4FpMOpFVJeQhbSi5TO9xRRWqPcHolXKklo9U9KR+eStyXteetzyu8Qi4 7hSJvV4qPSs/7ABS5Kxlw+mP0iEvkzuMp5xaNCz2EAUVDMpSRWz+V2mRCZnG0FQbcFch nAdPV5bQmjICEcA6zIPHs5dPAml/LfGWUOXh6VmQJC1NbSVDzFWeed7glhLWwqf6e51D n1NOibOQp/VoLclhYm0UnXKQZ3OGfY+5b9hwXfz1sAZLVqQYMLvKpuWUa+zjS/A4x4Gf R2KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=RrWN44HYNRqOADuMcYuxSH5ajqM9v+NFgeaFOpUM+zo=; fh=TcRPROXzT9svfC8PL4GA9v01BlJpZsrjV4HRPcpqUxk=; b=Dh2jEKUo+/5ZFr84ucl3e666TmiAi58wwO6VDZEXV3xvlSi9Flk4Jwb2pQ3EezPL5v y4COyZyM12Joos1/+JYIP/uTWu/1pwTCTBo8cbARr5UKmb115hp8QyJWW/8H16XoVBIh MaRvQL7ag6AAr6DuxclyFJx/2051rEbeMJO3er6EoS28Pwdpj9NzCJo8T/n51XA9grUl tVGR1v7QHclUGns9A/nJepxloJvhUpiiA6+lJrQDdLR4XKexI9NKUr7zVgpPadQQLX2k 3/qd9lHn1nmOnSVQgITNG+lfE4TKwTSHPWEVBxBNVU39M66C71EToc19ZPdeBJGXM+Ey +6zA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id k15-20020a6568cf000000b00565f294417bsi9933938pgt.426.2023.09.13.04.59.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 04:59:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 4BD5F801B919; Tue, 12 Sep 2023 11:48:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237687AbjILSsD (ORCPT + 36 others); Tue, 12 Sep 2023 14:48:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237590AbjILSry (ORCPT ); Tue, 12 Sep 2023 14:47:54 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD9C21716; Tue, 12 Sep 2023 11:47:43 -0700 (PDT) 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.2.0) id 1f78031281b7904c; Tue, 12 Sep 2023 20:47:42 +0200 Authentication-Results: v370.home.net.pl; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=rjwysocki.net (client-ip=195.136.19.94; helo=[195.136.19.94]; envelope-from=rjw@rjwysocki.net; receiver=) 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 v370.home.net.pl (Postfix) with ESMTPSA id E0F5A663BE5; Tue, 12 Sep 2023 20:47:41 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Linux PM , Zhang Rui , Srinivas Pandruvada , Daniel Lezcano Subject: [PATCH v1 3/9] ACPI: thermal: Determine the number of trip points earlier Date: Tue, 12 Sep 2023 20:37:59 +0200 Message-ID: <1863318.tdWV9SEqCh@kreacher> In-Reply-To: <5708760.DvuYhMxLoT@kreacher> References: <5708760.DvuYhMxLoT@kreacher> 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: gggruggvucftvghtrhhoucdtuddrgedviedrudeiiedgudeftdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeeipdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprhhuihdriihhrghnghesihhnthgvlhdrtghomhdprhgtphhtthhopehs rhhinhhivhgrshdrphgrnhgurhhuvhgruggrsehlihhnuhigrdhinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 12 Sep 2023 11:48:07 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776923551642372617 X-GMAIL-MSGID: 1776923551642372617 From: Rafael J. Wysocki Compute the number of trip points in acpi_thermal_add() so as to allow the driver's data structures to be simplified going forward. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Reviewed-by: Daniel Lezcano --- drivers/acpi/thermal.c | 60 +++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 31 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -452,7 +452,7 @@ static void acpi_thermal_get_hot_trip(st static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) { - bool valid; + unsigned int count = 0; int i; acpi_thermal_get_critical_trip(tz); @@ -460,18 +460,24 @@ static int acpi_thermal_get_trip_points( /* Passive and active trip points (optional). */ __acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT); - valid = tz->trips.critical.valid | - tz->trips.hot.valid | - tz->trips.passive.trip.valid; - - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) - valid = valid || tz->trips.active[i].trip.valid; - - if (!valid) { - pr_warn(FW_BUG "No valid trip found\n"); - return -ENODEV; + if (tz->trips.critical.valid) + count++; + + if (tz->trips.hot.valid) + count++; + + if (tz->trips.passive.trip.valid) + count++; + + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + if (tz->trips.active[i].trip.valid) + count++; + else + break; + } - return 0; + + return count; } /* sys I/F for generic thermal sysfs support */ @@ -681,29 +687,15 @@ static void acpi_thermal_zone_sysfs_remo sysfs_remove_link(&tzdev->kobj, "device"); } -static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) +static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz, + unsigned int trip_count) { struct acpi_thermal_trip *acpi_trip; struct thermal_trip *trip; int passive_delay = 0; - int trip_count = 0; int result; int i; - if (tz->trips.critical.valid) - trip_count++; - - if (tz->trips.hot.valid) - trip_count++; - - if (tz->trips.passive.trip.valid) { - trip_count++; - passive_delay = tz->trips.passive.tsp * 100; - } - - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].trip.valid; i++) - trip_count++; - trip = kcalloc(trip_count, sizeof(*trip), GFP_KERNEL); if (!trip) return -ENOMEM; @@ -724,6 +716,8 @@ static int acpi_thermal_register_thermal acpi_trip = &tz->trips.passive.trip; if (acpi_trip->valid) { + passive_delay = tz->trips.passive.tsp * 100; + trip->type = THERMAL_TRIP_PASSIVE; trip->temperature = acpi_thermal_temp(tz, acpi_trip->temperature); trip->priv = acpi_trip; @@ -893,6 +887,7 @@ static void acpi_thermal_check_fn(struct static int acpi_thermal_add(struct acpi_device *device) { struct acpi_thermal *tz; + unsigned int trip_count; int result; if (!device) @@ -911,9 +906,12 @@ static int acpi_thermal_add(struct acpi_ acpi_thermal_aml_dependency_fix(tz); /* Get trip points [_CRT, _PSV, etc.] (required). */ - result = acpi_thermal_get_trip_points(tz); - if (result) + trip_count = acpi_thermal_get_trip_points(tz); + 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); @@ -932,7 +930,7 @@ static int acpi_thermal_add(struct acpi_ acpi_thermal_guess_offset(tz); - result = acpi_thermal_register_thermal_zone(tz); + result = acpi_thermal_register_thermal_zone(tz, trip_count); if (result) goto free_memory;