From nobody Fri Apr 3 22:31:37 2026 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F3E736680E for ; Sun, 22 Mar 2026 19:07:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774206434; cv=none; b=NYI63eRq3e5u6OrfEPpFaho1Q4PF6+kyqTsXVGUIgd3oOXFMkS2Wq4Oi8QmH6EF1hNzyBVGvBRZFAdisiP3vLPpHBCKBDwbgM13l3on3nBQJZImlvZFlRpuULsXEvhk/BW/VzDo5U6KsSiBRbn0WGumCxT6emuAAWvQo3JiBFE8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774206434; c=relaxed/simple; bh=a65n9qrxIlLmhNIbEN4ovVg4f46IUX7I1DiASQ8NWOg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h2XDLsZv2hiYGWgoVOwb/0LHHgNx0cwF18npwwoCvJkvR2Ba+Qq0cGUdXppnN/2PfuSP//yjGgLyGEa9SxV9hTmhLHWqWTIS0p4YUIefCtsBb8BjXVAhf3diJ8GhWMjsNXWQrifEzTxQzg3I7MyIxrKJORyK7CoHu8JhvgQqbBI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OHp2OwzD; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OHp2OwzD" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-486fca3245cso4969585e9.2 for ; Sun, 22 Mar 2026 12:07:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1774206432; x=1774811232; darn=vger.kernel.org; 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=P9+vTI8xL38TJIAAcKMuD2MJ4WOoS3U7UcRhiuvjKaM=; b=OHp2OwzDMfAclDebwDoDFfA4rqpAfQ7RXKgicMsgynOCZE2n+RTbvvi6h6FbHLWREk RsA1wb55af78KPnyBN9NTpimfKRVFMyYiZbkG3SdBLXwZYatFL4FpiJQ0VBSJwyCfi8W ha+F+rZnn/KZ3Tvb/UUe576Kki0nAAL6Yv34oOgnZegR4P6nf4cPPGQKcUwXMg+qc/Hv RfglimAQwv3phPoFf66kX9ym/VpxJY7vkoWm0FxP2cROlqZOm5YIxBE2yL7pKOU+aGIK 2OZzrrdomeVJ6ZLBdl2QoDxFUsNmzbGRLds5q1jSvuWXCau+jDWOlQfRN4Q+yGsAW/ZN xbqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774206432; x=1774811232; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=P9+vTI8xL38TJIAAcKMuD2MJ4WOoS3U7UcRhiuvjKaM=; b=ORfghD9Uyev5uMcyVqwJAqVHrp8J6VaJ5ZSUqJYjBSbxo8YDL7BoTQqDw5QclDhlWg z9lJPQ8rfBnSU2lxMMfxGcMtzTlS+rAnZS0RondfPfHBd1FKm8WJh0TGzq1+F8f80YG1 dSUz6C6S0tdOgSJ3DA/BVldX+NT7MOib/BsbN7OE56JY7JDg4zblGPE7VYBb4VS7AFOp xhwh+QgwNzQLHim7XqoMyvHIm2IRdRA57lngc0N4iNdqB89RiLeq4Gush6Das8g6ASwP 7aEJ7KA2519vlVaQfiU0IbaepJHfVSSurjW7tRjJz8hhDUxQWlQvsH+502NwoYNe1E0c q+LQ== X-Forwarded-Encrypted: i=1; AJvYcCXBiIb7GtWS2mlDaD5p+BmO2UsHP4BZMrd+X8h2aR/8ocXvhZSQrq8B16X9RHtKd48LZkxm56KwikChhV0=@vger.kernel.org X-Gm-Message-State: AOJu0YwnWAXwhCS6arb9XWuVW4MllFEwUL5Nygjr2NG53H9LK592OmEd KHBeKPJ+uZ5+jUx2D6AC1B2yT5tLs56Se7mj8Ul/Ca/xFPtHC69bIF4x X-Gm-Gg: ATEYQzwX38ns4iE+8wnu7aKN4g7oPD3f6JrqzQJP4WckLz9cofxXxS9tz6GpPewFtNe 2V9mSxdisz6mjAHRnYAKNr83OOLCd4dLPv1DOIuEE3MdGOhAtYwAg/wpc4BGYAKT+3KhFsycoOJ nGj3zbTlVspJ4f69GFCgGmohOr5zFXw0STO9u4n86/yTGYDah6MFdKUT8P5QN468OnWNr3bXwk7 54HkNdgG2gu97k88kpCC1GY9gpH2qdeue/imHq9iDj5vXl5Y1k6DcwxYmCav3O/zzO6WgQUlO5r B1J2TiW5vi6Dw07ticPhB+MwgGSeXfPAiAQPv6yJCBFYRpwNr//JYn+3sdWAhg73+q+k/YXDb+u nMxif5l03X26HjR2E0thrpP4TPqWRroTs/pR1D/CCfNVyPP8Vh7AC6NOJ2mY2E4tTEEDRStFgTp sRqMnTu3NwQD9k8SGFOeLdTAxrK+/ldKg6yW7+6avpVHLZDFlXPyG3uZiTbtGu6OLoynKX3sE= X-Received: by 2002:a05:600c:3ba6:b0:47d:6f12:de57 with SMTP id 5b1f17b1804b1-486fee11756mr83906405e9.4.1774206431316; Sun, 22 Mar 2026 12:07:11 -0700 (PDT) Received: from localhost.localdomain ([46.155.1.197]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-486fe868cb1sm63340595e9.5.2026.03.22.12.07.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Mar 2026 12:07:10 -0700 (PDT) From: Emre Cecanpunar To: platform-driver-x86@vger.kernel.org Cc: hansg@kernel.org, ilpo.jarvinen@linux.intel.com, linux-kernel@vger.kernel.org, krishna.chomal108@gmail.com, Emre Cecanpunar Subject: [PATCH v2 1/5] platform/x86: hp-wmi: fix ignored return values in fan settings Date: Sun, 22 Mar 2026 22:06:20 +0300 Message-ID: <20260322190624.35162-2-emreleno@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260322190624.35162-1-emreleno@gmail.com> References: <20260322190624.35162-1-emreleno@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" hp_wmi_get_fan_count_userdefine_trigger() can fail, but its return value was silently discarded in the PWM_MODE_MAX and PWM_MODE_AUTO cases of hp_wmi_apply_fan_settings(). The same function's return value is already checked in hp_wmi_fan_speed_set(). Propagate errors consistently. hp_wmi_apply_fan_settings() itself returned an error code in all paths, but its callers hp_wmi_hwmon_keep_alive_handler() and hp_wmi_hwmon_init() both discarded the return value. Log failures via pr_warn_ratelimited() in the keep-alive handler (rate-limited because it fires every 90 seconds) and dev_warn() in init (non-fatal: the hwmon device is already registered). Also remove the unreachable "return 0" after the switch statement in hp_wmi_apply_fan_settings(): every case branch already returns explicitly. Signed-off-by: Emre Cecanpunar --- drivers/platform/x86/hp/hp-wmi.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-= wmi.c index 68ede7e5757a..0cb2a2b31998 100644 --- a/drivers/platform/x86/hp/hp-wmi.c +++ b/drivers/platform/x86/hp/hp-wmi.c @@ -2334,8 +2334,11 @@ static int hp_wmi_apply_fan_settings(struct hp_wmi_h= wmon_priv *priv) =20 switch (priv->mode) { case PWM_MODE_MAX: - if (is_victus_s_thermal_profile()) - hp_wmi_get_fan_count_userdefine_trigger(); + if (is_victus_s_thermal_profile()) { + ret =3D hp_wmi_get_fan_count_userdefine_trigger(); + if (ret < 0) + return ret; + } ret =3D hp_wmi_fan_speed_max_set(1); if (ret < 0) return ret; @@ -2353,7 +2356,9 @@ static int hp_wmi_apply_fan_settings(struct hp_wmi_hw= mon_priv *priv) return 0; case PWM_MODE_AUTO: if (is_victus_s_thermal_profile()) { - hp_wmi_get_fan_count_userdefine_trigger(); + ret =3D hp_wmi_get_fan_count_userdefine_trigger(); + if (ret < 0) + return ret; ret =3D hp_wmi_fan_speed_max_reset(priv); } else { ret =3D hp_wmi_fan_speed_max_set(0); @@ -2366,8 +2371,6 @@ static int hp_wmi_apply_fan_settings(struct hp_wmi_hw= mon_priv *priv) /* shouldn't happen */ return -EINVAL; } - - return 0; } =20 static umode_t hp_wmi_hwmon_is_visible(const void *data, @@ -2509,6 +2512,7 @@ static void hp_wmi_hwmon_keep_alive_handler(struct wo= rk_struct *work) { struct delayed_work *dwork; struct hp_wmi_hwmon_priv *priv; + int ret; =20 dwork =3D to_delayed_work(work); priv =3D container_of(dwork, struct hp_wmi_hwmon_priv, keep_alive_dwork); @@ -2516,7 +2520,10 @@ static void hp_wmi_hwmon_keep_alive_handler(struct w= ork_struct *work) * Re-apply the current hwmon context settings. * NOTE: hp_wmi_apply_fan_settings will handle the re-scheduling. */ - hp_wmi_apply_fan_settings(priv); + ret =3D hp_wmi_apply_fan_settings(priv); + if (ret) + pr_warn_ratelimited("keep-alive failed to refresh fan settings: %d\n", + ret); } =20 static int hp_wmi_setup_fan_settings(struct hp_wmi_hwmon_priv *priv) @@ -2578,7 +2585,9 @@ static int hp_wmi_hwmon_init(void) =20 INIT_DELAYED_WORK(&priv->keep_alive_dwork, hp_wmi_hwmon_keep_alive_handle= r); platform_set_drvdata(hp_wmi_platform_dev, priv); - hp_wmi_apply_fan_settings(priv); + ret =3D hp_wmi_apply_fan_settings(priv); + if (ret) + dev_warn(dev, "Failed to apply initial fan settings: %d\n", ret); =20 return 0; } --=20 2.53.0 From nobody Fri Apr 3 22:31:37 2026 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A7A637C11C for ; Sun, 22 Mar 2026 19:07:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774206435; cv=none; b=jkErbU8ASSHnd+dtYkzW2Evw0QTb2aMTzVxS4+FGqE1zC4KZqD+k4/hXiQn6XPa7DA8rJ4oWuWgKXcmSjkeGWZBOxXdJYBPUf69AwB70PRU5hj0Ra2hEy21i1c7UMUeX2k7cMoGaS8wwvVxGNpb546XE54Q7HhZ7bXvt406UMBM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774206435; c=relaxed/simple; bh=cUQdFgJp+vRzURST+mEj40buJgJjr19u5nHUQ/zSxsE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jPFcJoACNaTXC6CUIoPD3OcUqvjDtvo/I3BXsejv+QEED/It0BnkHZrnOKga0JjbMkwuc6UEkdroT2jKudeB7fI6gKh95cHguT1DvRF6bn5mPEWV2ZnPu7Hikaos28krpUVuFuUJqic7J3rW+Zs+QIGZFUv/+VvN9gRamo0gP80= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VpE7PO20; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VpE7PO20" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-4832c8f9d87so5658125e9.3 for ; Sun, 22 Mar 2026 12:07:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1774206433; x=1774811233; darn=vger.kernel.org; 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=SMegNoYPQ15g9bb1XM2RAfuMgiTFEwFZRaFEUS/laHQ=; b=VpE7PO20RaA12vy8qad625wgY5ngwlA/fZLv7AumhMvhQnASbnO9T7fkje4n2Nj9u2 ++oYH2PkYYo1oBDXnClSWSZ6JSZuFyJc9kFOorMHFTSbDVueN643yUI+JZ+Klm0NX3YB Wx7nMw5lzejQ1DS/6D3CnbE4HyG6jfveISMyzSwUjzNIx0Mi7zds572YTUy1KM5Xgnl1 ZUsRGtszDU2AYa9QXWZBvjmQtGs7a0sibX5iysx+A4XU+1wM+MUSnX9AWs6+4DHU6Nbo 4OaChUSDAZAoowzYk008HZT3DZQtrEZI7X9uouk0MHylxtuQYeeuqmmnZNfTVRqKGiko bsgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774206433; x=1774811233; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=SMegNoYPQ15g9bb1XM2RAfuMgiTFEwFZRaFEUS/laHQ=; b=UBLC9aF74bNAst1xvyEoF4/nP1+uveYm5KsXG7I0FYEDAr2j2pE0uaMf199Ugn7ajU brwd8v5GMS5cjn/XkjiwkajINpajGNm3OMfvTN9uzzRkmnRGhZvYbfKjD9Ulyfipmucp rDC19Tk+Bko8RdesH3VFF0dMX2xBHFSU7IeV7CKTqT/KWdbPxgKfa7xIlatNH3ONcJM2 qJEvvLrvcW0x3uRKUvHw7C+mVi1tO8yHyTq9gT9WuQpq1ZYBnFdknsWkKkHe4nJ0jf8D lRWaK/udP8Fmo69j+G0etKN0SQ2ULd7D8iydca2yrdFNW1T8Lw5NR54SrsCd6tMCfHqO CESA== X-Forwarded-Encrypted: i=1; AJvYcCUyiO/kQLLfja9/cCwtfPVnAIR1CIRZDHLzYtbSDgQaRvnHAtBfO0a4sp642s8Sv+S4pXERWMMsHIuEVfs=@vger.kernel.org X-Gm-Message-State: AOJu0YxUt1V4s2CSl+ZkocrUAopXhFDe/bwSVjHd6saMaha4OQCORLVZ tandUUl7xEAIYXSEcm/9p2NZBCedQAf0PJvUZDBrhDwF0fWRTVrdGMm39R6ZX7UL7Tf5hg== X-Gm-Gg: ATEYQzyGoIjxh/Fs56OyFgjN3SyeUybVbFRxQfTCJTsx3Y4WydUO0LIWgkYdUqxZTU8 9pd99e4BbidgL+J3PKIMhnkOJLhQ4SgeRmjdqM6RxHdIlzONi5PM2hgQwq4b6gwFqyM1u+YbdZs 4NpCmr0lD8h2eb6UiVmrFSzvPzzNUGpsws/mzOC9ObVXmZnBKpVnAWrOY1EmZOW7jPgTp9OVZrI v8NswA9tTHjQLIpWEs8Ac/Cq25I7BOViS1NDkkSI6YqzFGQCsZa8+m1beRx0MnkwAf1yBjCbABU sripWqB/Yjs8TZM42dtIEiLZ9lnhXzG2oiJtNgBBFcTTCvziwmeRZa0baDMHpXlBaBBI4Vl6Dun 9lUvL2I40oLz7mguwi4kDrTifJ20G8z0FzrmOUgRK3IITLcJix/wQ2F7nO6oUXthit4HkCTpjMA EdJRrcrZ9ZVcXMmND1bOal1ORRH8YPBxlnU87fpTb2dE+5UbuMRBn9PYxmu1FkE8bhKD1tzms= X-Received: by 2002:a05:600c:3554:b0:477:aed0:f402 with SMTP id 5b1f17b1804b1-486ff01d81amr85441425e9.8.1774206432823; Sun, 22 Mar 2026 12:07:12 -0700 (PDT) Received: from localhost.localdomain ([46.155.1.197]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-486fe868cb1sm63340595e9.5.2026.03.22.12.07.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Mar 2026 12:07:12 -0700 (PDT) From: Emre Cecanpunar To: platform-driver-x86@vger.kernel.org Cc: hansg@kernel.org, ilpo.jarvinen@linux.intel.com, linux-kernel@vger.kernel.org, krishna.chomal108@gmail.com, Emre Cecanpunar Subject: [PATCH v2 2/5] platform/x86: hp-wmi: avoid cancel_delayed_work_sync from work handler Date: Sun, 22 Mar 2026 22:06:21 +0300 Message-ID: <20260322190624.35162-3-emreleno@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260322190624.35162-1-emreleno@gmail.com> References: <20260322190624.35162-1-emreleno@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" hp_wmi_apply_fan_settings() calls cancel_delayed_work_sync() in the PWM_MODE_AUTO case to stop the keep-alive timer. This function is also called from hp_wmi_hwmon_keep_alive_handler(), which is itself a delayed work handler. If the keep-alive work is executing and the fan mode happens to be AUTO (e.g. a concurrent sysfs write changed it just before the handler read priv->mode), cancel_delayed_work_sync() tries to flush the work item it is already running inside, causing a deadlock. The workqueue documentation explicitly requires callers to ensure this self-flush situation does not arise. Replace cancel_delayed_work_sync() with cancel_delayed_work() in hp_wmi_apply_fan_settings(). The non-synchronous variant cancels pending work without waiting for a running instance to complete, avoiding the deadlock. The synchronous cancel in hp_wmi_bios_remove() is unaffected and still provides the final cleanup guarantee at driver removal time. Signed-off-by: Emre Cecanpunar --- drivers/platform/x86/hp/hp-wmi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-= wmi.c index 0cb2a2b31998..41769c0861e5 100644 --- a/drivers/platform/x86/hp/hp-wmi.c +++ b/drivers/platform/x86/hp/hp-wmi.c @@ -2365,7 +2365,7 @@ static int hp_wmi_apply_fan_settings(struct hp_wmi_hw= mon_priv *priv) } if (ret < 0) return ret; - cancel_delayed_work_sync(&priv->keep_alive_dwork); + cancel_delayed_work(&priv->keep_alive_dwork); return 0; default: /* shouldn't happen */ --=20 2.53.0 From nobody Fri Apr 3 22:31:37 2026 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BDF3E34CFC5 for ; Sun, 22 Mar 2026 19:07:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774206438; cv=none; b=qtW7A74YY6Slozzovk1ovUs52Y/qdzPKBl1QOfXZGLNsjk714o/f1K5v/+owsVHMcjnnlIUQZaZOsDw2zXD/qOw31n0ou9x1eRvX2HxmtkGBoRhvjXogWjv1e/qIjEQakbzJGDhw2pZvq/tTPSd+Bf4Xc0WDN+f9axyqYYO8ifg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774206438; c=relaxed/simple; bh=oLKGlkhw2FIIbPnQj7+BVbg/ng9EcldtKCH1eAUAjOY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o6/C0dkop+1t/f0ZYByURKwqChJNC/SZ6Es3+twX3UEfgmN/2W51nVlws4JokwqWhhffMpGE69Z1AUsSqwvqbbGH111MwM/GHyJp8hMRUnWg7XnL9GaO64GlNaLaM9BnLyqHWXTSAmDvw62mrapMaAWiT0tzbt6YhUtIkIGz+OY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=V12enzfM; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="V12enzfM" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-486fc3ac9fdso4285665e9.1 for ; Sun, 22 Mar 2026 12:07:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1774206435; x=1774811235; darn=vger.kernel.org; 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=yHNkiyRvuF9AQ8guLO6hV3hpVtlWV/mWDZ+jV3RDgbg=; b=V12enzfMJeUCA8PbnLb/J04GReoi223CpNFVd8PYSp827w4r3XYVqOPcb+drrGAhbY 15fBceS/prwIkCdM8O+m+bWGlN0IcJBf1AfT79FBOY96EgylEZ9TaGWVmlgneIVTqYhe ksG6+VsxuNpY0i/S1R9LyK6pewoo7aeWRL6lX9YnDuYB+UEr9WeAMXpjNZGjli3N5r0r 2XMXPHUXCg55YDWnc9jO4kl592IO+iaztMFP1clHqogkY60rfHoVpNTVndsQ14JMqp4I M2MWEDufquzB5zz7+hWsiXvWk6mZiknHUQ5m0GEUxNZyOhuVvvklMTegH/vHxtmCYCJF eAoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774206435; x=1774811235; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=yHNkiyRvuF9AQ8guLO6hV3hpVtlWV/mWDZ+jV3RDgbg=; b=KPIp0ojW5SQRKjz69F6MXJDj81NcO4BKdcjVIAxX5f4gDbX1UTo/aM2YjlKq8Tl+s6 zhDihK4p4IrC9BZnL64KVFjemZgOSCvo4SRuuDtyPA90AgdcWUX0WZ1aKwJYGThFi34I DqlbmVqhM1KtQMEMNNHmcbh5l3ayKzmzJm0x++NlR45C3bq5vOZweeWrajAhNbb3UHTS imotNklWZmG9e2IjOYXYhDPXWs8RMpOx67LfBHDVY6ulWzfLdt4E1aL4qCFrBS+Tc68F STRDxs4eHvPZzHZcZ1JxmqBDizBgAFKrfRj8jjam/gHCKcQBRAXul+c5zDecpzbPPvUM 2gQw== X-Forwarded-Encrypted: i=1; AJvYcCWln9lvUXPliW5t8o9Hd6CP+4airjJ4uzgqU1gH2xd1OIadhypBxMhqPHkgb0iUu0dPLK8fEU2SvJEA+7I=@vger.kernel.org X-Gm-Message-State: AOJu0Ywj4775zLcE2FyGTDsN1NFsXWhwFVuWzjSI874ayf1sI1o3SCVQ 2GDeFxAB5sHOYlrh/D7xm6z/0qbGdabcK/Gbu1ubG6WJ7Lm9p6bvbFLf X-Gm-Gg: ATEYQzxdYvd1a2rzxmCBinEkBL9zffjSh/2YZs/RisWAUGFkkF9n9nJ9RVTwS6ft+HX OGVeMQZHpp48WSm+TlbFeY5KXGK77VyPeS8y2LHQSR51eeqA2ekDyp4Y00HO04wOBAlY0gG8nEs O7lauNwZ1XEWNpuhBuF5fZcfrFeAmyLi7JZDbiKfaARK4I55mhXTW4YdzOZvXC4NrtcyBdmvrcA d0I4XEv0HoEXZzvdaU/E6ZGhk/9j0qT6q2Z4w0eB2gTPUPlxk/ZQTCah81OuHan3E1GSXa1zqx8 tBt3G/n0/i5NWPjA3i5Ym9l20Q3q7gj7icp7aH79czssa0d4m7uZHJaJKLapois4oouV6+BZUHx 6viHIkvMUyrHnVu4iB6QYMCRwIrmHR0E6L5S+J/BxGRdGW+S1X/zIW5kHFwJNgevD5aQqONrFnZ sHmR9oy3hS5djWSufcmdOa+m5BRn24FJS3Us+EZn6ssoT7fc/v8oIIxm3HKLwe1hwpJ+G1LwU= X-Received: by 2002:a05:600c:138a:b0:485:3177:d805 with SMTP id 5b1f17b1804b1-486fee29279mr81465475e9.7.1774206435068; Sun, 22 Mar 2026 12:07:15 -0700 (PDT) Received: from localhost.localdomain ([46.155.1.197]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-486fe868cb1sm63340595e9.5.2026.03.22.12.07.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Mar 2026 12:07:14 -0700 (PDT) From: Emre Cecanpunar To: platform-driver-x86@vger.kernel.org Cc: hansg@kernel.org, ilpo.jarvinen@linux.intel.com, linux-kernel@vger.kernel.org, krishna.chomal108@gmail.com, Emre Cecanpunar Subject: [PATCH v2 3/5] platform/x86: hp-wmi: use mod_delayed_work to reset keep-alive timer Date: Sun, 22 Mar 2026 22:06:22 +0300 Message-ID: <20260322190624.35162-4-emreleno@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260322190624.35162-1-emreleno@gmail.com> References: <20260322190624.35162-1-emreleno@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The keep-alive mechanism re-applies fan settings every 90 seconds to prevent the firmware from reverting to automatic mode after its 120 s timeout. Fan settings are also applied immediately when the user writes to the hwmon sysfs interface. schedule_delayed_work() is a no-op when the work item is already pending. If the user updates fan settings at T=3D85s, the keep-alive still fires at T=3D90s (5 s after the update) instead of 90 s later. This shortens the effective keep-alive window and may allow the firmware timeout to expire between cycles. Replace schedule_delayed_work() with mod_delayed_work() in both the PWM_MODE_MAX and PWM_MODE_MANUAL cases. mod_delayed_work() resets the delay to KEEP_ALIVE_DELAY_SECS from the time of each call, whether or not the work is already pending, ensuring each user action and each keep-alive expiry restarts the full 90 s window. Signed-off-by: Emre Cecanpunar --- drivers/platform/x86/hp/hp-wmi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-= wmi.c index 41769c0861e5..a29f34588055 100644 --- a/drivers/platform/x86/hp/hp-wmi.c +++ b/drivers/platform/x86/hp/hp-wmi.c @@ -2342,8 +2342,8 @@ static int hp_wmi_apply_fan_settings(struct hp_wmi_hw= mon_priv *priv) ret =3D hp_wmi_fan_speed_max_set(1); if (ret < 0) return ret; - schedule_delayed_work(&priv->keep_alive_dwork, - secs_to_jiffies(KEEP_ALIVE_DELAY_SECS)); + mod_delayed_work(system_wq, &priv->keep_alive_dwork, + secs_to_jiffies(KEEP_ALIVE_DELAY_SECS)); return 0; case PWM_MODE_MANUAL: if (!is_victus_s_thermal_profile()) @@ -2351,8 +2351,8 @@ static int hp_wmi_apply_fan_settings(struct hp_wmi_hw= mon_priv *priv) ret =3D hp_wmi_fan_speed_set(priv, pwm_to_rpm(priv->pwm, priv)); if (ret < 0) return ret; - schedule_delayed_work(&priv->keep_alive_dwork, - secs_to_jiffies(KEEP_ALIVE_DELAY_SECS)); + mod_delayed_work(system_wq, &priv->keep_alive_dwork, + secs_to_jiffies(KEEP_ALIVE_DELAY_SECS)); return 0; case PWM_MODE_AUTO: if (is_victus_s_thermal_profile()) { --=20 2.53.0 From nobody Fri Apr 3 22:31:37 2026 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2346A37C11C for ; Sun, 22 Mar 2026 19:07:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774206440; cv=none; b=Cnk7oDZKynohTG7vGxBh2GDOwTysUNXle3Ro3DEZyJ2WzUiKHB9IBiezfGB1NC/Si+LCJ1U4VEizEppVP7hvJ1ukhAqCmm6Cx/7zpEeV45YeFK1MFYNlardSTpbjMW/rFJxk4e1w8qW24i+5VTUEF8DGyuTd22wLSoStIEp3Yow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774206440; c=relaxed/simple; bh=b2Yu4QNmTqQ7VgOgSC58XEL8/pOhTJNoN/AnRGyQ49M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i5zN5iUF4644IoGSLO8W5EhpiPI5PLtQlmjtxF2huWXV/WStFyUNpsjRU4Fb8M7XSZUuaFB17qEBDzDJCNB7XVybhQEHPgXuVP9STeElCTJr00NueWOuzLH6dpB+8uqwII3elgRM0WDRTPs29EBbB627YZQ6uTP6/Ie9WDOQs3I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bR+p1Vu/; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bR+p1Vu/" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-486fca3245cso4969685e9.2 for ; Sun, 22 Mar 2026 12:07:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1774206437; x=1774811237; darn=vger.kernel.org; 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=eC4Vcl8jB5v5qB0mNZx8g21iRBAwUU3PRlx8EqzAROA=; b=bR+p1Vu/bRkhme126AfZM/SUnsFPy9UNrWb4wRUYcvszF76z6NF+0I3nkwc6x2/4ID Dgs9NFzguZhhxn693eVoPuN/p8u5HiYEnxgU8EhqnH0184lM1UQg9bvoIWTAESPPsRKy 5lsA4Et4gI4JhXQCa/za/CdaHDh8jy3RQaXaUmVsLdQDsXAIZOVaRNVs2Op8Bu3EnyhC VFLrkhuEQAjaE7mT/KDRYrWGdFaMNBqXYwLsGXgAbOasc7FeIOxbYA/SoryUhb6bv8Ud apAHDZE8FFqrHOrXCOerCiT4us5ux9ZnJt3xDvAIm4em1somUevVtLwaZ2mWkLwEG/Q/ 0Piw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774206437; x=1774811237; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=eC4Vcl8jB5v5qB0mNZx8g21iRBAwUU3PRlx8EqzAROA=; b=gKdJ2y3ju3R52tFeAAxoGZTvaYKM5/rx8x38X6g6o6d1/bKipYxZ1ArNiKGujD6mjs BVpXJGnqiasEBGF/f5q9ZcoAdY3nCka8xDZA4myIYDdINJZpmc32m9GYMTj/5JdrzawA xq3jcBj8xflKi2Sb05zZtBNB3J2DB0288tU8rejeAfA/psnTZs0JmakuQr5rYXnvcmCF u8D3nNzd8zhCJL7HKBZJpsg3kwwXHEk09slyXgZerdpQI7S5CAngug8+ncFimRsSAEeW raSLfaI8HDXSIlnwY1VTr2sqAnj6ZUnlFVO6gOZ58RJkjxWilcdL/EWyneOY/nV64nP2 NlQA== X-Forwarded-Encrypted: i=1; AJvYcCULqrIJfRykapJIV5/p9q0IDupQ5qKaAMIkU1Y+90cS57MIfvRTv+uWTW68p2CNG2Os5QV3YV8e7MWf1Q0=@vger.kernel.org X-Gm-Message-State: AOJu0Ywho2D+/RLzFhor9MMxEmRWpbEj42/K7vZYDRsG508rcZRKpvkW Q9N6hIX5sz7m366c69ue7bX/9ZH/uLCVM24NKnJqZRYnLRHt/UdP7/Ht X-Gm-Gg: ATEYQzwLip24jjRka8gd0MbUIL1uzxADXZXMZX9EUhY5EMqLBI06D5u9wJb36HKQ/Sc NBKHOXzlLLEWe5n2jzIyvhqlZIwHlEUhSB2Xs5NNqwJWtn9YRvznnVQF+nNj0tOqWKhidOXNHNx e4v+30ENVThILDjujrzVivXbRx74CuY8kU+Zc3DebaF/0j92dZ4tvwsTKKbPAgofF8+Ry+qA+kR JaIpSc5NG2YZAMQGnATDRmllO0k8/fKOGBYbged09vFsfSgfZhSAXNWK2vGa9pOjn8P0lAtD6PE OAaFQCc9/rLXevYuHY4Futj9b8ySVj2g4ndOfyUfn7yj4jTCU0eTk2ZCP+PJM+JUYI+QOLwIKDu VyIsS0Xwsd9FUqiL2aIpFLeM8jhb/FElZ9Abbjmjsyvm51vl9KJD16XSyJdl8Gb7mPKatU6y/5J cIRsUY8uV6q8T/OPOCkHEQvTEnTuEGaiGl4wz7zQaLJwFKZ9eDZfdq6TLc3CUALsiHfeiZf1A= X-Received: by 2002:a05:600c:3105:b0:485:3bc7:a224 with SMTP id 5b1f17b1804b1-486ff01b279mr83078485e9.6.1774206437259; Sun, 22 Mar 2026 12:07:17 -0700 (PDT) Received: from localhost.localdomain ([46.155.1.197]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-486fe868cb1sm63340595e9.5.2026.03.22.12.07.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Mar 2026 12:07:16 -0700 (PDT) From: Emre Cecanpunar To: platform-driver-x86@vger.kernel.org Cc: hansg@kernel.org, ilpo.jarvinen@linux.intel.com, linux-kernel@vger.kernel.org, krishna.chomal108@gmail.com, Emre Cecanpunar Subject: [PATCH v2 4/5] platform/x86: hp-wmi: fix u8 underflow in gpu_delta calculation Date: Sun, 22 Mar 2026 22:06:23 +0300 Message-ID: <20260322190624.35162-5-emreleno@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260322190624.35162-1-emreleno@gmail.com> References: <20260322190624.35162-1-emreleno@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" gpu_delta was declared as u8 and computed as the difference of two u8 fan RPM values from the firmware fan table. If gpu_rpm < cpu_rpm, the subtraction wraps around modulo 256, producing a large positive value (e.g. 10 - 20 =3D 246 as u8). This value is then added to every requested fan speed in hp_wmi_fan_speed_set(), causing the GPU fan to be clamped to U8_MAX on almost every write. Change gpu_delta to int in both struct hp_wmi_hwmon_priv and hp_wmi_setup_fan_settings(), and perform the subtraction in signed arithmetic. hp_wmi_fan_speed_set() already uses signed arithmetic with clamp_val(), so a negative delta correctly results in a lower GPU fan speed rather than saturating at U8_MAX. Signed-off-by: Emre Cecanpunar --- Changes in v2: - Drop the if (gpu_delta < 0) guard and pr_warn. A negative delta is valid firmware behavior on boards where CPU_RPM > GPU_RPM. Store gpu_delta as int in struct hp_wmi_hwmon_priv so the existing signed arithmetic and clamp_val() in hp_wmi_fan_speed_set() handle the negative case correctly without saturating at U8_MAX. drivers/platform/x86/hp/hp-wmi.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-= wmi.c index a29f34588055..af57cb0dbf9e 100644 --- a/drivers/platform/x86/hp/hp-wmi.c +++ b/drivers/platform/x86/hp/hp-wmi.c @@ -436,7 +436,7 @@ enum pwm_modes { struct hp_wmi_hwmon_priv { u8 min_rpm; u8 max_rpm; - u8 gpu_delta; + int gpu_delta; u8 mode; u8 pwm; struct delayed_work keep_alive_dwork; @@ -2530,8 +2530,8 @@ static int hp_wmi_setup_fan_settings(struct hp_wmi_hw= mon_priv *priv) { u8 fan_data[128] =3D { 0 }; struct victus_s_fan_table *fan_table; - u8 min_rpm, max_rpm, gpu_delta; - int ret; + u8 min_rpm, max_rpm; + int gpu_delta, ret; /* Default behaviour on hwmon init is automatic mode */ priv->mode =3D PWM_MODE_AUTO; @@ -2553,7 +2553,8 @@ static int hp_wmi_setup_fan_settings(struct hp_wmi_hw= mon_priv *priv) min_rpm =3D fan_table->entries[0].cpu_rpm; max_rpm =3D fan_table->entries[fan_table->header.num_entries - 1].cpu_rpm; - gpu_delta =3D fan_table->entries[0].gpu_rpm - fan_table->entries[0].cpu_r= pm; + gpu_delta =3D (int)fan_table->entries[0].gpu_rpm - + (int)fan_table->entries[0].cpu_rpm; priv->min_rpm =3D min_rpm; priv->max_rpm =3D max_rpm; priv->gpu_delta =3D gpu_delta; -- 2.53.0 From nobody Fri Apr 3 22:31:37 2026 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6FE9737EFF3 for ; Sun, 22 Mar 2026 19:07:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774206441; cv=none; b=hDTJwavRJvyk6EcwcL/rPtjyt4fgNydJVKorgMKuL3lHmv8gxekvRGHwYHtyw8MvsIpftWAHHaAhvN7ILuNdPa/jPEXpzN747ipxm2XZjFPNENwIVKlzyIqewvURGxuI60r2RbBOLnEpZmXMCEJK5hjoP2pmj3Yhz8T/d0NyztU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774206441; c=relaxed/simple; bh=9RXmA3V8mcAT6ll5oI10EzAS5EXkafvVpG2jgW4lEGA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=guF05sYhPTlMT6NG+qghd/8q50bGqhB2MwJyzmwOEHt4tv/MxS9xHdhRrndeetfIONJttco6PoOUKN/T/bpcHsjqlfwcBOrb1duz3yaWxhsV7mWugnFEOKl0Snrpf9pOpOTDvtlKX5vUN9iWEf7JUJjhtRS+0ILxJnxF2jJroOI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mT/oMSNm; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mT/oMSNm" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-486fca3245cso4969725e9.2 for ; Sun, 22 Mar 2026 12:07:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1774206439; x=1774811239; darn=vger.kernel.org; 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=T7L1ojh/JII8uIiYNtov3hn1GnFD4U/IU8c1ArxwoPI=; b=mT/oMSNmzlhVWnXUrhy3LvOpr9xhXX77TcilQ+9ccITRWBnFUrLgk861HJhQAVwJpD qkxyMj2vJVchykSRLlhSCbMRbHi92JIuapNhlZ89whktJWHr94Zc+Xl8Fwyj5NEkeLTS BWTjdWpavIS8ru5elYvKJoxRqVW4y3VXOKNee76aTi3g96h3l51Ta1GhCxaRQ638XpZz cpBxU55EZCoaFYpFY05sEsx0JkJMcqbj5/pWtzTA1ButGqddx3z7apc5e+gwd4JE6s0b YTXuHl8Am1hNBZUCJe9kiC+YrpMojddZYNEMqUFMXpuYrpqQarKZzgeMl8I6cyr2FiRY dF/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774206439; x=1774811239; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=T7L1ojh/JII8uIiYNtov3hn1GnFD4U/IU8c1ArxwoPI=; b=Ec/0q2jubZLWdmevqaKs8FQWvCA1BOy33JL4Dgg8eTyrQIi7A+AkCiWEMS23XjF1bm 0AoIceX0j9UBN0MwzRKdiPW2PPzACdUx4/ZcaIQsOmnn2NdqFISWGZ7bxDNXM1OVWpxV yKjmwIensjmDydD8VRq00Dw/MbkqVL0f2EgTmpwnGJMFo3W6i0DHylk6RGxD9RgRx6/a o+Rx1N33MSzvcIZ49jLaCwp1Ox0YIbp8PljM4wKfcUw+2wVzSLg7t21cl6AWkikxLsv3 kDnvaHhkXyN7DEXh3fz9LJkgr+DS+R0+WtaUSgg1xl3stou6qiYwu3hiZY+Uc83FTTSY Iydg== X-Forwarded-Encrypted: i=1; AJvYcCVh7kWPOpfFB3Mg1yCLqs4E/xHV2uBk67ynsqXPKdYiQJUF4eSGMOtPTaiyKWsS7A+NdFlPqsuqsa/uxjo=@vger.kernel.org X-Gm-Message-State: AOJu0Ywq4pQ8XwVhJWg/chK7qaAObd5WINUDpigiGuLS/tfr19DI1rtO jjuustAR1b5hfYDEfHFtySYu3UW+u54+X3FaVd2cCH1I36BmfCB2b7Cj X-Gm-Gg: ATEYQzxlj3qOPws+KaEtbn4rzTPEmDWlP/ZaPKC0QztbNaQ9agJNhMwQaVl21768zAR 3N0Z/AfKeXUzB4mVF9s8Ha/EFd8yyO5/0U55CaqzCOc01OmsvLfkP0A8nIv83pztXwhgpfxyjt2 ZN+itTGB7e4WwNGZ4YoZoAULQjzmHGxQIu4CX8rYtEMfsoSFj873CyYEkQ+G1t3ZrYns8ibaBC2 z2B4+B7lGjYTIFoglb6N4codbn6MuZmR9iAX1NCQdb60UnY4XXyL2BV5Ew9srWIFDNE5LH1Lov/ pr/VdKnQRj672UiuKQD997CH+INM7Ag26Cp9Ohs0AfolQP33T22EnJEGg0xi3nNmH5yVfiA/mCb usQNekAQXve+kBGnk8/pw9F8i9DYHCwYln5jCMqjhhKBRuiOuCpsmgQjePfcwfk1ENKEGdu1rak iodY0UORxl3YL8xzPjconoOTqOlL5LBF6b5hzDAHJQwP/v7z0fdmA2hFxtCcYHoB6eAcuWsfS2f 1Xpl7xQKw== X-Received: by 2002:a05:600c:4509:b0:486:b967:5c9b with SMTP id 5b1f17b1804b1-486fee1161bmr89737375e9.3.1774206438759; Sun, 22 Mar 2026 12:07:18 -0700 (PDT) Received: from localhost.localdomain ([46.155.1.197]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-486fe868cb1sm63340595e9.5.2026.03.22.12.07.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Mar 2026 12:07:18 -0700 (PDT) From: Emre Cecanpunar To: platform-driver-x86@vger.kernel.org Cc: hansg@kernel.org, ilpo.jarvinen@linux.intel.com, linux-kernel@vger.kernel.org, krishna.chomal108@gmail.com, Emre Cecanpunar Subject: [PATCH v2 5/5] platform/x86: hp-wmi: add locking for concurrent hwmon access Date: Sun, 22 Mar 2026 22:06:24 +0300 Message-ID: <20260322190624.35162-6-emreleno@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260322190624.35162-1-emreleno@gmail.com> References: <20260322190624.35162-1-emreleno@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" hp_wmi_hwmon_priv.mode and .pwm are written by hp_wmi_hwmon_write() in sysfs context and read by hp_wmi_hwmon_keep_alive_handler() running in a workqueue. There is no synchronisation between them, so a concurrent sysfs write and keep-alive expiry can observe an inconsistent combination of mode and pwm (e.g. mode=3DMANUAL with an stale pwm value from the previous mode). Add a mutex to hp_wmi_hwmon_priv that protects mode and pwm. Acquire it in hp_wmi_hwmon_write() for the full write operation (field update plus hp_wmi_apply_fan_settings() call), and in hp_wmi_hwmon_keep_alive_handler() before calling hp_wmi_apply_fan_settings(). In hp_wmi_hwmon_read(), only the pwm_enable attribute reads priv->mode and requires the lock. Use scoped_guard() to hold the mutex only for the mode read, avoiding holding it across unrelated WMI hardware calls. Signed-off-by: Emre Cecanpunar --- drivers/platform/x86/hp/hp-wmi.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-= wmi.c index af57cb0dbf9e..0947aaeabff3 100644 --- a/drivers/platform/x86/hp/hp-wmi.c +++ b/drivers/platform/x86/hp/hp-wmi.c @@ -434,6 +434,7 @@ enum pwm_modes { }; =20 struct hp_wmi_hwmon_priv { + struct mutex lock; /* protects mode, pwm */ u8 min_rpm; u8 max_rpm; int gpu_delta; @@ -2403,6 +2404,7 @@ static int hp_wmi_hwmon_read(struct device *dev, enum= hwmon_sensor_types type, { struct hp_wmi_hwmon_priv *priv; int rpm, ret; + u8 mode; =20 priv =3D dev_get_drvdata(dev); switch (type) { @@ -2426,11 +2428,13 @@ static int hp_wmi_hwmon_read(struct device *dev, en= um hwmon_sensor_types type, *val =3D rpm_to_pwm(rpm / 100, priv); return 0; } - switch (priv->mode) { + scoped_guard(mutex, &priv->lock) + mode =3D priv->mode; + switch (mode) { case PWM_MODE_MAX: case PWM_MODE_MANUAL: case PWM_MODE_AUTO: - *val =3D priv->mode; + *val =3D mode; return 0; default: /* shouldn't happen */ @@ -2448,6 +2452,7 @@ static int hp_wmi_hwmon_write(struct device *dev, enu= m hwmon_sensor_types type, int rpm; =20 priv =3D dev_get_drvdata(dev); + guard(mutex)(&priv->lock); switch (type) { case hwmon_pwm: if (attr =3D=3D hwmon_pwm_input) { @@ -2516,6 +2521,8 @@ static void hp_wmi_hwmon_keep_alive_handler(struct wo= rk_struct *work) =20 dwork =3D to_delayed_work(work); priv =3D container_of(dwork, struct hp_wmi_hwmon_priv, keep_alive_dwork); + + guard(mutex)(&priv->lock); /* * Re-apply the current hwmon context settings. * NOTE: hp_wmi_apply_fan_settings will handle the re-scheduling. @@ -2573,6 +2580,8 @@ static int hp_wmi_hwmon_init(void) if (!priv) return -ENOMEM; =20 + mutex_init(&priv->lock); + ret =3D hp_wmi_setup_fan_settings(priv); if (ret) return ret; --=20 2.53.0