Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp509609lqr; Wed, 5 Jun 2024 12:17:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWUaf6fArKY6ZU/S+GYLeV+8ijFmytlSy9Y/zKL9cOiDF2QSxXDi+UFzRhbtdAaoiLjAKBleudcAziiWlQ71hIgM+5PXZu6nlR0+Ln9pw== X-Google-Smtp-Source: AGHT+IEyebm07wzCWLOf7Vi+tLOyBeyVNi4bfMt+g0+wXhvNoMG/PYuwYByPQO6EUohCgrpt0VPA X-Received: by 2002:a05:6a00:114e:b0:702:78a2:8d26 with SMTP id d2e1a72fcca58-703e5aacd2bmr3026269b3a.33.1717615062040; Wed, 05 Jun 2024 12:17:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717615062; cv=pass; d=google.com; s=arc-20160816; b=sAhb0WI7ngVtP9nMM2vyr304DED12UmlNiVsF1PI91AirUMIEhz/A5jRhYsWKdVORE eei2SsvetB+fPGU8wef2kbf6ETUsIhedFFfqvw3tpMHHbsJN6qkQgjQHMq70Df7zAnlw hwNihc7C6I/4GaUWld9KW+h9jopsaXaJU2mddhm97j2drzB6M2LC8Hz+GhyLo9a8Lxr+ t9THodgLuwlEYc7rAqZHJnKGKi90IQMdmrxqSIifYFlHu+iOzz36tMupAhuMo4EYPJN4 2WkmvwEBLbYqPhL9TI5cbDaFzr8YN2AwVPBGViwBzK1DaAZwUOBwc/u40KP0sP8T9mGt /WzQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=0i5wNa7LleSWvzC6M30KJZQ4d8UNlVz5/K1juouvkLw=; fh=yUTTXm4awFuG44Q1duog6SiRjKv47s1IJOyw31u+LcY=; b=AzGWEHP6Oaw3UuJKeWKLoFmOWuftD1JKTpF15TLy4UkBfKwqy4YuORO2HpWWCYI2tD B71pLSEZV9G8twiY0TPZnZRfyftyZPhy1gEwwitBSz0q8rka1AM18UCS73ZwUPA7qIRS WDwNDE6eYVlfdtdTOpYBeiKEYjc+ldVXUlfadvWVW+a1FtvRKcZJYRWrSXN273hYa0En v1Cvbt0lom6WQhoDvpDZtuVEfjDSJ8kXG1PL6hWO9aEDtQyfG31owH9sxuhZbs/fbKN0 E9RiGBNproYhdSzCo1h7PlCwKc9+Hs6J4+XhRZtvSPetwwvz1h/02EpqEiKjtN8SgGVE mb7Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@rjwysocki.net header.s=dkim header.b=DNZ1Pomi; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-203092-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203092-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-70242e662e3si943335b3a.397.2024.06.05.12.17.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 12:17:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-203092-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=fail header.i=@rjwysocki.net header.s=dkim header.b=DNZ1Pomi; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-203092-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203092-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A5481286D84 for ; Wed, 5 Jun 2024 19:17:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 938C514A08D; Wed, 5 Jun 2024 19:17:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="DNZ1Pomi" Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A07391420BB; Wed, 5 Jun 2024 19:17:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717615051; cv=none; b=QML80XybCaaItizeiChEWcGLK3IKqU8y/zMBtl67JPVn/lkV7Q14Ws85mpfrI78PC8fKKnAfVi/CvkOmdc62KlFflu+Y+jnu2UWMNBoXjLJO3LzdEHnqOJv9w+0MBADAnvspSXSqr/BJUGIZOo0azTnU5r9+7vrMPb6aOWMOSqI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717615051; c=relaxed/simple; bh=yYpHplzEsye8kf7WqC0u0zc6c/VEQwOHkTd7TJ2eSrE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=fKLw25lzvsbqe/cbNfDqsFzRLh2W7TnFEHEdvKf2lny3oosQd07TUAyicMma1Fhm23Ikau8ffMrrkyh2T1WH+iv9o/N2BqE64h/s92MLf4XD3SsQCrX0G+aMA3GDL7uwA2EB3aWErGSZ2zrcC/4w+cNawylId32Cy2gJaqlzNb0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=fail (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=DNZ1Pomi reason="signature verification failed"; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.1.0) id 456ddfee378ce88f; Wed, 5 Jun 2024 21:17:22 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id ACEC8D512D3; Wed, 5 Jun 2024 21:17:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1717615039; bh=yYpHplzEsye8kf7WqC0u0zc6c/VEQwOHkTd7TJ2eSrE=; h=From:To:Cc:Subject:Date; b=DNZ1PomiVvIv0QpJaNUplGgDKrquROEVkQMWQx9T+vS925/pefnhDfSNDMGExVW9U mueLu1ifKRGI47/VHeKLOxd2fd/PdyRh3cYditPN7Tyx4jHJ0U/7LcidW1rdobEs6W 1gK39zR2Wrh/CNk9VYJPvPKEaxtNBPk5h2+q4M98EPvzqlzAdWAvCDabEon8GVB4mS Vt3cDOHBFAq6T7rhwLGvzTzi//WiHgnBsWpmJCACKDVWD6oxYhMWPW//XJ5ly18i71 OxUdXCsW6DPxw9ZRsNgzSbuVG3spmGpMNCBrT8oAH4pS3BEyQJA1We8nP2C/ICtd6G X8WkfMmmCggFw== From: "Rafael J. Wysocki" To: Linux PM Cc: Linux ACPI , LKML , Lukasz Luba , Srinivas Pandruvada , Zhang Rui , Daniel Lezcano , Laura Nao Subject: [PATCH v1] thermal: core: Do not fail cdev registration because of invalid initial state Date: Wed, 05 Jun 2024 21:17:17 +0200 Message-ID: <4569763.LvFx2qVVIh@kreacher> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvledrvdeliedgudefhecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpeegfffhudejlefhtdegffekteduhfethffhieettefhkeevgfdvgfefieekiefgheenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepkedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehluhhkrghsiidrlhhusggr segrrhhmrdgtohhmpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 From: Rafael J. Wysocki It is reported that commit 31a0fa0019b0 ("thermal/debugfs: Pass cooling device state to thermal_debug_cdev_add()") causes the ACPI fan driver to fail probing on some systems which turns out to be due to the _FST control method returning an invalid value until _FSL is first evaluated for the given fan. If this happens, the .get_cur_state() cooling device callback returns an error and __thermal_cooling_device_register() fails as uses that callback after commit 31a0fa0019b0. Arguably, _FST should not return an inavlid value even if it is evaluated before _FSL, so this may be regarded as a platform firmware issue, but at the same time it is not a good enough reason for failing the cooling device registration where the initial cooling device state is only needed to initialize a thermal debug facility. Accordingly, modify __thermal_cooling_device_register() to pass a negative state value to thermal_debug_cdev_add() instead of failing if the initial .get_cur_state() callback invocation fails and adjust the thermal debug code to ignore negative cooling device state values. Fixes: 31a0fa0019b0 ("thermal/debugfs: Pass cooling device state to thermal_debug_cdev_add()") Closes: https://lore.kernel.org/linux-acpi/20240530153727.843378-1-laura.nao@collabora.com Reported-by: Laura Nao Tested-by: Laura Nao Signed-off-by: Rafael J. Wysocki --- drivers/thermal/thermal_core.c | 11 +++++++---- drivers/thermal/thermal_debugfs.c | 7 ++++++- 2 files changed, 13 insertions(+), 5 deletions(-) Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -964,7 +964,8 @@ __thermal_cooling_device_register(struct { struct thermal_cooling_device *cdev; struct thermal_zone_device *pos = NULL; - unsigned long current_state; + unsigned long val; + int current_state; int id, ret; if (!ops || !ops->get_max_state || !ops->get_cur_state || @@ -1002,9 +1003,11 @@ __thermal_cooling_device_register(struct if (ret) goto out_cdev_type; - ret = cdev->ops->get_cur_state(cdev, ¤t_state); - if (ret) - goto out_cdev_type; + ret = cdev->ops->get_cur_state(cdev, &val); + if (!ret && val >= 0 && val <= INT_MAX) + current_state = val; + else + current_state = -1; thermal_cooling_device_setup_sysfs(cdev); Index: linux-pm/drivers/thermal/thermal_debugfs.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_debugfs.c +++ linux-pm/drivers/thermal/thermal_debugfs.c @@ -421,6 +421,8 @@ void thermal_debug_cdev_state_update(con cdev_dbg = &thermal_dbg->cdev_dbg; old_state = cdev_dbg->current_state; + if (old_state < 0) + goto unlock; /* * Get the old state information in the durations list. If @@ -463,6 +465,7 @@ void thermal_debug_cdev_state_update(con cdev_dbg->total++; +unlock: mutex_unlock(&thermal_dbg->lock); } @@ -499,7 +502,9 @@ void thermal_debug_cdev_add(struct therm * duration will be printed by cdev_dt_seq_show() as expected if it * runs before the first state transition. */ - thermal_debugfs_cdev_record_get(thermal_dbg, cdev_dbg->durations, state); + if (state >= 0) + thermal_debugfs_cdev_record_get(thermal_dbg, cdev_dbg->durations, + state); debugfs_create_file("trans_table", 0400, thermal_dbg->d_top, thermal_dbg, &tt_fops);