From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796499367; b=c+im2umR289c+XhuPOkAhk3Lo2vzQktuguVm3HNnxXI9AS5KbJJuSmWbrYUakJjjWaJ1 uwSi3/pmGgAq1LW2UbMB35XzNR6KGUxRjvkV5Si0zRnKhhvDse1IVkQC2AF+Jar6vKX52 sFijYkpZ64YExKt9WPQnAPN+RELqFk+T9YI9m7nnfBBNIN6RFnZh+QYnFfIR+ir2Xxj9h VwZEgBL046w3md2KlWSGD4hx4OO15I/q+R+q2pCe/LNXR2GCQPcaQfW9d1TvzwbTahDo2 WKi3rIFijOnfWaBUGTjMkLRx3D2H3FNv4SJ0eZ7suAgWJSy1zHGs6+U6xQSeWsUtdwg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796499367; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=bTfMu+DV83l/rttYXobDul+0Sgdsf+BOySr6zBSrLGQ=; b=ZhBtGgY38NPe9KJjLl5DEfsL8fuAo7gjrivv4/7C/Fs92hESFMIFv1OSIXbw+aR5P7ey hdF8U1YUqpla2sP6+ZIBPA1oZIjeU4E5LbDAnUEZ++jILCbiewLGZ9mduXYQjKq5ZMLuP OrikUwrT1iz8d82wxogUiDVCF3IN80SysCWc4Fsa4DVz0UoxcY8FgayaUXpYHj+13p0gT vQJrk1EhYlK2tdDj983JMxe3xN6BWG0L+MzQxaReZClof9bBCT+JxywbAGVmxERBmCQWD xQvF+K2j5sNy8G0enM4pvjn9hH/F5jWs4JJSpuPJG7dRqhM239SJ0esb7bqoPiK2MTg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=XTk9fqn1; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1588606A31F; Sat, 5 Dec 2026 19:36:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=XTk9fqn1 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FEF41F0092B; Sat, 5 Dec 2026 19:36:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796499367; bh=bTfMu+DV83l/rttYXobDul+0Sgdsf+BOySr6zBSrLGQ=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=XTk9fqn1R0831zlKhHd0lAZnyUr5s+lpJI8HLMJ2GRc2gpbUXUst9z8O9GJprP/l5 RMmPBcn7VSlcJ6A6tKLtxRJHpY/Q7qicczBF1w+NmlO6Oi2NoXJHNUB432ddbnBOdx rIADaMznDjRmUI1+Yu9g3R755bNmxQZRd6CuwJf1w+CKolRDKXTXn9OVUvcqqShpa3 zEO7fPUsUOnIzOhrqNPEutuBzcT8nGX9qXfY75Gw+n5NtSIX4YmghoBsVf/IlK8WWt m1cf/B99izSJO8NMj4FX1BEBsXNWVQ/OW7y1ue7BPYe2gZHJR/S4ufx599KsfwjiI+ g7axh0Ur/tvTA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] hwmon: Add Razer PWM PC Fan Controller driver Reply-To: sashiko-reviews@lists.linux.dev To: "Victor Chernyakin" Cc: linux-hwmon@vger.kernel.org, linux-input@vger.kernel.org, dmitry.torokhov@gmail.com In-Reply-To: References: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 19:36:07 +0000 X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 8 potential issues to consider: - [High] HID: unconditional hid_ignore_list entry breaks hidraw for 1532:0F3C - [High] hwmon: missing hwmon_lock() in razer_pwm custom sysfs show callbacks - [Medium] hwmon: razer_pwm_disconnect() allows USB control I/O after returning - [Medium] hwmon: razer_pwm_set_pwm() leaves cached PWM valid after mode error - [Medium] hwmon: missing .reset_resume in razer_pwm_driver drops PWM state on resume - [Medium] hwmon: partial union init in razer_pwm_report leaves tail bytes uninitialized - [Low] hwmon: non-standard firmware_version and serial_number sysfs attributes - [Low] hwmon: off-by-one sequence wrap-around in razer_pwm_send_report() -- commit 34454e665e3840bb53e9795a612560c2739013e6 Author: Victor Chernyakin hwmon: Add Razer PWM PC Fan Controller driver This commit adds a USB hwmon driver for the Razer PWM PC Fan Controller, exposing fan speed readings, PWM duty cycle control, and firmware/serial attributes, and adds the device to the HID ignore list. > diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c > index 793db001a62b7..17813b2557666 100644 > --- a/drivers/hid/hid-quirks.c > +++ b/drivers/hid/hid-quirks.c > @@ -976,6 +976,7 @@ static const struct hid_device_id hid_ignore_list[] = =3D { > { HID_USB_DEVICE(USB_VENDOR_ID_PETZL, USB_DEVICE_ID_PETZL_HEADLAMP) }, > { HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE80215= 4_DONGLE) }, > { HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) }, > + { HID_USB_DEVICE(USB_VENDOR_ID_RAZER, 0x0F3C) }, > { HID_USB_DEVICE(USB_VENDOR_ID_SAI, USB_DEVICE_ID_CYPRESS_HIDCOM) }, > #if IS_ENABLED(CONFIG_MOUSE_SYNAPTICS_USB) > { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_TP) }, [Severity: High] Does adding 0x1532:0x0F3C unconditionally to hid_ignore_list[] break existing userspace hidraw access? When CONFIG_SENSORS_RAZER_PWM_PC_FAN_CONTROLLER is disabled, usbhid still rejects the device because hid_gets_squirk() applies HID_QUIRK_IGNORE to every entry in hid_ignore_list[], leaving userspace tools with no /dev/hidraw* node and no kernel driver bound. In addition, hid_ignore_list[] blocks all HID interfaces on the device even though razer_pwm_table only binds interface 0x00. Since razer_pwm_send_report() only sends standard HID Feature Report requests (HID_REQ_SET_REPORT and HID_REQ_GET_REPORT), could this driver be implemented as a struct hid_driver using hid_hw_raw_request() instead, avoiding hid_ignore_list[] altogether? > diff --git a/drivers/hwmon/razer_pwm_pc_fan_controller.c b/drivers/hwmon/= razer_pwm_pc_fan_controller.c > new file mode 100644 > index 0000000000000..dc6dbe096e11b > --- /dev/null > +++ b/drivers/hwmon/razer_pwm_pc_fan_controller.c [ ... ] > +static int razer_pwm_send_report(struct razer_pwm_dev *d) > +{ > + unsigned long timeout; > + int ret; > + > + ++d->current_sequence_number; > + d->current_sequence_number %=3D 31; /* Synapse also wraps around after = 31. */ > + > + d->report.sequence_number =3D d->current_sequence_number; [Severity: Low] Is there an off-by-one in the sequence number wrap-around? Using %=3D 31 wraps 31 to 0, so sequence number 31 is never emitted and the counter wraps after 30 instead of after 31 as the comment states. When d->current_sequence_number wraps to 0 on every 31st transfer, an all-zero response would also pass both the checksum and sequence_number checks and return -EIO immediately instead of retrying. [ ... ] > +static int razer_pwm_set_pwm(struct razer_pwm_dev *d, u8 channel, u8 val) > +{ > + int ret; > + > + d->report =3D (struct razer_pwm_report) { > + RAZER_PWM_CMD_SET_CHANNEL_MODE, > + .set_channel_mode =3D { > + .always_1 =3D 1, > + .channel_plus_5 =3D channel + 5, > + .mode =3D RAZER_PWM_CHANNEL_MODE_MANUAL, > + }, > + }; [Severity: Medium] Can assigning a compound literal with a smaller union member leave the remaining bytes of d->report uninitialized? On compilers without -fzero-init-padding-bits=3Dall (such as GCC 8.1 through 14), bytes beyond the designated union member are unspecified. For RAZER_PWM_CMD_SET_CHANNEL_MODE, payload_len is 4 while set_channel_mode only defines 3 bytes, so byte 3 of the command payload and the remaining tail bytes in the 80-byte union can contain stale response bytes or uninitialized stack data that get checksummed and sent over USB. The same applies to the .set_duty_cycle and .get_rpm assignments in razer_pwm_set_pwm() and razer_pwm_hwmon_read(). Zeroing d->report with memset() before populating the request fields would avoid this across all supported compilers. > + ret =3D razer_pwm_send_report(d); > + if (ret) > + return ret; > + > + /* > + * The controller's firmware refuses to set any duty cycle lower > + * than 33% (it rounds up any lower values to 33%, expect of course for > + * the value 0, which disables the fan). Reflect that behaviour here. > + */ > + if (val !=3D 0) > + val =3D umax(val, 255 / 3); > + > + d->report =3D (struct razer_pwm_report) { > + RAZER_PWM_CMD_SET_DUTY_CYCLE, > + .set_duty_cycle =3D { > + .always_1 =3D 1, > + .channel_plus_5 =3D channel + 5, > + .percent =3D DIV_ROUND_CLOSEST(val * 100, 255), > + }, > + }; > + ret =3D razer_pwm_send_report(d); > + d->cached_pwm_might_be_stale[channel] =3D !!ret; > + if (ret) > + return ret; [Severity: Medium] If the first razer_pwm_send_report() for RAZER_PWM_CMD_SET_CHANNEL_MODE fails, does this leave d->cached_pwm_might_be_stale[channel] as false? During probe and resume, razer_pwm_resume() ignores errors from razer_pwm_set_pwm(), and d->cached_pwm_might_be_stale[] starts out false with d->cached_pwm[] pre-populated to 127. If SET_CHANNEL_MODE fails, subsequent reads of pwm[1-8] return the unapplied cached value instead of -ENODATA. Setting d->cached_pwm_might_be_stale[channel] =3D true before sending SET_CHANNEL_MODE (or on its error path) would keep the cache state consistent. [ ... ] > +static ssize_t firmware_version_show(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + struct razer_pwm_dev *d =3D dev_get_drvdata(dev); > + int ret; > + > + d->report =3D (struct razer_pwm_report) { > + RAZER_PWM_CMD_GET_FIRMWARE_VERSION, > + }; > + ret =3D razer_pwm_send_report(d); > + if (ret) > + return ret; > + > + return sysfs_emit(buf, "%u.%u.%u.%u\n", > + d->report.firmware_version.major, > + d->report.firmware_version.minor, > + d->report.firmware_version.patch, > + d->report.firmware_version.hotfix); > +} > + > +static ssize_t serial_number_show(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + struct razer_pwm_dev *d =3D dev_get_drvdata(dev); > + int ret; > + > + d->report =3D (struct razer_pwm_report) { > + RAZER_PWM_CMD_GET_SERIAL_NUMBER, > + }; > + ret =3D razer_pwm_send_report(d); [Severity: High] Can firmware_version_show() and serial_number_show() race with hwmon callbacks on the shared d->report buffer and d->current_sequence_number? Standard hwmon_ops callbacks are serialized by hwdev->lock in hwmon_attr_show() and hwmon_attr_store(), but custom attributes passed via extra_groups are invoked through dev_attr_show() without holding it: CPU0 CPU1 hwmon_attr_show() lock(&hwdev->lock) razer_pwm_hwmon_read() d->report =3D GET_RPM razer_pwm_send_report() usb_control_msg(SET) msleep(10) firmware_version_show() d->report =3D GET_FW_VER <-- overwrites razer_pwm_send_report() ++d->current_sequence_number usb_control_msg(SET) <-- DMA race usb_control_msg(GET) <-- corrupted buffer / seq mismatch Because d->report is passed directly to usb_control_msg() for DMA, this also violates DMA buffer ownership while a transfer is in flight and lets any unprivileged reader of these 0444 files corrupt concurrent PWM writes or RPM reads. Acquiring hwmon_lock(dev) (for instance via guard(hwmon_lock)(dev)) in both show callbacks would serialize all access. [ ... ] > +static const DEVICE_ATTR_RO(firmware_version); > +static const DEVICE_ATTR_RO(serial_number); > + > +static const struct attribute *const razer_pwm_attrs[] =3D { > + &dev_attr_firmware_version.attr, > + &dev_attr_serial_number.attr, > + NULL > +}; [Severity: Low] Should firmware_version and serial_number be exposed through debugfs instead of non-standard hwmon sysfs attributes? Documentation/hwmon/submitting-patches.rst discourages non-standard sysfs attributes without prior discussion and ABI documentation, and other USB hwmon drivers (such as aquacomputer_d5next, corsair-cpro, and nzxt-kraken3) read static metadata once at probe time and expose it in debugfs instead of issuing live USB control transfers on every sysfs read. [ ... ] > + hwmon_dev =3D devm_hwmon_device_register_with_info(&intf->dev, > + "razer_pwm_pc_fan_controller", > + d, > + &razer_pwm_chip_info, > + razer_pwm_groups); > + return PTR_ERR_OR_ZERO(hwmon_dev); > +} > + > +static void razer_pwm_disconnect(struct usb_interface *intf) {} [Severity: Medium] Does using devm_hwmon_device_register_with_info() with an empty razer_pwm_disconnect() allow usb_control_msg() calls to run after disconnect() returns? During unbind, __device_release_driver() runs usb_unbind_interface() and driver->disconnect() before device_unbind_cleanup() runs devres cleanup to unregister the hwmon device. Because usb_disable_interface() does not disable ep0, active or newly entered sysfs callbacks can keep issuing usb_control_msg() transfers while usb_unbind_interface() resets interface state and autosuspends the device, violating the usb_control_msg() contract that disconnect() must wait for in-flight calls to complete. Registering with hwmon_device_register_with_info() and calling hwmon_device_unregister() in razer_pwm_disconnect() would ensure sysfs callbacks drain before disconnect() returns. [ ... ] > +static struct usb_driver razer_pwm_driver =3D { > + .name =3D "razer_pwm_pc_fan_controller", > + .id_table =3D razer_pwm_table, > + .probe =3D razer_pwm_probe, > + .disconnect =3D razer_pwm_disconnect, > + .suspend =3D razer_pwm_suspend, > + .resume =3D razer_pwm_resume, > +}; [Severity: Medium] Should razer_pwm_driver also set .reset_resume =3D razer_pwm_resume? When the USB port loses power during suspend or hibernation, usb_resume_interface() skips driver->resume() if driver->reset_resume is NULL and sets intf->needs_binding =3D 1 instead. USB core then unbinds and re-probes the driver, recreating the hwmon device and resetting all 4-wire fans back to 50% (127) instead of restoring d->cached_pwm[]. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/SN1PR12MB25286AB7CB= 896D4B92FD8914A5492@SN1PR12MB2528.namprd12.prod.outlook.com?part=3D1