From patchwork Tue Oct 4 16:31:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 612466 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70D90C433F5 for ; Tue, 4 Oct 2022 16:33:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230159AbiJDQdP (ORCPT ); Tue, 4 Oct 2022 12:33:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230147AbiJDQdM (ORCPT ); Tue, 4 Oct 2022 12:33:12 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E235B58513; Tue, 4 Oct 2022 09:33:09 -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.0.0) id e8d3fdc3e6bc692e; Tue, 4 Oct 2022 18:33:08 +0200 Received: from kreacher.localnet (unknown [213.134.189.18]) (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 6D65F6665F6; Tue, 4 Oct 2022 18:33:07 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: Srinivas Pandruvada , Zhang Rui , Linux PM , LKML Subject: [PATCH v1 1/3] ACPI: thermal: Use white space more consistently Date: Tue, 04 Oct 2022 18:31:11 +0200 Message-ID: <4774295.31r3eYUQgx@kreacher> In-Reply-To: <12068304.O9o76ZdvQC@kreacher> References: <12068304.O9o76ZdvQC@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 213.134.189.18 X-CLIENT-HOSTNAME: 213.134.189.18 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvfedrfeeiuddguddtvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepvddufedrudefgedrudekledrudeknecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvddufedrudefgedrudekledrudekpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeehpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhg pdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-DCC--Metrics: v370.home.net.pl 1024; Body=5 Fuz1=5 Fuz2=5 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Rafael J. Wysocki The usage of white space in the ACPI thermal driver is not very consistent, so improve that a bit. While at it, add missing braces to if()/else in a few places. No functional impact. Signed-off-by: Rafael J. Wysocki Acked-by: Daniel Lezcano --- drivers/acpi/thermal.c | 190 +++++++++++++++++++++++-------------------------- 1 file changed, 92 insertions(+), 98 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -158,7 +158,7 @@ struct acpi_thermal_flags { }; struct acpi_thermal { - struct acpi_device * device; + struct acpi_device *device; acpi_bus_id name; unsigned long temperature; unsigned long last_temperature; @@ -270,8 +270,7 @@ static int acpi_thermal_trips_update(str /* Critical Shutdown */ if (flag & ACPI_TRIPS_CRITICAL) { - status = acpi_evaluate_integer(tz->device->handle, - "_CRT", NULL, &tmp); + status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &tmp); tz->trips.critical.temperature = tmp; /* * Treat freezing temperatures as invalid as well; some @@ -284,8 +283,7 @@ static int acpi_thermal_trips_update(str acpi_handle_debug(tz->device->handle, "No critical threshold\n"); } else if (tmp <= 2732) { - pr_info(FW_BUG "Invalid critical threshold (%llu)\n", - tmp); + pr_info(FW_BUG "Invalid critical threshold (%llu)\n", tmp); tz->trips.critical.flags.valid = 0; } else { tz->trips.critical.flags.valid = 1; @@ -312,8 +310,7 @@ static int acpi_thermal_trips_update(str /* Critical Sleep (optional) */ if (flag & ACPI_TRIPS_HOT) { - status = acpi_evaluate_integer(tz->device->handle, - "_HOT", NULL, &tmp); + status = acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &tmp); if (ACPI_FAILURE(status)) { tz->trips.hot.flags.valid = 0; acpi_handle_debug(tz->device->handle, @@ -329,7 +326,7 @@ static int acpi_thermal_trips_update(str /* Passive (optional) */ if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) || - (flag == ACPI_TRIPS_INIT)) { + (flag == ACPI_TRIPS_INIT)) { valid = tz->trips.passive.flags.valid; if (psv == -1) { status = AE_SUPPORT; @@ -338,32 +335,31 @@ static int acpi_thermal_trips_update(str status = AE_OK; } else { status = acpi_evaluate_integer(tz->device->handle, - "_PSV", NULL, &tmp); + "_PSV", NULL, &tmp); } - if (ACPI_FAILURE(status)) + if (ACPI_FAILURE(status)) { tz->trips.passive.flags.valid = 0; - else { + } else { tz->trips.passive.temperature = tmp; tz->trips.passive.flags.valid = 1; if (flag == ACPI_TRIPS_INIT) { - status = acpi_evaluate_integer( - tz->device->handle, "_TC1", - NULL, &tmp); + status = acpi_evaluate_integer(tz->device->handle, + "_TC1", NULL, &tmp); if (ACPI_FAILURE(status)) tz->trips.passive.flags.valid = 0; else tz->trips.passive.tc1 = tmp; - status = acpi_evaluate_integer( - tz->device->handle, "_TC2", - NULL, &tmp); + + status = acpi_evaluate_integer(tz->device->handle, + "_TC2", NULL, &tmp); if (ACPI_FAILURE(status)) tz->trips.passive.flags.valid = 0; else tz->trips.passive.tc2 = tmp; - status = acpi_evaluate_integer( - tz->device->handle, "_TSP", - NULL, &tmp); + + status = acpi_evaluate_integer(tz->device->handle, + "_TSP", NULL, &tmp); if (ACPI_FAILURE(status)) tz->trips.passive.flags.valid = 0; else @@ -374,25 +370,25 @@ static int acpi_thermal_trips_update(str if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.flags.valid) { memset(&devices, 0, sizeof(struct acpi_handle_list)); status = acpi_evaluate_reference(tz->device->handle, "_PSL", - NULL, &devices); + NULL, &devices); if (ACPI_FAILURE(status)) { acpi_handle_info(tz->device->handle, "Invalid passive threshold\n"); tz->trips.passive.flags.valid = 0; - } - else + } else { tz->trips.passive.flags.valid = 1; + } if (memcmp(&tz->trips.passive.devices, &devices, - sizeof(struct acpi_handle_list))) { + sizeof(struct acpi_handle_list))) { memcpy(&tz->trips.passive.devices, &devices, - sizeof(struct acpi_handle_list)); + sizeof(struct acpi_handle_list)); ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device"); } } if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) { if (valid != tz->trips.passive.flags.valid) - ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state"); + ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state"); } /* Active (optional) */ @@ -404,28 +400,30 @@ static int acpi_thermal_trips_update(str break; /* disable all active trip points */ if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) && - tz->trips.active[i].flags.valid)) { + tz->trips.active[i].flags.valid)) { status = acpi_evaluate_integer(tz->device->handle, - name, NULL, &tmp); + name, NULL, &tmp); if (ACPI_FAILURE(status)) { tz->trips.active[i].flags.valid = 0; if (i == 0) break; + if (act <= 0) break; + if (i == 1) - tz->trips.active[0].temperature = - celsius_to_deci_kelvin(act); + tz->trips.active[0].temperature = celsius_to_deci_kelvin(act); else /* * Don't allow override higher than * the next higher trip point */ - tz->trips.active[i - 1].temperature = - (tz->trips.active[i - 2].temperature < + tz->trips.active[i-1].temperature = + (tz->trips.active[i-2].temperature < celsius_to_deci_kelvin(act) ? - tz->trips.active[i - 2].temperature : + tz->trips.active[i-2].temperature : celsius_to_deci_kelvin(act)); + break; } else { tz->trips.active[i].temperature = tmp; @@ -434,22 +432,22 @@ static int acpi_thermal_trips_update(str } name[2] = 'L'; - if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid ) { + if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid) { memset(&devices, 0, sizeof(struct acpi_handle_list)); status = acpi_evaluate_reference(tz->device->handle, - name, NULL, &devices); + name, NULL, &devices); if (ACPI_FAILURE(status)) { acpi_handle_info(tz->device->handle, "Invalid active%d threshold\n", i); tz->trips.active[i].flags.valid = 0; - } - else + } else { tz->trips.active[i].flags.valid = 1; + } if (memcmp(&tz->trips.active[i].devices, &devices, - sizeof(struct acpi_handle_list))) { + sizeof(struct acpi_handle_list))) { memcpy(&tz->trips.active[i].devices, &devices, - sizeof(struct acpi_handle_list)); + sizeof(struct acpi_handle_list)); ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device"); } } @@ -464,9 +462,9 @@ static int acpi_thermal_trips_update(str if (flag & ACPI_TRIPS_DEVICES) { memset(&devices, 0, sizeof(devices)); status = acpi_evaluate_reference(tz->device->handle, "_TZD", - NULL, &devices); - if (ACPI_SUCCESS(status) - && memcmp(&tz->devices, &devices, sizeof(devices))) { + NULL, &devices); + if (ACPI_SUCCESS(status) && + memcmp(&tz->devices, &devices, sizeof(devices))) { tz->devices = devices; ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device"); } @@ -548,8 +546,7 @@ static int thermal_get_trip_type(struct trip--; } - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && - tz->trips.active[i].flags.valid; i++) { + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].flags.valid; i++) { if (!trip) { *type = THERMAL_TRIP_ACTIVE; return 0; @@ -572,8 +569,8 @@ static int thermal_get_trip_temp(struct if (tz->trips.critical.flags.valid) { if (!trip) { *temp = deci_kelvin_to_millicelsius_with_offset( - tz->trips.critical.temperature, - tz->kelvin_offset); + tz->trips.critical.temperature, + tz->kelvin_offset); return 0; } trip--; @@ -582,8 +579,8 @@ static int thermal_get_trip_temp(struct if (tz->trips.hot.flags.valid) { if (!trip) { *temp = deci_kelvin_to_millicelsius_with_offset( - tz->trips.hot.temperature, - tz->kelvin_offset); + tz->trips.hot.temperature, + tz->kelvin_offset); return 0; } trip--; @@ -592,8 +589,8 @@ static int thermal_get_trip_temp(struct if (tz->trips.passive.flags.valid) { if (!trip) { *temp = deci_kelvin_to_millicelsius_with_offset( - tz->trips.passive.temperature, - tz->kelvin_offset); + tz->trips.passive.temperature, + tz->kelvin_offset); return 0; } trip--; @@ -603,8 +600,8 @@ static int thermal_get_trip_temp(struct tz->trips.active[i].flags.valid; i++) { if (!trip) { *temp = deci_kelvin_to_millicelsius_with_offset( - tz->trips.active[i].temperature, - tz->kelvin_offset); + tz->trips.active[i].temperature, + tz->kelvin_offset); return 0; } trip--; @@ -620,15 +617,15 @@ static int thermal_get_crit_temp(struct if (tz->trips.critical.flags.valid) { *temperature = deci_kelvin_to_millicelsius_with_offset( - tz->trips.critical.temperature, - tz->kelvin_offset); + tz->trips.critical.temperature, + tz->kelvin_offset); return 0; } else return -EINVAL; } static int thermal_get_trend(struct thermal_zone_device *thermal, - int trip, enum thermal_trend *trend) + int trip, enum thermal_trend *trend) { struct acpi_thermal *tz = thermal->devdata; enum thermal_trip_type type; @@ -657,9 +654,8 @@ static int thermal_get_trend(struct ther * tz->temperature has already been updated by generic thermal layer, * before this callback being invoked */ - i = (tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature)) - + (tz->trips.passive.tc2 - * (tz->temperature - tz->trips.passive.temperature)); + i = (tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature)) + + (tz->trips.passive.tc2 * (tz->temperature - tz->trips.passive.temperature)); if (i > 0) *trend = THERMAL_TREND_RAISING; @@ -667,6 +663,7 @@ static int thermal_get_trend(struct ther *trend = THERMAL_TREND_DROPPING; else *trend = THERMAL_TREND_STABLE; + return 0; } @@ -691,8 +688,8 @@ static void acpi_thermal_zone_device_cri } static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev, - bool bind) + struct thermal_cooling_device *cdev, + bool bind) { struct acpi_device *device = cdev->devdata; struct acpi_thermal *tz = thermal->devdata; @@ -711,22 +708,23 @@ static int acpi_thermal_cooling_device_c if (tz->trips.passive.flags.valid) { trip++; - for (i = 0; i < tz->trips.passive.devices.count; - i++) { + for (i = 0; i < tz->trips.passive.devices.count; i++) { handle = tz->trips.passive.devices.handles[i]; dev = acpi_fetch_acpi_dev(handle); if (dev != device) continue; + if (bind) - result = - thermal_zone_bind_cooling_device - (thermal, trip, cdev, - THERMAL_NO_LIMIT, THERMAL_NO_LIMIT, - THERMAL_WEIGHT_DEFAULT); + result = thermal_zone_bind_cooling_device( + thermal, trip, cdev, + THERMAL_NO_LIMIT, + THERMAL_NO_LIMIT, + THERMAL_WEIGHT_DEFAULT); else result = - thermal_zone_unbind_cooling_device - (thermal, trip, cdev); + thermal_zone_unbind_cooling_device( + thermal, trip, cdev); + if (result) goto failed; } @@ -735,22 +733,24 @@ static int acpi_thermal_cooling_device_c for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { if (!tz->trips.active[i].flags.valid) break; + trip++; - for (j = 0; - j < tz->trips.active[i].devices.count; - j++) { + for (j = 0; j < tz->trips.active[i].devices.count; j++) { handle = tz->trips.active[i].devices.handles[j]; dev = acpi_fetch_acpi_dev(handle); if (dev != device) continue; + if (bind) - result = thermal_zone_bind_cooling_device - (thermal, trip, cdev, - THERMAL_NO_LIMIT, THERMAL_NO_LIMIT, - THERMAL_WEIGHT_DEFAULT); + result = thermal_zone_bind_cooling_device( + thermal, trip, cdev, + THERMAL_NO_LIMIT, + THERMAL_NO_LIMIT, + THERMAL_WEIGHT_DEFAULT); else - result = thermal_zone_unbind_cooling_device - (thermal, trip, cdev); + result = thermal_zone_unbind_cooling_device( + thermal, trip, cdev); + if (result) goto failed; } @@ -762,14 +762,14 @@ failed: static int acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) + struct thermal_cooling_device *cdev) { return acpi_thermal_cooling_device_cb(thermal, cdev, true); } static int acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev) + struct thermal_cooling_device *cdev) { return acpi_thermal_cooling_device_cb(thermal, cdev, false); } @@ -802,20 +802,20 @@ static int acpi_thermal_register_thermal if (tz->trips.passive.flags.valid) trips++; - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && - tz->trips.active[i].flags.valid; i++, trips++); + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].flags.valid; + i++, trips++); if (tz->trips.passive.flags.valid) - tz->thermal_zone = - thermal_zone_device_register("acpitz", trips, 0, tz, - &acpi_thermal_zone_ops, NULL, - tz->trips.passive.tsp*100, - tz->polling_frequency*100); + tz->thermal_zone = thermal_zone_device_register("acpitz", trips, 0, tz, + &acpi_thermal_zone_ops, NULL, + tz->trips.passive.tsp * 100, + tz->polling_frequency * 100); else tz->thermal_zone = thermal_zone_device_register("acpitz", trips, 0, tz, - &acpi_thermal_zone_ops, NULL, - 0, tz->polling_frequency*100); + &acpi_thermal_zone_ops, NULL, + 0, tz->polling_frequency * 100); + if (IS_ERR(tz->thermal_zone)) return -ENODEV; @@ -881,7 +881,6 @@ static void acpi_thermal_notify(struct a { struct acpi_thermal *tz = acpi_driver_data(device); - if (!tz) return; @@ -893,13 +892,13 @@ static void acpi_thermal_notify(struct a acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_THRESHOLDS); acpi_queue_thermal_check(tz); acpi_bus_generate_netlink_event(device->pnp.device_class, - dev_name(&device->dev), event, 0); + dev_name(&device->dev), event, 0); break; case ACPI_THERMAL_NOTIFY_DEVICES: acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_DEVICES); acpi_queue_thermal_check(tz); acpi_bus_generate_netlink_event(device->pnp.device_class, - dev_name(&device->dev), event, 0); + dev_name(&device->dev), event, 0); break; default: acpi_handle_debug(device->handle, "Unsupported event [0x%x]\n", @@ -944,7 +943,6 @@ static int acpi_thermal_get_info(struct { int result = 0; - if (!tz) return -EINVAL; @@ -1023,7 +1021,6 @@ static int acpi_thermal_add(struct acpi_ int result = 0; struct acpi_thermal *tz = NULL; - if (!device) return -EINVAL; @@ -1099,6 +1096,7 @@ static int acpi_thermal_resume(struct de for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { if (!tz->trips.active[i].flags.valid) break; + tz->trips.active[i].flags.enabled = 1; for (j = 0; j < tz->trips.active[i].devices.count; j++) { result = acpi_bus_update_power( @@ -1119,7 +1117,6 @@ static int acpi_thermal_resume(struct de #endif static int thermal_act(const struct dmi_system_id *d) { - if (act == 0) { pr_notice("%s detected: disabling all active thermal trip points\n", d->ident); @@ -1128,14 +1125,12 @@ static int thermal_act(const struct dmi_ return 0; } static int thermal_nocrt(const struct dmi_system_id *d) { - pr_notice("%s detected: disabling all critical thermal trip point actions.\n", d->ident); nocrt = 1; return 0; } static int thermal_tzp(const struct dmi_system_id *d) { - if (tzp == 0) { pr_notice("%s detected: enabling thermal zone polling\n", d->ident); @@ -1144,7 +1139,6 @@ static int thermal_tzp(const struct dmi_ return 0; } static int thermal_psv(const struct dmi_system_id *d) { - if (psv == 0) { pr_notice("%s detected: disabling all passive thermal trip points\n", d->ident); From patchwork Tue Oct 4 17:26:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 612465 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE442C433FE for ; Tue, 4 Oct 2022 17:27:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229773AbiJDR1T (ORCPT ); Tue, 4 Oct 2022 13:27:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229703AbiJDR1Q (ORCPT ); Tue, 4 Oct 2022 13:27:16 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2563B5E67F for ; Tue, 4 Oct 2022 10:27:10 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id o20-20020a05600c4fd400b003b4a516c479so7960957wmq.1 for ; Tue, 04 Oct 2022 10:27:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aN4DlCPGos4eyvhsW5aRQQoXE+IjMULxnKXbP9xGXDQ=; b=MdmC3bD5Oh/cdnenOJ4NEb7GbyqpiNsMH7lGhHBrJLpw1yx3byvR93U+jh5z5iOGlD b75aU6vU6F+rMmSPGydOKObwpCVCDvk4V3cXM3dkSMsMwN+9IOC1PUKvngNyj3VyNUpz mbogigJ/uimDvPP1hrK0nKkB3d6L0saIiCbnyboPbICRqVt0z8Tj2Je3BJh7fGnuLMox EH0m4+fuYDfz1MxQD8ycqeuWcAWwC/J2d+GXy0+rbaxPbfmUTBOzdZc5VTK81+scNSv/ ctRFKpPCJtg/dRvu5uyCmIjXoqBpFVPiYdnrrPaeUIQ8vzlpFgr1SQhqJFzXEFr2pUWz JM+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aN4DlCPGos4eyvhsW5aRQQoXE+IjMULxnKXbP9xGXDQ=; b=pBVYLKWXgv9dTfcdYoWMFWRRVjE1go5KhUq7f7+XuV1HrQHQOGLGLB5B6xQ89QVgnQ o5yzfLQnn6drOIazplWZheBu4T4s+jGE/hU68DEcpqOU8oxBzpl/1KylVAs3sbIpMH47 ln0s7eQB3M6laRFYq4jvZTsPoBW17cASP85kl25KeitP8ItQTi0pFe9n0NyKXAi4dJLw xOODhqJgLbaz6ZcM32WlAu9f0UZpJU5fFJovAzHSUXGdxJuqvmXT68mCzoPX31A4wo7t T2w8qPPbBa67yWpS1ymNneXPNVytESRVY55gM2PTE1I6iqfZ8ZxVxP8xeMOTsnzXhX+M rvHw== X-Gm-Message-State: ACrzQf38EDRdQCSPjUETPuQrQGxDnrjanh/qsyxXSdwih86Rsx2IrMtF KIi8QjzrvAbN0ryXhXV+jjYGhA== X-Google-Smtp-Source: AMsMyM4fewkyF1YEUvyBECAFoXHpF17NNPpniY1oejie64eK+YzJln4WINw1gXXB15BLecFQmz7z5A== X-Received: by 2002:a05:600c:1d2a:b0:3b4:6e31:92da with SMTP id l42-20020a05600c1d2a00b003b46e3192damr559571wms.103.1664904429185; Tue, 04 Oct 2022 10:27:09 -0700 (PDT) Received: from mai.. ([2a05:6e02:1041:c10:c456:8337:99aa:2667]) by smtp.gmail.com with ESMTPSA id l19-20020a5d5273000000b00228dbf15072sm13060941wrc.62.2022.10.04.10.27.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 10:27:08 -0700 (PDT) From: Daniel Lezcano To: rafael@kernel.org Cc: linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhang Rui , Len Brown Subject: [PATCH RFC 2/9] thermal/acpi: Change to a common acpi_thermal_trip structure Date: Tue, 4 Oct 2022 19:26:51 +0200 Message-Id: <20221004172658.2302511-3-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004172658.2302511-1-daniel.lezcano@linaro.org> References: <12068304.O9o76ZdvQC@kreacher> <20221004172658.2302511-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Do not differentiate hot, critical, passive and active trip points. Use a single acpi_thermal_trip structure. Signed-off-by: Daniel Lezcano --- drivers/acpi/thermal.c | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index b2e73e45c6d6..9620128f05d2 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -119,36 +119,13 @@ struct acpi_thermal_state_flags { u8 reserved:6; }; -struct acpi_thermal_critical { - struct acpi_thermal_state_flags flags; - unsigned long temperature; -}; - -struct acpi_thermal_hot { - struct acpi_thermal_state_flags flags; - unsigned long temperature; -}; - -struct acpi_thermal_passive { +struct acpi_thermal_trip { struct acpi_thermal_state_flags flags; + struct acpi_handle_list devices; unsigned long temperature; unsigned long tc1; unsigned long tc2; unsigned long tsp; - struct acpi_handle_list devices; -}; - -struct acpi_thermal_active { - struct acpi_thermal_state_flags flags; - unsigned long temperature; - struct acpi_handle_list devices; -}; - -struct acpi_thermal_trips { - struct acpi_thermal_critical critical; - struct acpi_thermal_hot hot; - struct acpi_thermal_passive passive; - struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE]; }; struct acpi_thermal_flags { @@ -166,10 +143,10 @@ struct acpi_thermal { volatile u8 zombie; struct acpi_thermal_flags flags; struct acpi_thermal_state state; - struct acpi_thermal_critical critical; - struct acpi_thermal_hot hot; - struct acpi_thermal_passive passive; - struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE]; + struct acpi_thermal_trip critical; + struct acpi_thermal_trip hot; + struct acpi_thermal_trip passive; + struct acpi_thermal_trip active[ACPI_THERMAL_MAX_ACTIVE]; struct acpi_handle_list devices; struct thermal_zone_device *thermal_zone; int kelvin_offset; /* in millidegrees */ From patchwork Tue Oct 4 17:26:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 612464 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1802CC433FE for ; Tue, 4 Oct 2022 17:27:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229810AbiJDR1V (ORCPT ); Tue, 4 Oct 2022 13:27:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229734AbiJDR1R (ORCPT ); Tue, 4 Oct 2022 13:27:17 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69550647C3 for ; Tue, 4 Oct 2022 10:27:12 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id f11so19738676wrm.6 for ; Tue, 04 Oct 2022 10:27:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XO25AA5MH7o6mmP/ulciu6/M0rMSBo6p6lETw4mAlpw=; b=EYd8ISRDRP3m6H0QOJ3lqAOf+GTcDb53IVGkGXxakLLhtte45Jaf3vQy8+MXsceTxF JTeuRMTQ+OcHFTsvGpBar0nVFWi2w9MihV+26iK501AxsjoE32lZzYhiA54dUm1DKkDV GxXphFuSaBNlBw1RpglSx4fOnvOUOZxUVJo+ViHt++gT5FkWM+oRtJwMjDddr6vQEXJ5 RXsiDdAXcHQtm/BNZaasg9Wy4JbvzqxiNueGl30YezOl/CoNfb1/2lhWluzejdeF0gpo JKcGvzggpMhYPwSq+VWpmgdM2UArR8FfXLo3l4yWPjgD43w6XOTOlNsv/e07WD0OzFdb WqkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XO25AA5MH7o6mmP/ulciu6/M0rMSBo6p6lETw4mAlpw=; b=qdOiTa27SpYNMFDyNIbH5Qv84BtyOOnTifCMkzanJvBuPJAsIPx0y7h/OLAuRJQ1q/ r2Eg980yPEkRnz70jRGl6fN061UBgH7UWVZ6d/Ctx0YcJ9kII9XTAo2wMgTAWcQf6bgX ubXJ1ApmJ9J9iB3yYkwUwvI55DlMbnpQig5BB6VmTdV8LsDYxvXihOvFaN25hhS3JGNk iMBEIc5GImRVM1klUMPJrvjlJuouMeA+u2fGoYphImbdsUPNKPcOYICCPhe4ET1bH/JY CT+rDpMetpodl79Qs207aKgOvtjvppDr77yKx50Z1N5+jf7jgsv6zORxtqWmlebpzg+I +SEA== X-Gm-Message-State: ACrzQf1kpbTkZO8yhfFtkoPAG8wXLOZNEW+16q5fQd3uTTTPw7wYtdIA KF7PHLRIWU1+Sdq9AhogIuk3vQ== X-Google-Smtp-Source: AMsMyM7TdOf06JeB9+3SJ05CnANDstNHT8p3fNmJYTRBtajZuQEhDlRBVfxebl+FQkKKeFHEeXe3jA== X-Received: by 2002:a05:6000:18ab:b0:22e:39f1:861a with SMTP id b11-20020a05600018ab00b0022e39f1861amr7260752wri.129.1664904430642; Tue, 04 Oct 2022 10:27:10 -0700 (PDT) Received: from mai.. ([2a05:6e02:1041:c10:c456:8337:99aa:2667]) by smtp.gmail.com with ESMTPSA id l19-20020a5d5273000000b00228dbf15072sm13060941wrc.62.2022.10.04.10.27.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 10:27:10 -0700 (PDT) From: Daniel Lezcano To: rafael@kernel.org Cc: linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhang Rui , Len Brown Subject: [PATCH RFC 3/9] thermal/acpi: Convert the acpi thermal trips to an array Date: Tue, 4 Oct 2022 19:26:52 +0200 Message-Id: <20221004172658.2302511-4-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004172658.2302511-1-daniel.lezcano@linaro.org> References: <12068304.O9o76ZdvQC@kreacher> <20221004172658.2302511-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Instead of having multiple trip points in the structure fields for each trip type, let's create an array of trip points. Signed-off-by: Daniel Lezcano --- drivers/acpi/thermal.c | 131 ++++++++++++++++++++++------------------- 1 file changed, 69 insertions(+), 62 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 9620128f05d2..8bf2b25acdf1 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -104,6 +104,15 @@ static struct acpi_driver acpi_thermal_driver = { .drv.pm = &acpi_thermal_pm, }; +enum { + ACPI_THERMAL_TRIP_CRITICAL, + ACPI_THERMAL_TRIP_HOT, + ACPI_THERMAL_TRIP_PASSIVE, + ACPI_THERMAL_TRIP_ACTIVE +}; + +#define ACPI_THERMAL_TRIP_MAX (ACPI_THERMAL_TRIP_ACTIVE + ACPI_THERMAL_MAX_ACTIVE) + struct acpi_thermal_state { u8 critical:1; u8 hot:1; @@ -143,9 +152,7 @@ struct acpi_thermal { volatile u8 zombie; struct acpi_thermal_flags flags; struct acpi_thermal_state state; - struct acpi_thermal_trip critical; - struct acpi_thermal_trip hot; - struct acpi_thermal_trip passive; + struct acpi_thermal_trip trips[ACPI_THERMAL_TRIP_MAX]; struct acpi_thermal_trip active[ACPI_THERMAL_MAX_ACTIVE]; struct acpi_handle_list devices; struct thermal_zone_device *thermal_zone; @@ -252,7 +259,7 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) if (flag & ACPI_TRIPS_CRITICAL) { status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &tmp); - tz->critical.temperature = tmp; + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature = tmp; /* * Treat freezing temperatures as invalid as well; some * BIOSes return really low values and cause reboots at startup. @@ -260,32 +267,32 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) * ... so lets discard those as invalid. */ if (ACPI_FAILURE(status)) { - tz->critical.flags.valid = 0; + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 0; acpi_handle_debug(tz->device->handle, "No critical threshold\n"); } else if (tmp <= 2732) { pr_info(FW_BUG "Invalid critical threshold (%llu)\n", tmp); - tz->critical.flags.valid = 0; + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 0; } else { - tz->critical.flags.valid = 1; + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 1; acpi_handle_debug(tz->device->handle, "Found critical threshold [%lu]\n", - tz->critical.temperature); + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature); } - if (tz->critical.flags.valid == 1) { + if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid == 1) { if (crt == -1) { - tz->critical.flags.valid = 0; + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 0; } else if (crt > 0) { unsigned long crt_k = celsius_to_deci_kelvin(crt); /* * Allow override critical threshold */ - if (crt_k > tz->critical.temperature) + if (crt_k > tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature) pr_info("Critical threshold %d C\n", crt); - tz->critical.temperature = crt_k; + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature = crt_k; } } } @@ -295,22 +302,22 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) status = acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &tmp); if (ACPI_FAILURE(status)) { - tz->hot.flags.valid = 0; + tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid = 0; acpi_handle_debug(tz->device->handle, "No hot threshold\n"); } else { - tz->hot.temperature = tmp; - tz->hot.flags.valid = 1; + tz->trips[ACPI_THERMAL_TRIP_HOT].temperature = tmp; + tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid = 1; acpi_handle_debug(tz->device->handle, "Found hot threshold [%lu]\n", - tz->hot.temperature); + tz->trips[ACPI_THERMAL_TRIP_HOT].temperature); } } /* Passive (optional) */ - if (((flag & ACPI_TRIPS_PASSIVE) && tz->passive.flags.valid) || + if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) || (flag == ACPI_TRIPS_INIT)) { - valid = tz->passive.flags.valid; + valid = tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid; if (psv == -1) { status = AE_SUPPORT; } else if (psv > 0) { @@ -322,56 +329,56 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) } if (ACPI_FAILURE(status)) - tz->passive.flags.valid = 0; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; else { - tz->passive.temperature = tmp; - tz->passive.flags.valid = 1; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].temperature = tmp; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 1; if (flag == ACPI_TRIPS_INIT) { status = acpi_evaluate_integer( tz->device->handle, "_TC1", NULL, &tmp); if (ACPI_FAILURE(status)) - tz->passive.flags.valid = 0; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; else - tz->passive.tc1 = tmp; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tc1 = tmp; status = acpi_evaluate_integer( tz->device->handle, "_TC2", NULL, &tmp); if (ACPI_FAILURE(status)) - tz->passive.flags.valid = 0; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; else - tz->passive.tc2 = tmp; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tc2 = tmp; status = acpi_evaluate_integer( tz->device->handle, "_TSP", NULL, &tmp); if (ACPI_FAILURE(status)) - tz->passive.flags.valid = 0; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; else - tz->passive.tsp = tmp; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tsp = tmp; } } } - if ((flag & ACPI_TRIPS_DEVICES) && tz->passive.flags.valid) { + if ((flag & ACPI_TRIPS_DEVICES) && tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) { memset(&devices, 0, sizeof(struct acpi_handle_list)); status = acpi_evaluate_reference(tz->device->handle, "_PSL", NULL, &devices); if (ACPI_FAILURE(status)) { acpi_handle_info(tz->device->handle, "Invalid passive threshold\n"); - tz->passive.flags.valid = 0; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; } else - tz->passive.flags.valid = 1; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 1; - if (memcmp(&tz->passive.devices, &devices, + if (memcmp(&tz->trips[ACPI_THERMAL_TRIP_PASSIVE].devices, &devices, sizeof(struct acpi_handle_list))) { - memcpy(&tz->passive.devices, &devices, + memcpy(&tz->trips[ACPI_THERMAL_TRIP_PASSIVE].devices, &devices, sizeof(struct acpi_handle_list)); ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device"); } } if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) { - if (valid != tz->passive.flags.valid) + if (valid != tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state"); } @@ -462,9 +469,9 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) if (ret) return ret; - valid = tz->critical.flags.valid | - tz->hot.flags.valid | - tz->passive.flags.valid; + valid = tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid | + tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid | + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid; for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) valid |= tz->active[i].flags.valid; @@ -504,7 +511,7 @@ static int thermal_get_trip_type(struct thermal_zone_device *thermal, if (!tz || trip < 0) return -EINVAL; - if (tz->critical.flags.valid) { + if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid) { if (!trip) { *type = THERMAL_TRIP_CRITICAL; return 0; @@ -512,7 +519,7 @@ static int thermal_get_trip_type(struct thermal_zone_device *thermal, trip--; } - if (tz->hot.flags.valid) { + if (tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid) { if (!trip) { *type = THERMAL_TRIP_HOT; return 0; @@ -520,7 +527,7 @@ static int thermal_get_trip_type(struct thermal_zone_device *thermal, trip--; } - if (tz->passive.flags.valid) { + if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) { if (!trip) { *type = THERMAL_TRIP_PASSIVE; return 0; @@ -549,30 +556,30 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal, if (!tz || trip < 0) return -EINVAL; - if (tz->critical.flags.valid) { + if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid) { if (!trip) { *temp = deci_kelvin_to_millicelsius_with_offset( - tz->critical.temperature, + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature, tz->kelvin_offset); return 0; } trip--; } - if (tz->hot.flags.valid) { + if (tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid) { if (!trip) { *temp = deci_kelvin_to_millicelsius_with_offset( - tz->hot.temperature, + tz->trips[ACPI_THERMAL_TRIP_HOT].temperature, tz->kelvin_offset); return 0; } trip--; } - if (tz->passive.flags.valid) { + if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) { if (!trip) { *temp = deci_kelvin_to_millicelsius_with_offset( - tz->passive.temperature, + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].temperature, tz->kelvin_offset); return 0; } @@ -598,9 +605,9 @@ static int thermal_get_crit_temp(struct thermal_zone_device *thermal, { struct acpi_thermal *tz = thermal->devdata; - if (tz->critical.flags.valid) { + if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid) { *temperature = deci_kelvin_to_millicelsius_with_offset( - tz->critical.temperature, + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature, tz->kelvin_offset); return 0; } else @@ -637,9 +644,9 @@ static int thermal_get_trend(struct thermal_zone_device *thermal, * tz->temperature has already been updated by generic thermal layer, * before this callback being invoked */ - i = (tz->passive.tc1 * (tz->temperature - tz->last_temperature)) - + (tz->passive.tc2 - * (tz->temperature - tz->passive.temperature)); + i = (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tc1 * (tz->temperature - tz->last_temperature)) + + (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tc2 + * (tz->temperature - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].temperature)); if (i > 0) *trend = THERMAL_TREND_RAISING; @@ -683,17 +690,17 @@ static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal, int trip = -1; int result = 0; - if (tz->critical.flags.valid) + if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid) trip++; - if (tz->hot.flags.valid) + if (tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid) trip++; - if (tz->passive.flags.valid) { + if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) { trip++; - for (i = 0; i < tz->passive.devices.count; + for (i = 0; i < tz->trips[ACPI_THERMAL_TRIP_PASSIVE].devices.count; i++) { - handle = tz->passive.devices.handles[i]; + handle = tz->trips[ACPI_THERMAL_TRIP_PASSIVE].devices.handles[i]; dev = acpi_fetch_acpi_dev(handle); if (dev != device) continue; @@ -773,23 +780,23 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) acpi_status status; int i; - if (tz->critical.flags.valid) + if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid) trips++; - if (tz->hot.flags.valid) + if (tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid) trips++; - if (tz->passive.flags.valid) + if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) trips++; for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->active[i].flags.valid; i++, trips++); - if (tz->passive.flags.valid) + if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) tz->thermal_zone = thermal_zone_device_register("acpitz", trips, 0, tz, &acpi_thermal_zone_ops, NULL, - tz->passive.tsp*100, + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tsp*100, tz->polling_frequency*100); else tz->thermal_zone = @@ -966,8 +973,8 @@ static int acpi_thermal_get_info(struct acpi_thermal *tz) */ static void acpi_thermal_guess_offset(struct acpi_thermal *tz) { - if (tz->critical.flags.valid && - (tz->critical.temperature % 5) == 1) + if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid && + (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature % 5) == 1) tz->kelvin_offset = 273100; else tz->kelvin_offset = 273200; From patchwork Tue Oct 4 17:26:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 612749 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82C6FC433F5 for ; Tue, 4 Oct 2022 17:27:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229840AbiJDR1Y (ORCPT ); Tue, 4 Oct 2022 13:27:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229768AbiJDR1S (ORCPT ); Tue, 4 Oct 2022 13:27:18 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51F2C6564B for ; Tue, 4 Oct 2022 10:27:14 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id ay36so9354169wmb.0 for ; Tue, 04 Oct 2022 10:27:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ruxSNDrAyIsZW86sIahAkKmDpVpE5j1H1T3C5bdYovs=; b=qT6Sc8H6U7PqP88ISMx9JRsYeDCfwmeX8XWzBqw95Zrw1oRDxbv2ZYcI9VAHdjwAB2 pz5kjGKiYP9t4Yr3k+48GNB8t8PzobVT3ivtR840ofya6AZrG/4gmlkEuOj9wa16Jq20 wFmzLe7iNFlxJLBDtGGzPXDqA4tk2jajpOYzizM68o1NlkZj6RivqqxNMIbX09vTGLxN vVlLa8wm/Ury9rWdCoarZ2aPoRntQwlzaFfH5z8whVoojLmuuwUi5kOWKZiirw7pO3fi oyi/oBrgMElJBlDuzedb60Iyuqf+K57GZsK7sv4bx12ik9RJY2hD8xtoue9Sbrd+rcFP CCNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ruxSNDrAyIsZW86sIahAkKmDpVpE5j1H1T3C5bdYovs=; b=D4PDn/v7vXGFeZrXbk9qiYKEf4xSQtsCiEJl11W6A/mx8y/KZWZhacCM5v/5i7dSHi aCiADrLwuRKetMlNUbjrJ9WbNBT6mrNhq1e2/j2o3ypEgJiVBQDHxP8+y9ZCAGeOUbd6 BBKVmgZekCD6YHsSH41ptppoYWKlY85wz072/l1UB0eN3D8vYNHOautS6VzWwP4Tj6pX sFA1adDq+P4gOgPUu75qw9ju4MA5OGJ60mW/FVGK6Tk/YcEOkRITaltdBc++3/YpuV3s WKBZFqFGSbAcrWAKLX8KouyWL1aghu7Y8UXYdGCMmzFPcp3/dmNQVkmIe+/d98WDgacx IaNg== X-Gm-Message-State: ACrzQf1xCQFjVgDFYrSorV4OxOEJXZQmSXLH37qFDQ9YjFsl4AX2vMuS N2c9OHy2Lqiv0QVmVpsYckmamw== X-Google-Smtp-Source: AMsMyM6XiJfl/UzOMKRZDskQDdM+15btP26qbCA/h4X62O/v3STY2X5zlfvron0IxxKvFOluIQLvVg== X-Received: by 2002:a1c:cc0e:0:b0:3b4:fda3:c808 with SMTP id h14-20020a1ccc0e000000b003b4fda3c808mr573627wmb.146.1664904432111; Tue, 04 Oct 2022 10:27:12 -0700 (PDT) Received: from mai.. ([2a05:6e02:1041:c10:c456:8337:99aa:2667]) by smtp.gmail.com with ESMTPSA id l19-20020a5d5273000000b00228dbf15072sm13060941wrc.62.2022.10.04.10.27.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 10:27:11 -0700 (PDT) From: Daniel Lezcano To: rafael@kernel.org Cc: linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhang Rui , Len Brown Subject: [PATCH RFC 4/9] thermal/acpi: Move the active trip points to the same array Date: Tue, 4 Oct 2022 19:26:53 +0200 Message-Id: <20221004172658.2302511-5-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004172658.2302511-1-daniel.lezcano@linaro.org> References: <12068304.O9o76ZdvQC@kreacher> <20221004172658.2302511-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org This change does the second pass to move the active trip points in the thermal trip array. Signed-off-by: Daniel Lezcano --- drivers/acpi/thermal.c | 75 +++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 8bf2b25acdf1..ce37494bd133 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -153,7 +153,6 @@ struct acpi_thermal { struct acpi_thermal_flags flags; struct acpi_thermal_state state; struct acpi_thermal_trip trips[ACPI_THERMAL_TRIP_MAX]; - struct acpi_thermal_trip active[ACPI_THERMAL_MAX_ACTIVE]; struct acpi_handle_list devices; struct thermal_zone_device *thermal_zone; int kelvin_offset; /* in millidegrees */ @@ -383,68 +382,68 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) } /* Active (optional) */ - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) { char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; - valid = tz->active[i].flags.valid; + valid = tz->trips[i].flags.valid; if (act == -1) break; /* disable all active trip points */ if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) && - tz->active[i].flags.valid)) { + tz->trips[i].flags.valid)) { status = acpi_evaluate_integer(tz->device->handle, name, NULL, &tmp); if (ACPI_FAILURE(status)) { - tz->active[i].flags.valid = 0; + tz->trips[i].flags.valid = 0; if (i == 0) break; if (act <= 0) break; if (i == 1) - tz->active[0].temperature = + tz->trips[0].temperature = celsius_to_deci_kelvin(act); else /* * Don't allow override higher than * the next higher trip point */ - tz->active[i - 1].temperature = - (tz->active[i - 2].temperature < + tz->trips[i - 1].temperature = + (tz->trips[i - 2].temperature < celsius_to_deci_kelvin(act) ? - tz->active[i - 2].temperature : + tz->trips[i - 2].temperature : celsius_to_deci_kelvin(act)); break; } else { - tz->active[i].temperature = tmp; - tz->active[i].flags.valid = 1; + tz->trips[i].temperature = tmp; + tz->trips[i].flags.valid = 1; } } name[2] = 'L'; - if ((flag & ACPI_TRIPS_DEVICES) && tz->active[i].flags.valid ) { + if ((flag & ACPI_TRIPS_DEVICES) && tz->trips[i].flags.valid ) { memset(&devices, 0, sizeof(struct acpi_handle_list)); status = acpi_evaluate_reference(tz->device->handle, name, NULL, &devices); if (ACPI_FAILURE(status)) { acpi_handle_info(tz->device->handle, "Invalid active%d threshold\n", i); - tz->active[i].flags.valid = 0; + tz->trips[i].flags.valid = 0; } else - tz->active[i].flags.valid = 1; + tz->trips[i].flags.valid = 1; - if (memcmp(&tz->active[i].devices, &devices, + if (memcmp(&tz->trips[i].devices, &devices, sizeof(struct acpi_handle_list))) { - memcpy(&tz->active[i].devices, &devices, + memcpy(&tz->trips[i].devices, &devices, sizeof(struct acpi_handle_list)); ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device"); } } if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES)) - if (valid != tz->active[i].flags.valid) + if (valid != tz->trips[i].flags.valid) ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state"); - if (!tz->active[i].flags.valid) + if (!tz->trips[i].flags.valid) break; } @@ -473,8 +472,8 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid | tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid; - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) - valid |= tz->active[i].flags.valid; + for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) + valid |= tz->trips[i].flags.valid; if (!valid) { pr_warn(FW_BUG "No valid trip found\n"); @@ -535,8 +534,8 @@ static int thermal_get_trip_type(struct thermal_zone_device *thermal, trip--; } - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && - tz->active[i].flags.valid; i++) { + for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE && + tz->trips[i].flags.valid; i++) { if (!trip) { *type = THERMAL_TRIP_ACTIVE; return 0; @@ -586,11 +585,11 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal, trip--; } - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && - tz->active[i].flags.valid; i++) { + for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE && + tz->trips[i].flags.valid; i++) { if (!trip) { *temp = deci_kelvin_to_millicelsius_with_offset( - tz->active[i].temperature, + tz->trips[i].temperature, tz->kelvin_offset); return 0; } @@ -719,14 +718,14 @@ static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal, } } - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { - if (!tz->active[i].flags.valid) + for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + if (!tz->trips[i].flags.valid) break; trip++; for (j = 0; - j < tz->active[i].devices.count; + j < tz->trips[i].devices.count; j++) { - handle = tz->active[i].devices.handles[j]; + handle = tz->trips[i].devices.handles[j]; dev = acpi_fetch_acpi_dev(handle); if (dev != device) continue; @@ -789,8 +788,8 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) trips++; - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && - tz->active[i].flags.valid; i++, trips++); + for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE && + tz->trips[i].flags.valid; i++, trips++); if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) tz->thermal_zone = @@ -1083,20 +1082,20 @@ static int acpi_thermal_resume(struct device *dev) if (!tz) return -EINVAL; - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { - if (!tz->active[i].flags.valid) + for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + if (!tz->trips[i].flags.valid) break; - tz->active[i].flags.enabled = 1; - for (j = 0; j < tz->active[i].devices.count; j++) { + tz->trips[i].flags.enabled = 1; + for (j = 0; j < tz->trips[i].devices.count; j++) { result = acpi_bus_update_power( - tz->active[i].devices.handles[j], + tz->trips[i].devices.handles[j], &power_state); if (result || (power_state != ACPI_STATE_D0)) { - tz->active[i].flags.enabled = 0; + tz->trips[i].flags.enabled = 0; break; } } - tz->state.active |= tz->active[i].flags.enabled; + tz->state.active |= tz->trips[i].flags.enabled; } acpi_queue_thermal_check(tz); From patchwork Tue Oct 4 17:26:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 612463 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E63D9C433FE for ; Tue, 4 Oct 2022 17:27:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229783AbiJDR1Z (ORCPT ); Tue, 4 Oct 2022 13:27:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229794AbiJDR1T (ORCPT ); Tue, 4 Oct 2022 13:27:19 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 393865F137 for ; Tue, 4 Oct 2022 10:27:15 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id j16so10442872wrh.5 for ; Tue, 04 Oct 2022 10:27:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ffflrD4DXIWja44hBCEf9IQ+O0RpUhCuc08rXykRjDg=; b=o8wah8z8XT1ziWccJxJ9Cmb/4HGi1U8gEOqZUzPdEc2rv/FmTnpl+gj2oR+bB7R+Ef quao0/x+CfVNyMiuCz15YAezFgCGNsq/caIMXmYbH9b4LAGOGUAWU4VnagwUqsS0Xu/5 G+ioBlERSqNGsUSKVxkK3zyMaeTc0V+04Cq7QBC4s1r3uzf4rp9KSMq2PIJeL+3NS9Ax JSPW/EYHn6ERHfnr82Uzul0XpwAog3wGvvSzIldTaPnXXkLj0hNgL62Ft6YvPxT/umyD BMoO9V0TSlEilv2Q+4QuH4uX8U3Mwc+kBrJOr+tmwDFuFEGLQ9XAR5QGMPS5VcmC6a1e dTmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ffflrD4DXIWja44hBCEf9IQ+O0RpUhCuc08rXykRjDg=; b=A7Phqg0NBonGGiSwgd+cm2lcWRpetiUptjeo0ZzrmpoM4qhv4DbOznytmAxSJq4JBD d1hAzUhfHQrKiXnitMFyV8Rxu+bidgDQvR5HDIzZqMEDXZxinqkgYSAPrqbhNiArk7Ja /bCAbjMGk067q7s2rFExodOlspv/BC0DyQHy7RdJ99FDZkGIl+FevLbChaUG1dP0tj/z P7jQ9PA7p6JPC+LV4SCBWs8AxchANBjYF+adCyW/Hvwd1OMfjaG9s0TFuTY1e07kfLPh xW2UWQDixY0yWrIPr6b9VeGT7WSi1QwA++g26QIf9BakhN2gvcFo/CnYaQIQVGMUaQBv VmyA== X-Gm-Message-State: ACrzQf2Sl9ANM9bInn0v/hSh5X+6mJc7Focg5S0JYVSrdClmMptFKKvl Qd3NJGHWsCyRdTow02HjCJaRkg== X-Google-Smtp-Source: AMsMyM5NjECWapjJ7d70XwY9SIHtxnFliyPngXpj7L5b8H234DSD5P7SSw1R2URsRMaDYoK8HMsksw== X-Received: by 2002:a05:6000:1a8f:b0:228:e3c3:679 with SMTP id f15-20020a0560001a8f00b00228e3c30679mr16757847wry.281.1664904433625; Tue, 04 Oct 2022 10:27:13 -0700 (PDT) Received: from mai.. ([2a05:6e02:1041:c10:c456:8337:99aa:2667]) by smtp.gmail.com with ESMTPSA id l19-20020a5d5273000000b00228dbf15072sm13060941wrc.62.2022.10.04.10.27.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 10:27:13 -0700 (PDT) From: Daniel Lezcano To: rafael@kernel.org Cc: linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhang Rui , Len Brown Subject: [PATCH RFC 5/9] thermal/acpi: Optimize get_trip_points() Date: Tue, 4 Oct 2022 19:26:54 +0200 Message-Id: <20221004172658.2302511-6-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004172658.2302511-1-daniel.lezcano@linaro.org> References: <12068304.O9o76ZdvQC@kreacher> <20221004172658.2302511-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The function has two purposes. Initialize the trip points by reading the ACPI table and then doing a check trip points exists. This check will go through all the trip points and at the end if a valid trip point is found, the parsing is considered valid. Instead of checking all the trip points, exit when a valid trip point is found. Signed-off-by: Daniel Lezcano --- drivers/acpi/thermal.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index ce37494bd133..9841b597a9c7 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -463,23 +463,20 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) { - int i, valid, ret = acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT); + int i, ret; + ret = acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT); if (ret) return ret; - valid = tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid | - tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid | - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid; + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + if (tz->trips[i].flags.valid) + return 0; + } - for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) - valid |= tz->trips[i].flags.valid; + pr_warn(FW_BUG "No valid trip found\n"); - if (!valid) { - pr_warn(FW_BUG "No valid trip found\n"); - return -ENODEV; - } - return 0; + return -ENODEV; } /* sys I/F for generic thermal sysfs support */ From patchwork Tue Oct 4 17:26:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 612748 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5762C433F5 for ; Tue, 4 Oct 2022 17:27:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229703AbiJDR11 (ORCPT ); Tue, 4 Oct 2022 13:27:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229802AbiJDR1T (ORCPT ); Tue, 4 Oct 2022 13:27:19 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83B6F564DB for ; Tue, 4 Oct 2022 10:27:16 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id ay7-20020a05600c1e0700b003b49861bf48so1111829wmb.0 for ; Tue, 04 Oct 2022 10:27:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JV78r0khKIiVMoqle2Ji/80JCnIJufCj0psslXCqQ5A=; b=F6wDpcwl5ot3TQcMzPUxRoigjYRXF3M2Y2IAQ2j85gh1vseO7Eo0xFf9d8xlgCQPeK mWfqR/Q/obiFkQmLP90BbfZXT+AafX6xFDCtQqLfL5B2U+H5aotBBpxz79HxjOfWxeee fcPUHhp0xp1yMoHPMQDWF/lelYJBs6ZrslFrk2EowpZ1tHynvx6Qz6IlY1SRwgbwcqAN qWVN48XBdgGbzDwe5MMPXtfBsQRzV2GRQUi+PIgqg5Bd0fNoUjD77GOiHxGXAa2cGZ0n LjlxrLOCc3FmPhY1GdZQ/ZpW2DZKE1r6cbPify6A1QO2iCGCJmegsdXUqxnXh0QPhHik HIQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JV78r0khKIiVMoqle2Ji/80JCnIJufCj0psslXCqQ5A=; b=71owlSfvzPfEamu6uTkRYvx7ZfzayazomOQdlOoP0+1nf1RSjFnfhxOWafmLwPIC1+ BhuVmPbuHis+0vAMS/NTm842jI251k8NYl0xHN20A1tg4B/Dh6VDKQNu+WLM8eFpJGd4 Qin6rCdKEGNYDioUZbcnFuuxQKR6jstNQQ7ja5vURMF3awIQPRAt8wCtPnb2GY2BIcX2 x5ZQkP7LPKhXBIaCG/tsn2iXshdiLl+MjltJazZCBIMaoWi6kDZ0/adeDQ+/lEsJ/IJk 7YYuAVikHOcW7olpBE6p4Dv8/ztrRb4T45uKOYHeaoe39xInVPwQhTB1bDxZMFssDgWD lS2w== X-Gm-Message-State: ACrzQf0dFrsBTSa6l4iIauQm3fc/Ac3RWvhqSSa1b/NsDkYNK8vC5HTj TaQXtbM3kAfc+nnxInG1NOLZ/A== X-Google-Smtp-Source: AMsMyM4fF1yhBIxAQ1lvjEfocDTVgWjd/SuzwVIm6gIeECdmc+PYKnm1lKeoxZTYCDZHaxMdAXv9kw== X-Received: by 2002:a05:600c:21c7:b0:3bd:ef29:2d08 with SMTP id x7-20020a05600c21c700b003bdef292d08mr563673wmj.177.1664904434840; Tue, 04 Oct 2022 10:27:14 -0700 (PDT) Received: from mai.. ([2a05:6e02:1041:c10:c456:8337:99aa:2667]) by smtp.gmail.com with ESMTPSA id l19-20020a5d5273000000b00228dbf15072sm13060941wrc.62.2022.10.04.10.27.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 10:27:14 -0700 (PDT) From: Daniel Lezcano To: rafael@kernel.org Cc: linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhang Rui , Len Brown Subject: [PATCH RFC 6/9] thermal/acpi: Encapsualte in functions the trip initialization Date: Tue, 4 Oct 2022 19:26:55 +0200 Message-Id: <20221004172658.2302511-7-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004172658.2302511-1-daniel.lezcano@linaro.org> References: <12068304.O9o76ZdvQC@kreacher> <20221004172658.2302511-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The thermal trip update function is a bit difficult to read. In order to improve its readability, let's encapuslate the different parts into dedicated functions. Signed-off-by: Daniel Lezcano --- drivers/acpi/thermal.c | 267 ++++++++++++++++++++++++----------------- 1 file changed, 159 insertions(+), 108 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 9841b597a9c7..e62381561255 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -246,117 +246,123 @@ do { \ "Please report to linux-acpi@vger.kernel.org\n", str); \ } while (0) -static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) +static int acpi_thermal_trips_update_critical(struct acpi_thermal *tz, int flag) { acpi_status status = AE_OK; unsigned long long tmp; - struct acpi_handle_list devices; - int valid = 0; - int i; - /* Critical Shutdown */ - if (flag & ACPI_TRIPS_CRITICAL) { - status = acpi_evaluate_integer(tz->device->handle, + status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &tmp); - tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature = tmp; - /* - * Treat freezing temperatures as invalid as well; some - * BIOSes return really low values and cause reboots at startup. - * Below zero (Celsius) values clearly aren't right for sure.. - * ... so lets discard those as invalid. - */ - if (ACPI_FAILURE(status)) { - tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 0; - acpi_handle_debug(tz->device->handle, - "No critical threshold\n"); - } else if (tmp <= 2732) { - pr_info(FW_BUG "Invalid critical threshold (%llu)\n", - tmp); + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature = tmp; + /* + * Treat freezing temperatures as invalid as well; some + * BIOSes return really low values and cause reboots at startup. + * Below zero (Celsius) values clearly aren't right for sure.. + * ... so lets discard those as invalid. + */ + if (ACPI_FAILURE(status)) { + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 0; + acpi_handle_debug(tz->device->handle, + "No critical threshold\n"); + } else if (tmp <= 2732) { + pr_info(FW_BUG "Invalid critical threshold (%llu)\n", + tmp); + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 0; + } else { + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 1; + acpi_handle_debug(tz->device->handle, + "Found critical threshold [%lu]\n", + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature); + } + if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid == 1) { + if (crt == -1) { tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 0; - } else { - tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 1; - acpi_handle_debug(tz->device->handle, - "Found critical threshold [%lu]\n", - tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature); - } - if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid == 1) { - if (crt == -1) { - tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 0; - } else if (crt > 0) { - unsigned long crt_k = celsius_to_deci_kelvin(crt); - - /* - * Allow override critical threshold - */ - if (crt_k > tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature) - pr_info("Critical threshold %d C\n", crt); - - tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature = crt_k; - } + } else if (crt > 0) { + unsigned long crt_k = celsius_to_deci_kelvin(crt); + + /* + * Allow override critical threshold + */ + if (crt_k > tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature) + pr_info("Critical threshold %d C\n", crt); + + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature = crt_k; } } - /* Critical Sleep (optional) */ - if (flag & ACPI_TRIPS_HOT) { - status = acpi_evaluate_integer(tz->device->handle, - "_HOT", NULL, &tmp); - if (ACPI_FAILURE(status)) { - tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid = 0; - acpi_handle_debug(tz->device->handle, - "No hot threshold\n"); - } else { - tz->trips[ACPI_THERMAL_TRIP_HOT].temperature = tmp; - tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid = 1; - acpi_handle_debug(tz->device->handle, - "Found hot threshold [%lu]\n", - tz->trips[ACPI_THERMAL_TRIP_HOT].temperature); - } + return 0; +} + +static int acpi_thermal_trips_update_hot(struct acpi_thermal *tz, int flag) +{ + acpi_status status = AE_OK; + unsigned long long tmp; + + status = acpi_evaluate_integer(tz->device->handle, + "_HOT", NULL, &tmp); + if (ACPI_FAILURE(status)) { + tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid = 0; + acpi_handle_debug(tz->device->handle, + "No hot threshold\n"); + } else { + tz->trips[ACPI_THERMAL_TRIP_HOT].temperature = tmp; + tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid = 1; + acpi_handle_debug(tz->device->handle, + "Found hot threshold [%lu]\n", + tz->trips[ACPI_THERMAL_TRIP_HOT].temperature); } - /* Passive (optional) */ - if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) || - (flag == ACPI_TRIPS_INIT)) { - valid = tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid; - if (psv == -1) { - status = AE_SUPPORT; - } else if (psv > 0) { - tmp = celsius_to_deci_kelvin(psv); - status = AE_OK; - } else { - status = acpi_evaluate_integer(tz->device->handle, - "_PSV", NULL, &tmp); - } + return 0; +} - if (ACPI_FAILURE(status)) - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; - else { - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].temperature = tmp; - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 1; - if (flag == ACPI_TRIPS_INIT) { - status = acpi_evaluate_integer( - tz->device->handle, "_TC1", - NULL, &tmp); - if (ACPI_FAILURE(status)) - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; - else - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tc1 = tmp; - status = acpi_evaluate_integer( - tz->device->handle, "_TC2", - NULL, &tmp); - if (ACPI_FAILURE(status)) - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; - else - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tc2 = tmp; - status = acpi_evaluate_integer( - tz->device->handle, "_TSP", - NULL, &tmp); - if (ACPI_FAILURE(status)) - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; - else - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tsp = tmp; - } +static int acpi_thermal_trips_update_passive(struct acpi_thermal *tz, int flag) +{ + acpi_status status = AE_OK; + unsigned long long tmp; + struct acpi_handle_list devices; + int valid = 0; + + valid = tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid; + if (psv == -1) { + status = AE_SUPPORT; + } else if (psv > 0) { + tmp = celsius_to_deci_kelvin(psv); + status = AE_OK; + } else { + status = acpi_evaluate_integer(tz->device->handle, + "_PSV", NULL, &tmp); + } + + if (ACPI_FAILURE(status)) + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; + else { + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].temperature = tmp; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 1; + if (flag == ACPI_TRIPS_INIT) { + status = acpi_evaluate_integer( + tz->device->handle, "_TC1", + NULL, &tmp); + if (ACPI_FAILURE(status)) + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; + else + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tc1 = tmp; + status = acpi_evaluate_integer( + tz->device->handle, "_TC2", + NULL, &tmp); + if (ACPI_FAILURE(status)) + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; + else + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tc2 = tmp; + status = acpi_evaluate_integer( + tz->device->handle, "_TSP", + NULL, &tmp); + if (ACPI_FAILURE(status)) + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; + else + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tsp = tmp; } } + if ((flag & ACPI_TRIPS_DEVICES) && tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) { memset(&devices, 0, sizeof(struct acpi_handle_list)); status = acpi_evaluate_reference(tz->device->handle, "_PSL", @@ -376,12 +382,23 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device"); } } + if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) { if (valid != tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) - ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state"); + ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state"); } - /* Active (optional) */ + return 0; +} + +static int acpi_thermal_trips_update_active(struct acpi_thermal *tz, int flag) +{ + acpi_status status = AE_OK; + unsigned long long tmp; + struct acpi_handle_list devices; + int valid = 0; + int i; + for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) { char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; valid = tz->trips[i].flags.valid; @@ -447,17 +464,51 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) break; } - if (flag & ACPI_TRIPS_DEVICES) { - memset(&devices, 0, sizeof(devices)); - status = acpi_evaluate_reference(tz->device->handle, "_TZD", - NULL, &devices); - if (ACPI_SUCCESS(status) - && memcmp(&tz->devices, &devices, sizeof(devices))) { - tz->devices = devices; - ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device"); - } + return 0; +} + +static int acpi_thermal_trips_update_devices(struct acpi_thermal *tz, int flag) +{ + acpi_status status = AE_OK; + struct acpi_handle_list devices; + + memset(&devices, 0, sizeof(devices)); + status = acpi_evaluate_reference(tz->device->handle, "_TZD", + NULL, &devices); + if (ACPI_SUCCESS(status) + && memcmp(&tz->devices, &devices, sizeof(devices))) { + tz->devices = devices; + ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device"); + } + + return 0; +} + +static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) +{ + /* Critical Shutdown */ + if (flag & ACPI_TRIPS_CRITICAL) { + acpi_thermal_trips_update_critical(tz, flag); } + /* Critical Sleep (optional) */ + if (flag & ACPI_TRIPS_HOT) { + acpi_thermal_trips_update_hot(tz, flag); + } + + /* Passive (optional) */ + if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) || + (flag == ACPI_TRIPS_INIT)) { + acpi_thermal_trips_update_passive(tz, flag); + } + + /* Active (optional) */ + acpi_thermal_trips_update_active(tz, flag); + + if (flag & ACPI_TRIPS_DEVICES) { + acpi_thermal_trips_update_devices(tz, flag); + } + return 0; } From patchwork Tue Oct 4 17:26:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 612462 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2AD28C433FE for ; Tue, 4 Oct 2022 17:27:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229900AbiJDR13 (ORCPT ); Tue, 4 Oct 2022 13:27:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229640AbiJDR1U (ORCPT ); Tue, 4 Oct 2022 13:27:20 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C53DC5A835 for ; Tue, 4 Oct 2022 10:27:17 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id f11so19739049wrm.6 for ; Tue, 04 Oct 2022 10:27:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=X/wkXK/VoNshwYJ83FzY4wXHrBNAZHWyNhQmshjdi+0=; b=ULlderE9PrJ6jo1NnPTqYQLkjZBAtWAa2Jgc3YfPEKyMdp8aCVIc75YB7FJ0/e42mk z09bZEWgoFsxxNSNJPl6DBhs6JjholHc616znfP78OR4S7rx745fcGkR7gAFWBNXh/2d h3HFUygS3z7pgEw5JE6zKpNuIKdGK9Gp/P80cExsbxNL5PY1tiL7ut2tlEhcjlgB+4Cw layLN59rADcM4r3rywzo2N9pIW4dCpRAbiBjvuKC6L8Zyst0tThrhyZWzLJp6q8uQx7N BFWm0MFEMSe78zJXJM3zABJjZDRtK7v07rEcxsgYqQptebaKtD9SxxlAuW5lqs6WuPVR yfSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X/wkXK/VoNshwYJ83FzY4wXHrBNAZHWyNhQmshjdi+0=; b=pspdVy8SyDvtrxqMt7k9KHHKAfY6OLZmAmBXdlLriHE3GT18FmGmwwtscodVDNrrjc t/YYlZLQXyuBK0vAsxxk/cbBJ3sD+nAiczUiLhbiCkC7mZ5ld5ngwjGvQVGBsX3XG/Ko 9rhSh/BKAxyyo0nL2xUJ1IUo1aAKbYIzsn5RnRiq6APTL3tPLy+o2c6kzzT7pal6cw7+ 1xpgXpMIRwrjcUBQKDkLiiSa+cq8Rs/FEzijyMxBzU251mBblZDg0YzAuB7ayRbfUi0k R6++ggCvz1G40sO1zBaLcjt3GeqlmyqPPsKmYiVAq+6f9PGTy2Li80RHyvvhKYr3UaO4 ijrQ== X-Gm-Message-State: ACrzQf1znthCf9kcED1Js8F4y76VOq8YSMsVRjpT47PUhz04Psau25N0 b/XcJrB4KxfODNx8OBYH+gVd3w== X-Google-Smtp-Source: AMsMyM7Xp8iqAHHWmGPM3+tdztVeDOHDC954tnbDHhlpH4EBnUFR9rfsqtLQlv0GC7PyhdYdnD1n/Q== X-Received: by 2002:a05:6000:1861:b0:22a:bb41:886d with SMTP id d1-20020a056000186100b0022abb41886dmr16757834wri.661.1664904436154; Tue, 04 Oct 2022 10:27:16 -0700 (PDT) Received: from mai.. ([2a05:6e02:1041:c10:c456:8337:99aa:2667]) by smtp.gmail.com with ESMTPSA id l19-20020a5d5273000000b00228dbf15072sm13060941wrc.62.2022.10.04.10.27.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 10:27:15 -0700 (PDT) From: Daniel Lezcano To: rafael@kernel.org Cc: linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhang Rui , Len Brown Subject: [PATCH RFC 7/9] thermal/acpi: Simplifify the condition check Date: Tue, 4 Oct 2022 19:26:56 +0200 Message-Id: <20221004172658.2302511-8-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004172658.2302511-1-daniel.lezcano@linaro.org> References: <12068304.O9o76ZdvQC@kreacher> <20221004172658.2302511-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The condition: if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE)) and on the other side: ACPI_TRIPS_INIT (... | ACPI_TRIPS_ACTIVE) So if the first predicate is true, the second is also true. The 'valid' flag for the trip point is also checked before, so it is pointless to redo the same check again and again. Signed-off-by: Daniel Lezcano --- drivers/acpi/thermal.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index e62381561255..116e5cf19c5d 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -323,6 +323,9 @@ static int acpi_thermal_trips_update_passive(struct acpi_thermal *tz, int flag) int valid = 0; valid = tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid; + if (!valid) + return 0; + if (psv == -1) { status = AE_SUPPORT; } else if (psv > 0) { @@ -401,13 +404,16 @@ static int acpi_thermal_trips_update_active(struct acpi_thermal *tz, int flag) for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) { char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; + valid = tz->trips[i].flags.valid; if (act == -1) break; /* disable all active trip points */ - if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) && - tz->trips[i].flags.valid)) { + if (!tz->trips[i].flags.valid) + continue; + + if (flag & ACPI_TRIPS_ACTIVE) { status = acpi_evaluate_integer(tz->device->handle, name, NULL, &tmp); if (ACPI_FAILURE(status)) { @@ -437,7 +443,7 @@ static int acpi_thermal_trips_update_active(struct acpi_thermal *tz, int flag) } name[2] = 'L'; - if ((flag & ACPI_TRIPS_DEVICES) && tz->trips[i].flags.valid ) { + if (flag & ACPI_TRIPS_DEVICES) { memset(&devices, 0, sizeof(struct acpi_handle_list)); status = acpi_evaluate_reference(tz->device->handle, name, NULL, &devices); @@ -456,6 +462,7 @@ static int acpi_thermal_trips_update_active(struct acpi_thermal *tz, int flag) ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device"); } } + if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES)) if (valid != tz->trips[i].flags.valid) ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state"); @@ -497,8 +504,7 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) } /* Passive (optional) */ - if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) || - (flag == ACPI_TRIPS_INIT)) { + if (flag & ACPI_TRIPS_PASSIVE) { acpi_thermal_trips_update_passive(tz, flag); } From patchwork Tue Oct 4 17:26:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 612747 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 321E7C433F5 for ; Tue, 4 Oct 2022 17:27:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229905AbiJDR1a (ORCPT ); Tue, 4 Oct 2022 13:27:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229812AbiJDR1V (ORCPT ); Tue, 4 Oct 2022 13:27:21 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B84356B82 for ; Tue, 4 Oct 2022 10:27:19 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id w18so13654511wro.7 for ; Tue, 04 Oct 2022 10:27:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=X3dYKf0qeHKGAU0Mki69uVmAl8R+LfwbHqZ8xsk7ums=; b=dII8QRZ6zhyQT9a2/PchBDxFaBAr8L5XyqNrbjTTidqs+PrVbzughtWLokmMb0b8ME CIgnXABDQqiBBkaLVbIRJiuvM5cNqSmVQz38ATAgqE3rLScurH7PajORNFe3zKp6PB0c UJ2LxGHu1a+T2ddxIcUTu6LfOsg4gnXCywMRwFFKaj3OZhoHEY2YROsghbybs3vTH7bl Af13qD2gR48X2LQIgMvDKLe7AfetnewxOIk7dRRa0TLoHncAuIdUSXCsQRgtX/PyG2Zq HMfSUI1a2k6T2gvYryRRTTPkXDv4UYh+KQj1TYxm0lZJb9zeadypDIY1my424slmLCex QbtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X3dYKf0qeHKGAU0Mki69uVmAl8R+LfwbHqZ8xsk7ums=; b=2kzQCp/aCfe355ydygFuJcSqPetJYZRdufoCjn0v5+y239ldzULvdzSgpxqQctXSGF Xmob+B00dk8wh+n/ODTev+OKUANnjUKKVIawPC5L93YivJWal2LRiiKhgfqGoMSKFLD1 tvhZuEJhDWbGOwu5YgIXqv7BB4/bhkx5gQ2RXdU+rgNkPc5msbI8QZADu2rr5D5vSWzG 5QmMV0FriU8E8UXYlmUOdt2KxyM6GNIUu0jXWJYg/ij496ncoNBo09PR376pDtNhjKdE fGBv9FDAj1CO/fE5Jhi8jwh5uXdgGQq2fwNvthwuUrZ7wWMK4aWpGBGQBXoWCqzjpcge eaGg== X-Gm-Message-State: ACrzQf3evPzybB8nncOVcSKe8lC+NU4mpIl406yDZY+I9lSfjUEjUHAN yPVX8O5AmwvP/S8Tdhg6sBc49jZksZVKOA== X-Google-Smtp-Source: AMsMyM4LXI8R1HuZNW+5VD6dycQqURSOfLBrLzAoKRh7h9K6VcQasQv31GKtfIo9sQgarr/piJKXsg== X-Received: by 2002:a5d:4209:0:b0:22c:d5fd:1a06 with SMTP id n9-20020a5d4209000000b0022cd5fd1a06mr15858552wrq.508.1664904437688; Tue, 04 Oct 2022 10:27:17 -0700 (PDT) Received: from mai.. ([2a05:6e02:1041:c10:c456:8337:99aa:2667]) by smtp.gmail.com with ESMTPSA id l19-20020a5d5273000000b00228dbf15072sm13060941wrc.62.2022.10.04.10.27.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 10:27:17 -0700 (PDT) From: Daniel Lezcano To: rafael@kernel.org Cc: linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhang Rui , Len Brown Subject: [PATCH RFC 8/9] thermal/acpi: Remove active and enabled flags Date: Tue, 4 Oct 2022 19:26:57 +0200 Message-Id: <20221004172658.2302511-9-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004172658.2302511-1-daniel.lezcano@linaro.org> References: <12068304.O9o76ZdvQC@kreacher> <20221004172658.2302511-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The 'active' field in the struct acpi_thermal_state is never used. The 'enabled' field of the structure acpi_thermal_state_flags is assigned but never used. Remove them. Signed-off-by: Daniel Lezcano --- drivers/acpi/thermal.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 116e5cf19c5d..f530dbfa80db 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -117,14 +117,12 @@ struct acpi_thermal_state { u8 critical:1; u8 hot:1; u8 passive:1; - u8 active:1; u8 reserved:4; int active_index; }; struct acpi_thermal_state_flags { u8 valid:1; - u8 enabled:1; u8 reserved:6; }; @@ -1139,17 +1137,14 @@ static int acpi_thermal_resume(struct device *dev) for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) { if (!tz->trips[i].flags.valid) break; - tz->trips[i].flags.enabled = 1; + for (j = 0; j < tz->trips[i].devices.count; j++) { result = acpi_bus_update_power( tz->trips[i].devices.handles[j], &power_state); - if (result || (power_state != ACPI_STATE_D0)) { - tz->trips[i].flags.enabled = 0; + if (result || (power_state != ACPI_STATE_D0)) break; - } } - tz->state.active |= tz->trips[i].flags.enabled; } acpi_queue_thermal_check(tz); From patchwork Tue Oct 4 17:26:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 612461 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DC56C433FE for ; Tue, 4 Oct 2022 17:27:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229940AbiJDR1b (ORCPT ); Tue, 4 Oct 2022 13:27:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229816AbiJDR1W (ORCPT ); Tue, 4 Oct 2022 13:27:22 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C0EF543D3 for ; Tue, 4 Oct 2022 10:27:20 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id b4so15432331wrs.1 for ; Tue, 04 Oct 2022 10:27:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uHWVJjYFys4E4VnwcJwmNb2PtDiS0NwkDLnS2KTt1pw=; b=pluwJqgQQFeUu18QT/MQePJPn3oDIyzD7d3xvyWidLpLiqJYr2mv2B7kxxfq4pFNp3 q1iDaVs1NMANu/AENgfAuBgGZjFcXTEa6xK9NWBzn4OFc8b715HSsrSH6Ll0+BLsqjmU 9P7fvpWx7WqegwnAoVCXgjSPAqU1hvQx9Jlxs8AAIxdC/UrHztzHcIyCoYSMxuWnxkyc sx0Z3A6l2mud8VVSuhlSITHntNnxsRj4bwAdbJuthhG6gBeRsCUKrjWbuGiWHegCYs4M Ey9MxqUJi+fVkenpvV1JyTC9kKUJT5IGMGV7sfcd28JipsyjbflWA+WFUIPxliJ1ht/U 7Skg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uHWVJjYFys4E4VnwcJwmNb2PtDiS0NwkDLnS2KTt1pw=; b=rRvc+WgVAmOjqDhzLZu1sgE+jWxug1fBGmhCPvCq7hw5GQldiaQ5kjJEidSlyCPr3w r1iwNN96mbhzNvp3Cqfr5ZrEM/C6uzoQxc1pnbbxAOXO+6Mu+egqj1Q65L4tzzgRoNEG 1O/JOOf/Qdsxubce8Y6lEkV1A4iinSFPvMezJ4WXymZZxpgoIBubpGs5yQlvY0CaM/xS v/2LeeryGnU6z+bBpl9dV904SRWx/FKdnRaH/bCNSvtlertSTEJgBDEAqAjKl0JdWLEe SzFEv+NvZW7vcZa+XCV0Ugdzv7K/zd/iFBPjGdAVh6Jg6Yc6rC3c2fUAhylpajKGauGx NKpA== X-Gm-Message-State: ACrzQf3tcX96TRv8LX1HV0LFjHGorn2acsBBcPI3zI+Md3pia9oiIkCK Wi5MLw/6G9UloYzBgQyfj6vPZg== X-Google-Smtp-Source: AMsMyM5UpumukXIoVvrJrUKr894WHOr/KlXAAce/RDZZCESdtJwSKZmswqVXZTJz+gGA8M12fmPDpA== X-Received: by 2002:a05:6000:144f:b0:22a:94f1:25d6 with SMTP id v15-20020a056000144f00b0022a94f125d6mr16343460wrx.422.1664904438890; Tue, 04 Oct 2022 10:27:18 -0700 (PDT) Received: from mai.. ([2a05:6e02:1041:c10:c456:8337:99aa:2667]) by smtp.gmail.com with ESMTPSA id l19-20020a5d5273000000b00228dbf15072sm13060941wrc.62.2022.10.04.10.27.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 10:27:18 -0700 (PDT) From: Daniel Lezcano To: rafael@kernel.org Cc: linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhang Rui , Len Brown Subject: [PATCH RFC 9/9] thermal/acpi: Rewrite the trip point intialization to use the generic thermal trip Date: Tue, 4 Oct 2022 19:26:58 +0200 Message-Id: <20221004172658.2302511-10-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004172658.2302511-1-daniel.lezcano@linaro.org> References: <12068304.O9o76ZdvQC@kreacher> <20221004172658.2302511-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org We can use the thermal trip points defined in the thermal.h. Let's initialize them properly and when the code will be moved to the generic thermal structure, we will be able to remove the specific acpi trip points. Still WIP. Signed-off-by: Daniel Lezcano --- drivers/acpi/thermal.c | 211 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 186 insertions(+), 25 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index f530dbfa80db..994b96807be3 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -244,6 +244,171 @@ do { \ "Please report to linux-acpi@vger.kernel.org\n", str); \ } while (0) +static void acpi_thermal_trips_override_critical(struct thermal_trip *trip, + int temperature) +{ + int ktemp = = celsius_to_deci_kelvin(temperature); + + if (ktemp > trip->temperature) + pr_info("Overriding %d C\n", temperature); + + trip->temperature = ktemp; +} + +static struct thermal_trip *acpi_thermal_trips_alloc_critical(struct acpi_thermal *tz, + struct thermal_trip *trips, + int *num_trips) +{ + acpi_status status = AE_OK; + unsigned long long temp; + + /* + * Module parameters disable the critical trip point + */ + if (crt < 0) + goto out; + + status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &temp); + if (ACPI_FAILURE(status)) { + acpi_handle_debug(tz->device->handle, "No critical threshold\n"); + goto out; + } + + if (temp <= 2732) { + pr_info(FW_BUG "Invalid critical threshold (%llu)\n", temp); + goto out; + } + + trips = krealloc(trips, sizeof(*trips) * (*num_trips + 1), GFP_KERNEL); + if (!trips) + goto out; + + memset(&trips[*num_trips], 0, sizeof(*trips)); + + trips[*num_trips].temperature = deci_kelvin_to_millicelsius(temp); + trips[*num_trips].type = THERMAL_TRIP_CRITICAL; + + if (crt > 0) + acpi_thermal_trips_override_critical(&trips[*num_trips], crt); + + (*num_trips)++; +out: + return trips; +} + +static struct thermal_trip *acpi_thermal_trips_alloc_hot(struct acpi_thermal *tz, + struct thermal_trip *trips, + int *num_trips) +{ + acpi_status status = AE_OK; + unsigned long long temp; + + status = acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &temp); + if (ACPI_FAILURE(status)) { + acpi_handle_debug(tz->device->handle, "No hot threshold\n"); + goto out; + } + + trips = krealloc(trips, sizeof(*trips) * (*num_trips + 1), GFP_KERNEL); + if (!trips) + goto out; + + memset(&trips[*num_trips], 0, sizeof(*trips)); + + trips[*num_trips].temperature = deci_kelvin_to_millicelsius(temp); + trips[*num_trips].type = THERMAL_TRIP_HOT; + + (*num_trips)++; +out: + return trips; +} + +static struct thermal_trip *acpi_thermal_trips_alloc_passive(struct acpi_thermal *tz, + struct thermal_trip *trips, + int *num_trips) +{ + acpi_status status; + unsigned long long temp; + + /* + * Module parameters disable all passive trip points + */ + if (psv < 0) + goto out; + + status = acpi_evaluate_integer(tz->device->handle, "_PSV", NULL, &temp); + if (ACPI_FAILURE(status)) { + acpi_handle_debug(tz->device->handle, "No passive threshold\n"); + goto out; + } + + trips = krealloc(trips, sizeof(*trips) * (*num_trips + 1), GFP_KERNEL); + if (!trips) + goto out; + + memset(&trips[*num_trips], 0, sizeof(*trips)); + + trips[*num_trips].temperature = deci_kelvin_to_millicelsius(temp); + trips[*num_trips].type = THERMAL_TRIP_PASSIVE; + + (*num_trips)++; +out: + return trips; +} + +static struct thermal_trip *acpi_thermal_trips_alloc_active(struct acpi_thermal *tz, + struct thermal_trip *trips, + int *num_trips) +{ + acpi_status status; + unsigned long long temp; + int i; + + /* + * Module parameters disable all active trip points + */ + if (act < 0) + return trips; + + for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; + + status = acpi_evaluate_integer(tz->device->handle, name, NULL, &temp); + if (ACPI_FAILURE(status)) + break; + + trips = krealloc(trips, sizeof(*trips) * (*num_trips + 1), GFP_KERNEL); + if (!trips) + break; + + memset(&trips[*num_trips], 0, sizeof(*trips)); + + trips[*num_trips].temperature = deci_kelvin_to_millicelsius(temp); + trips[*num_trips].type = THERMAL_TRIP_ACTIVE; + + (*num_trips)++; + } + + return trips; +} + +static struct thermal_trip *acpi_thermal_trips_alloc(struct acpi_thermal *tz, int *num_trips) +{ + struct thermal_trip *trips = NULL; + + *num_trips = 0; + + trips = acpi_thermal_trips_alloc_critical(tz, trips, num_trips); + + trips = acpi_thermal_trips_alloc_hot(tz, trips, num_trips); + + trips = acpi_thermal_trips_alloc_passive(tz, trips, num_trips); + + trips = acpi_thermal_trips_alloc_active(tz, trips, num_trips); + + return trips; +} + static int acpi_thermal_trips_update_critical(struct acpi_thermal *tz, int flag) { acpi_status status = AE_OK; @@ -824,36 +989,24 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { .critical = acpi_thermal_zone_device_critical, }; -static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) +static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz, + struct thermal_trip *trips, + int num_trips) { - int trips = 0; int result; acpi_status status; - int i; - - if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid) - trips++; - - if (tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid) - trips++; - - if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) - trips++; - - for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE && - tz->trips[i].flags.valid; i++, trips++); if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) tz->thermal_zone = - thermal_zone_device_register("acpitz", trips, 0, tz, - &acpi_thermal_zone_ops, NULL, - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tsp*100, - tz->polling_frequency*100); + thermal_zone_device_register_with_trips("acpitz", trips, num_trips, 0, tz, + &acpi_thermal_zone_ops, NULL, + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tsp*100, + tz->polling_frequency*100); else tz->thermal_zone = - thermal_zone_device_register("acpitz", trips, 0, tz, - &acpi_thermal_zone_ops, NULL, - 0, tz->polling_frequency*100); + thermal_zone_device_register_with_trips("acpitz", trips, num_trips, 0, tz, + &acpi_thermal_zone_ops, NULL, + 0, tz->polling_frequency*100); if (IS_ERR(tz->thermal_zone)) return -ENODEV; @@ -1060,7 +1213,8 @@ static int acpi_thermal_add(struct acpi_device *device) { int result = 0; struct acpi_thermal *tz = NULL; - + struct thermal_trip *trips; + int num_trips; if (!device) return -EINVAL; @@ -1081,9 +1235,13 @@ static int acpi_thermal_add(struct acpi_device *device) acpi_thermal_guess_offset(tz); - result = acpi_thermal_register_thermal_zone(tz); + trips = acpi_thermal_trips_alloc(tz, &num_trips); + if (!trips) + goto free_trips; + + result = acpi_thermal_register_thermal_zone(tz, trips, num_trips); if (result) - goto free_memory; + goto free_trips; refcount_set(&tz->thermal_check_count, 3); mutex_init(&tz->thermal_check_lock); @@ -1095,6 +1253,8 @@ static int acpi_thermal_add(struct acpi_device *device) free_memory: kfree(tz); +free_trips: + kfree(trips); end: return result; } @@ -1109,6 +1269,7 @@ static int acpi_thermal_remove(struct acpi_device *device) flush_workqueue(acpi_thermal_pm_queue); tz = acpi_driver_data(device); + kfree(tz->trips); acpi_thermal_unregister_thermal_zone(tz); kfree(tz); return 0;