From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796343532; b=CiR+TedafD2kDBpmZCQNF+jkQMfqE5n4RofVqvu9rtwh1BYNhYikQmv+XppkypBq1ErA hwue7ziRzNLPz/0QNrEWu5S08lJKDZiDjSPjS03rLZ4Rxha73FF/SVW1y4bXhK28y2wli bulQreU3ae1CjvSYH1WiIUSjH6a5OjlIJkteAkGojA/zWvI/w5Qye5T+1PXGuFOsy32kQ CXe2d67gjyXel/lZyhnQ2GCTTSuA6O6jg38L9NL/KVXHhkDzyPFMkPw9wGY2C+1UewqCh xfnpP4HqXadnZ+0SHdzJSY2KYKcb2E1Lox9nPPHtWznoycxDI4lXf3DjcDOJBz1LGdw== 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-Forwarded-Encrypted: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=4Vuh/EpUOvXpAVG1r8g4j+yvDiYmJfXN0dhkyMSCxazfdX/rWl0ma+1mYcsMF534+ZBK DxIlRlQ4ensX9PravELJGRpvh9A3j50aDV3oqkZxlZtv1lIrYhVRoxTvnzpYrbTm7bLTG Jf4VtuAetscUDweR1rWw2WHfT6RnS4O1nIjczZEdrRBGluRMBH2Q8S7fX1aQKpGuMXNaT wCMK+LeutyEO28WgFMnv0MqMi7nzK9yMskyQk3o5vzZsjVTV+QjVmYKU6Y178pZWU3dAE 34iiwemPt2iHE2fzdkimp+xKuWoP0oCulIM6oKXSDw2qk9r6i7DFo9QSzL+MTz6ncjw== 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.172 Received: from mail-dy1-f172.google.com (mail-dy1-f172.google.com [74.125.82.172]) (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 1D9C5606A33D for ; Fri, 4 Dec 2026 00:18:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1D9C5606A33D 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-f172.google.com with SMTP id 5a478bee46e88-386ab9ab619so559498eec.1 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=uSnZGml6xzkYa4zm48WAcBQvWXWSwGwpMZlRS1OfkKPSrrvkfD9tuYrOGgapV5mJB6 XLSyksfvivpNj7IzWIUc7+eQ+W2zpXkqk16qCOuStPKvauBIh4BrVpv6aztIdexOjQMw GGsWZ9D7KsLDDvo3V0ShY2CDiQjo2nTXoLh7yLARbeViCVvSLzxS6Oo79lBUSDaMey34 gF0R1Bk+r/EWghc3YHDJhyQ2Pyafmo6TciqmDQKRX1hNcRc9ZtGO+ngJwlqmbH8i8aio lduJZFULygYHIJl6LzKFjjx8cKlP2rvo4a4tbT5Z/IErX+4wQG1/+jt2CO279uEH/MDD eL4g== X-Forwarded-Encrypted: i=1; AL+hErFnXHrTsQrJJNdXisg7pDUacLoKbLYIbTiwGsbFU33OWeIfl0KolCVdfdODdHlQUe8uBz0E4lul7oc=@vger.kernel.org X-Gm-Message-State: APuU4Z89eqb1AsaFCWbQ8EJTHZi421KGUmWD1vv+Mih/GhTaWWG5p5zz br0uMPgbkeo1wYnCwORgIa90stnrbVWuftM73sUxuBGv75p77JW8Q8Fv X-Gm-Gg: AZFdTZddRVM7IXh4UtPSe7Vur2Ii1Gd7sMrdgvpk/vZrJNBx82tWCX2o1avxvK0z0n9 CC2iZI2xKMfnk9K7oaYwfc79T2hGYE13aKrr98lDF1mZVg6XC3Jxpiiil5euIOKKEmw34jSrH1V WxazlPiqHprliw54NLw4zzr9JkZmRM6x3l88WfOpr48ZNb40npP4/WpTnzoGeFyaRasET5HbpgJ efPMwmSb+HLx/paxavbnxYC7x7beZJn2hxfr+RqVo3yQpu3HuUU4/tFp7sr11/wBhA9YVpmDoRf 4p7MM98B4KpE2vnHvu6S7ONWN/Fq3XzMgm6u3A7dV1/I+sCG35g2l2HZK0JzjfQ66QON/FT/ybW aKYZTkBikPswkDw2xGBlaSebShcx+yVEr3vZqn9ZsHJVW89BWDxmYusdDURBK2Tu6HhJHoT8nKY K1Dou7HUgymA9/VyENIsyox7kPWdqgz2r0kFjRIoSA6pIfWb91bd6ZhGvv2LErPv/rfNdKwQEjp pinrjSqJn4txRJMLSmx+0wipihgdVQUccXo3ru0QtVf/sxecKtmIdcb83JxZJ6XWbiuVcukWiNI G33qV0XI9DgbJKdZZvbf0YfnAIxOzGFOddBo1+wWCbm+u6//8WDr+iLIrcVEn2VmGvpgPqyMceA ex4S52KB5GD9VLJ7bR+TvV/GCRuowcw== 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-usb@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