From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796343532; b=HIkIexJD2wp8DDZqUvdc2oXu0UfaRrah8oKB299UqV5kGrh4EBkZYEjBsWSr2v1d4Eqo q0FmaAKKDRB4Z5f4Y18YZ/NuM+Rl9mFglfEEeCInkDGb22rSSmX+aENWOkVEhieKfla6T zkDxpHoGj/PIivue/Z5AlIoH4IAxf1ciXiqGRnjEuX8g/NCqUx5v/sgMrptr2edmXSft9 yv7e9OAH7qynqypycGzpkhfvjH5xldu465wB1KrgamS+YGGmhlX/b12UpEtB2ygilpq4t JoBYxGGx0pZnU/ILZzfUS3TxA6EN+pXcVSPAWKJ2JS5VnQ4NAVwZAlEv0ecnloG0liA== 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=X2BiB1b5F32rpkAFAla47mxZL+5+y45L3bqEdyUonnajHzcmkY3CfTtNC8P64jTRIK+4 n0zc9rk1rYXUImXYjM2PKoK+L1Nuqluvj56CTAoiLUkOevdbpCd4L8ZNXFXBizvBGZyI/ 4UpoU/aClU3C8zvKlkPalexMVrna4M+qRKXxEh/jE31LGb+FFi0QKeQOZjlWfam2Rno8A yRCnxY1KUWuODBOrADoceZ+Ubnd3VGj0lCFIIU1+KrZNCnVlXIOjsvp8vcEi96cf/PsB2 taF+62Sf7lPiZOMSBHkCcx6vWuyC6nLAoiQ/tzhDFuEweESA+zMAM86AtTvXjJ89WsQ== 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.48 Received: from mail-dl1-f48.google.com (mail-dl1-f48.google.com [74.125.82.48]) (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 54E86606A680 for ; Fri, 4 Dec 2026 00:18:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 54E86606A680 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-dl1-f48.google.com with SMTP id a92af1059eb24-1b5d60183f9so442234c88.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=vq2Du015xHgS2Kb21FZpiRh3I1JveoX94pnUBZRlP+P19aShmeyz0aV8MCLaEfN9kF vh4VLUJlT4xU72dRpRYB8a9RTU6c0ov2xsY34XykjGxEWWoiWetCxlG2uTcTOVSQ1M64 udNSbannWjYL4hG7ksBh6DIi08M+z4IyzcaD9EH6jm+b8bARW7QL7lc+7vFixZa3LpPU 3cyIw04bC20DfzwlWgrdCEMeTAdcRmBh4T4nNnorf6GfyHBqAU3T/nG1VfCcht4pcUEu D2WGa35OYpj/hBszcsplWaRxShREat1QNfbkK1P+pOE7IxpGIakOxXLrva2uqcHhBjsb vuBA== X-Forwarded-Encrypted: i=1; AL+hErFkhvKJ+Zu94dhXcqPJXGoztOVC9s7f7VxSSkCdnJGTodMDlsdjhuCZNM3jSyjIh19tIhSHM5Q=@vger.kernel.org X-Gm-Message-State: APuU4Z96UaaBEHGi3edcWB2qfYnBMvmiqwBufMWVfJX5fzu/uJ59vUBT 1yUWa9p4oWi063JaTxvqq9B5JvC27Rz3EZO9yKSuccY6nJxbvhXMPqr4 X-Gm-Gg: AZFdTZdDG2ByPRtiCEe9B0dhG2tOo8deFnnNj6mm4KxyZlSIgW4+q7xTnXXRXU/Qd5u yQ3Rz3g/EfH2eKuYJ8wx0WFzwFI7mwTtjvfvwl+zF9J6sNRlBT5kI+G+sMbz5ofzvrdytSpS0EE y8zzkh+NkfXMIaG7nhjAH+L3bRCnmT1PWyy02KMq1LWTj2zw/6ORnAuUlawXsNaoyGcDz42dLs2 fXF15kcPpokcw8d/xt60/khdt1TaSbnT8Ow2QB5uBmyWry0u201tvBX3L2eUwX7xJIuY8kyVexW mA7ZvpXFyKvPV93v+qjlizpcBtXaXH43BP/5n/WX9drbIy7eDFTzcs3cmQdwHXnLJq75umwSjTv /oOcoALfs+ToTcrnlugMnrdFd3+z0VMAlXCyUE0ynqPoxeBcFRIHE1STQbG80wLFLjjGZh+XeIn QI0lEtv6l5euPa4VKshuALGuLxfeXLqTfnPaJHfS3sNOzQxW78tK3l8/+h9DcXnrgbUhPpRBcIV NYAI+H8w8tUC2coZYPGIVvm9XlGRSpeRbbewKrUrVSD/FLnV70HoVS3xj5IVWBouWd5uUdB7ft6 8eAvGG6v0M/ydDUm3oX7IKHgmHPKGss7KscvgE1MksBXJfgM0p/du3V3KhQPTGqgYvdQYQ+i2Qg 2CWM3He9g7uyDlDSKOAZqaVd7D93gWA== 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: stable@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