From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.179 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796343532; b=4IdYrjVL13wQm7+Tb/C8FcwBKnyzMEuUw37rdAne0QofwV2Fr7VmU0AzFjYSkGqbYxHX dJ3LI0EbIkwcY+9OSaBSJXsjGkBY5BwOHyFAyfW0DtlmrXCkHkVWutDQEKoBSwR9Aak3f qTuK59+vZ4jaXFY/EEFVy15fEKiQfTJoVdSELtLHnKXTb0roEXmkCwBHHmtB99YxZ3FPl FVofv6Q/DUSUwjLvIQLop/34tZA1yXg4gBh0ECXntGJr9yyXLMBsujIcaMDeKBsAlobYW wNzV5+98Px9LF7WG91jkPxK0eNxe6/pgOAw7k6sB0BKbbXGWZogxXVHscgDZq0YM4BA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796343532; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=0XzMe0UdOP60nNziUF3lncUC5iHy5O0gydFgyd8WRJI=; b=1F7V4KRCN6Ia1FyMslI0BRfgm6Ah7HT3ze7mf3uFb9h1pVPVAzWrlk0SCcaP5d6Mkjot p4ZGwJHfebDnyso2SzAJQZmkK/1rJ7HZijJprcU57jea8yYOnHUejDew5ugZjBKSX9H2J rRzJnLUBLFmzRn69k22IA+xLpmtII6Rg47CG36Ltnz3+To5dLoFn5sHQl1PKg61gI1f12 PuUZfgTlK2q47Mtpb4EnfQxi2hEs+OqTby/WT0ZCdBK6Ljq6i+x2Fc6te/mQHW3yLF//8 2379vQAtB8TIGW5h6d5+V7W2B2HhSK6cUDOgYnlh1calzTBnIGbJ3oYRwwKi4S4blag== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=mOBaxEwM; arc=none smtp.remote-ip=74.125.82.179 Received: from mail-dy1-f179.google.com (mail-dy1-f179.google.com [74.125.82.179]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 48484606A33F for ; Fri, 4 Dec 2026 00:18:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 48484606A33F 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.a=rsa-sha256 header.s=20260707 header.b=mOBaxEwM Received: by mail-dy1-f179.google.com with SMTP id 5a478bee46e88-3866a784546so484457eec.0 for ; Thu, 03 Dec 2026 16:18:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796343531; x=1796948331; 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:content-type; bh=0XzMe0UdOP60nNziUF3lncUC5iHy5O0gydFgyd8WRJI=; b=mOBaxEwMjK7G0Wh9WglqfIo/7BM1hf+3Tx06v8rV5AIHHXsUWeHuu+W7zVeUze4xy/ l7sWvsH6J8Ej+30Ebsyu+lK2Cze8I8gfc+fRn+LKOQYxJe/a7dS0rQFW3eOUeOUSTsvh 9RFajpDqXT+AxSexRbPbbIvg1Y6nzISnKYEz446ls2b0nk+0PAgGWAmfH3AHnUd7p9cK ed4RB1zgOHlaWwYfWux2Xupxpt3xQVHE1k+BW8XSL4/kEng0vjM8u01vwXAcA6W641i/ qx1acQRe0GkguNYraLZ7THasIIOo5BiCmS3fIU3NvOWvocbiFsh4ZiWAoIx7a5WjyEoG H57A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796343531; x=1796948331; 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:content-type; bh=0XzMe0UdOP60nNziUF3lncUC5iHy5O0gydFgyd8WRJI=; b=Q5ahMZ1EBDCPJhnRZB76KwgcoK5D57znEyc5XhJvYjw2jTyVsj5CBb3s2iAkv9L/Kz mXtZbr86Ah7pSIBkHnZGt7m6TmjT9yEvBVW2iZVZgJhrlg3aIsHwaLCH4BLu4lMeZ55f Evk1afvP67jrRUyYmW43R6BI31gW0vadilqMEnBhOEHZecHdsCCXPJtR1uU87JJ1NzXS LRr/oOmjz+uDivGmoGM9UwI5WfFmhpof13TGZ/B2QouqIjSLcqVHo7MP8TuRMMwoMfVy seY8Gocm2PSTWI5O01t0LD5KWS9amoQObs26bE5sTkIcRdZD95kYG9CzEZOfjEp3/qp2 x+Rg== X-Gm-Message-State: APuU4Z/KppfftLukADxRYW2mQEIiQuJk5BUYPJyMYL43ecrlo8VYEHqE QRF4lhjrqqUsNDpas3J5J4yxOJqirUmXkIwf2LZW0ZZ9OGl5gfMnRwqO X-Gm-Gg: AZFdTZfgQ87/DW5r94qzWNUMYEMD2RkqzMdNEOEfAYgVjPRc7C7UfV1zL22GhOxjdMH nQj0rEz4kzQR4Br0fhyEL7VUBIfQX51XuayvGReRumN2O7kelEAyV98tDxYJ7ipU8s1r1hvb28d TH9EGQ2FpxWrvPYgQDcZM9CWfg1KElpThx5gNs246Ijxv6N3ckfQppsLIW1VbHiKw5b0Zmc3D8m 7hw2iitYmKiWQff65ol5lAyTpGvL7PXi45YD8wSR/IR8GBi+0zK3HADFZwx9j6GyZaAtQJp05yd 8CfhZVKt/4M7YsCvFCP8WvJG77lnxJnUME284v7ZG7Kw7EyXb7nc9CI1cZqgIIJYldm4+gZt7x6 hCyGo0g0uvoHAmDJfyrcUR5VsoUWL6oo3gN2udc+JRuvaxAyqK1qHYfsfDZeC/yup+ytoooFxJT NviPnfN2yORh5t6nztAGo345H3D4IzDaLrZ62uD+Om7YEJLiTaQ4OEok0QXrf25RP5PuDxD4jY8 +w82zC4oZvGMCsqPigQJsyfnpiKDopyE8T0Ud8skm9YiAPSTXToDTBDqzdyaHMdTzA+aG9EpyS8 in8bNPJKJB7wRF9/1LrLES3Mxxkz+LQO4kNrMSananqe2BvxHU/h/ktpPoqTueDQM7QUmhJCdo0 uZxlT2cwVgVC2NoRKLJY39yhkpc7ylA== X-Received: by 2002:a05:7300:4f24:b0:386:240c:19dd with SMTP id 5a478bee46e88-387520b0356mr396256eec.9.1796343531243; Thu, 03 Dec 2026 16:18:51 -0800 (PST) Received: from lappy.taila8a9bd.ts.net (108-228-232-20.lightspeed.sndgca.sbcglobal.net. [108.228.232.20]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521bdedbsm1130836eec.12.2026.12.03.16.18.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 16:18:50 -0800 (PST) From: "Derek J. Clark" To: jikos@kernel.org, bentiss@kernel.org Cc: linux-input@vger.kernel.org, kernel@lists.opengamingcollective.org, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, pgriffais@valvesoftware.com, derekjohn.clark@gmail.com, stable@vger.kernel.org Subject: [PATCH 2/8] HID: hid-msi: Move the ROM commit to an explicit apply attribute Date: Thu, 3 Dec 2026 16:18:40 -0800 Message-ID: <20261204001846.3801336-3-derekjohn.clark@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261204001846.3801336-1-derekjohn.clark@gmail.com> References: <20261204001846.3801336-1-derekjohn.clark@gmail.com> X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Four write paths end with SYNC_TO_ROM, the command that copies the MCU working copy to its internal flash. They are the M-key store behind button_m1 and button_m2, rumble_intensity_left/right and the RGB state write behind effect, speed and enabled. Changes to settings without SYNC_TO_ROM survive until the MCU is power cycled, so a write on every change adds unnecessary wear on the internal flash. Add a write-only attribute, apply, that issues SYNC_TO_ROM on demand and drop it from those four paths. This changes how userspace interacts, though it isn't a critical difference. Users who want the changes to persist will need to do an additional step, but most users are using userspace tools that set the last configured state on startup already. Every store currently reaches the flash, causing excess wear, and the life of the chip outweighs userspace ABI stability in this case. Fixes: 93ff13ed1c4b ("HID: hid-msi: Add M-key mapping attributes") Fixes: 95547c53f1c6 ("HID: hid-msi: Add Rumble Intensity Attributes") Fixes: f27e2e3c80ed ("HID: hid-msi: Add RGB control interface") Cc: stable@vger.kernel.org Signed-off-by: Derek J. Clark --- drivers/hid/hid-msi.c | 72 +++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/drivers/hid/hid-msi.c b/drivers/hid/hid-msi.c index d4128955e463..0e1e5e6f664d 100644 --- a/drivers/hid/hid-msi.c +++ b/drivers/hid/hid-msi.c @@ -340,7 +340,7 @@ struct claw_drvdata { struct hid_device *hdev; bool orphan_ack_pending; struct mutex cfg_mutex; /* mutex for synchronous data */ - struct mutex rom_mutex; /* mutex for SYNC_TO_ROM calls */ + struct mutex rom_mutex; /* Serialises profile writes and the ROM commit */ spinlock_t cmd_lock; /* Lock for cmd data read/write */ u8 waiting_cmd; int cmd_status; @@ -852,6 +852,39 @@ static ssize_t reset_store(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_WO(reset); +static ssize_t apply_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct hid_device *hdev = to_hid_device(dev); + struct claw_drvdata *drvdata = hid_get_drvdata(hdev); + bool val; + int ret; + + scoped_guard(spinlock_irqsave, &drvdata->registration_lock) { + /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */ + if (!smp_load_acquire(&drvdata->gp_registered)) + return -ENODEV; + } + + ret = kstrtobool(buf, &val); + if (ret) + return ret; + + if (!val) + return -EINVAL; + + flush_delayed_work(&drvdata->rgb_queue); + + guard(mutex)(&drvdata->rom_mutex); + + ret = claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_SYNC_TO_ROM, NULL, 0, 0); + if (ret) + return ret; + + return count; +} +static DEVICE_ATTR_WO(apply); + static int mkey_mapping_name_to_code(const char *name) { int i; @@ -918,12 +951,6 @@ static int claw_mkey_store(struct device *dev, const char *buf, u8 mkey) (u8 *)&report, sizeof(report), 25); if (ret) return ret; - /* MCU will not send ACK until the USB transaction completes. ACK is sent - * immediately after and will hit the stale state machine, before the next - * command re-arms the state machine. Timeout 0 ensures no deadlock waiting - * for ACK that ill never come. - */ - ret = claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_SYNC_TO_ROM, NULL, 0, 0); } return ret; @@ -1054,15 +1081,6 @@ static ssize_t rumble_intensity_left_store(struct device *dev, if (ret) return ret; - /* MCU will not send ACK until the USB transaction completes. ACK is sent - * immediately after and will hit the stale state machine, before the next - * command re-arms the state machine. Timeout 0 ensures no deadlock waiting - * for ACK that ill never come. - */ - ret = claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_SYNC_TO_ROM, NULL, 0, 0); - if (ret) - return ret; - return count; } @@ -1128,15 +1146,6 @@ static ssize_t rumble_intensity_right_store(struct device *dev, if (ret) return ret; - /* MCU will not send ACK until the USB transaction completes. ACK is sent - * immediately after and will hit the stale state machine, before the next - * command re-arms the state machine. Timeout 0 ensures no deadlock waiting - * for ACK that ill never come. - */ - ret = claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_SYNC_TO_ROM, NULL, 0, 0); - if (ret) - return ret; - return count; } @@ -1196,7 +1205,8 @@ static umode_t claw_gamepad_attr_is_visible(struct kobject *kobj, struct attribu attr == &dev_attr_gamepad_mode_index.attr || attr == &dev_attr_mkeys_function.attr || attr == &dev_attr_mkeys_function_index.attr || - attr == &dev_attr_reset.attr) + attr == &dev_attr_reset.attr || + attr == &dev_attr_apply.attr) return attr->mode; /* Hide rumble attrs if not supported */ @@ -1218,6 +1228,7 @@ static struct attribute *claw_gamepad_attrs[] = { &dev_attr_mkeys_function.attr, &dev_attr_mkeys_function_index.attr, &dev_attr_reset.attr, + &dev_attr_apply.attr, &dev_attr_rumble_intensity_left.attr, &dev_attr_rumble_intensity_right.attr, &dev_attr_rumble_intensity_range.attr, @@ -1292,14 +1303,7 @@ static int claw_write_rgb_state(struct claw_drvdata *drvdata) write_addr += CLAW_RGB_FRAME_OFFSET; } - /* MCU will not send ACK until the USB transaction completes. ACK is sent - * immediately after and will hit the stale state machine, before the next - * command re-arms the state machine. Timeout 0 ensures no deadlock waiting - * for ACK that ill never come. - */ - ret = claw_hw_output_report(drvdata->hdev, CLAW_COMMAND_TYPE_SYNC_TO_ROM, NULL, 0, 0); - - return ret; + return 0; } /* Fill all zones with the same color */ -- 2.56.0