* [PATCH 0/2] Input: drive the HP ZBook 17 G3 touchpad LED through RMI4 @ 2026-12-03 12:50 ahmad baghereslami 2026-12-03 12:50 ` [PATCH 1/2] Input: synaptics-rmi4 - support the LEDs of function $30 ahmad baghereslami 2026-12-03 12:50 ` [PATCH 2/2] Input: synaptics - enable SMBus for HP ZBook 17 G3 ahmad baghereslami 0 siblings, 2 replies; 4+ messages in thread From: ahmad baghereslami @ 2026-12-03 12:50 UTC (permalink / raw) To: dmitry.torokhov; +Cc: linux-input, linux-kernel, ahmad baghereslami Dmitry suggested [1] moving the HP ZBook 17 G3 touchpad to SMBus and driving its LED from rmi_f30 instead of the RMI register backdoor over PS/2 in "Input: synaptics - support the touchpad LED on RMI function $30" (v3 [2]). This series does that and replaces that patch. Patch 1 adds LED class support to rmi_f30: an LED device for each pin that control 0 selects as an LED, using the on bits in control 4 and the brightness bytes in control 6. It works for any RMI4 transport. Patch 2 adds SYN3040 to smbus_pnp_ids. As discussed, over SMBus touching the touchpad no longer wakes the keyboard backlight, which the EC did on PS/2 input; that belongs in hp-wmi and is not part of this series. rmi_f30 uses IS_REACHABLE(CONFIG_LEDS_CLASS) so that F30 keeps working when RMI4_CORE is built in and LEDS_CLASS is a module; I can turn that into a Kconfig dependency instead if you prefer. [1] https://lore.kernel.org/all/84b917b9feb4a934e67d0e8f25707cc1@gmail.com/ [2] https://lore.kernel.org/all/20261114090808.2572722-1-ahmad.b1995@gmail.com/ ahmad baghereslami (2): Input: synaptics-rmi4 - support the LEDs of function $30 Input: synaptics - enable SMBus for HP ZBook 17 G3 drivers/input/mouse/synaptics.c | 1 + drivers/input/rmi4/rmi_f30.c | 113 +++++++++++++++++++++++++++++++- 2 files changed, 111 insertions(+), 3 deletions(-) -- 2.53.0 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] Input: synaptics-rmi4 - support the LEDs of function $30 2026-12-03 12:50 [PATCH 0/2] Input: drive the HP ZBook 17 G3 touchpad LED through RMI4 ahmad baghereslami @ 2026-12-03 12:50 ` ahmad baghereslami 2026-12-03 13:06 ` sashiko-bot 2026-12-03 12:50 ` [PATCH 2/2] Input: synaptics - enable SMBus for HP ZBook 17 G3 ahmad baghereslami 1 sibling, 1 reply; 4+ messages in thread From: ahmad baghereslami @ 2026-12-03 12:50 UTC (permalink / raw) To: dmitry.torokhov; +Cc: linux-input, linux-kernel, ahmad baghereslami Function $30 can drive LEDs: query 0 says whether it has any, control 0 selects which of its GPIO/LED pins are LEDs (all of them when the function has no GPIOs), a bit per pin in control 4 turns the LED on that pin on, and control 6 holds a brightness byte per pin. rmi_f30 already works out where these registers are, but does nothing with the LEDs. Register an LED class device for each LED pin, named "rmi4-XX.fn30::ledN" after the pin. Setting the brightness writes it to control 6 and sets the pin's bit in control 4, and brightness 0 clears that bit. The values are kept in ctrl_regs, so rmi_f30_config() puts them back after a reset; a mutex keeps the two from interleaving. A pin's LED starts with the brightness in control 6 if its bit in control 4 is already set. The Synaptics TM2706-002 touchpad of the HP ZBook 17 G3 has an LED in its top left corner that HP's Windows driver lights while the touchpad is disabled. It is pin 3 of four, with the control registers at 0x55 on page 1, and HP's driver uses brightness 0x0b. Tested on an HP ZBook 17 G3 over SMBus with Ubuntu's 7.0.0 kernel: the firmware leaves the LED off with brightness 0x05; brightness 1 lights it dimly and 11, 40 and 255 brightly, 0 turns it off; the LED goes off when the driver unbinds, and comes back after reloading the driver and after suspend and resume. The touchpad and the pointing stick keep working. Assisted-by: LLM Signed-off-by: ahmad baghereslami <ahmad.b1995@gmail.com> --- drivers/input/rmi4/rmi_f30.c | 113 ++++++++++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 3 deletions(-) diff --git a/drivers/input/rmi4/rmi_f30.c b/drivers/input/rmi4/rmi_f30.c index b2155c8e2..55428e9a9 100644 --- a/drivers/input/rmi4/rmi_f30.c +++ b/drivers/input/rmi4/rmi_f30.c @@ -6,6 +6,8 @@ #include <linux/kernel.h> #include <linux/rmi.h> #include <linux/input.h> +#include <linux/leds.h> +#include <linux/mutex.h> #include <linux/slab.h> #include "rmi_driver.h" @@ -54,6 +56,15 @@ struct rmi_f30_ctrl_data { u8 *regs; }; +struct f30_data; + +struct rmi_f30_led { + struct led_classdev cdev; + struct rmi_function *fn; + struct f30_data *f30; + unsigned int pin; +}; + struct f30_data { /* Query Data */ bool has_extended_pattern; @@ -71,6 +82,8 @@ struct f30_data { struct rmi_f30_ctrl_data ctrl[RMI_F30_CTRL_MAX_REG_BLOCKS]; u8 ctrl_regs[RMI_F30_CTRL_REGS_MAX_SIZE]; u32 ctrl_regs_size; + /* Serializes LED updates of ctrl_regs with writing them back. */ + struct mutex ctrl_mutex; u8 data_regs[RMI_F30_CTRL_MAX_BYTES]; u16 *gpioled_key_map; @@ -182,8 +195,11 @@ static int rmi_f30_config(struct rmi_function *fn) drv->clear_irq_bits(fn->rmi_dev, fn->irq_mask); } else { /* Write Control Register values back to device */ - error = rmi_write_block(fn->rmi_dev, fn->fd.control_base_addr, - f30->ctrl_regs, f30->ctrl_regs_size); + scoped_guard(mutex, &f30->ctrl_mutex) + error = rmi_write_block(fn->rmi_dev, + fn->fd.control_base_addr, + f30->ctrl_regs, + f30->ctrl_regs_size); if (error) { dev_err(&fn->dev, "%s: Could not write control registers at 0x%x: %d\n", @@ -363,6 +379,92 @@ static int rmi_f30_initialize(struct rmi_function *fn, struct f30_data *f30) return 0; } +/* + * Control 4 has a bit per pin that turns the LED on that pin on, and + * control 6 a byte per pin with the brightness of its LED. The values are + * kept in ctrl_regs, which rmi_f30_config() writes back after a reset. + */ +static int rmi_f30_led_set(struct led_classdev *cdev, + enum led_brightness value) +{ + struct rmi_f30_led *led = container_of(cdev, struct rmi_f30_led, cdev); + struct rmi_device *rmi_dev = led->fn->rmi_dev; + struct rmi_f30_ctrl_data *on = &led->f30->ctrl[4]; + struct rmi_f30_ctrl_data *level = &led->f30->ctrl[6]; + unsigned int reg = led->pin >> 3; + u8 mask = BIT(led->pin & 0x07); + int error; + + guard(mutex)(&led->f30->ctrl_mutex); + + if (value) { + error = rmi_write(rmi_dev, level->address + led->pin, value); + if (error) + return error; + + level->regs[led->pin] = value; + on->regs[reg] |= mask; + } else { + on->regs[reg] &= ~mask; + } + + return rmi_write(rmi_dev, on->address + reg, on->regs[reg]); +} + +static bool rmi_f30_is_led(struct f30_data *f30, unsigned int pin) +{ + /* Without GPIOs there is no LED select register: all pins are LEDs. */ + if (!f30->has_gpio) + return true; + + return f30->ctrl[0].regs[pin >> 3] & BIT(pin & 0x07); +} + +static int rmi_f30_register_leds(struct rmi_function *fn, struct f30_data *f30) +{ + struct rmi_f30_led *led; + unsigned int pin; + int error; + + if (!IS_REACHABLE(CONFIG_LEDS_CLASS) || !f30->has_led) + return 0; + + for (pin = 0; pin < f30->gpioled_count; pin++) { + if (!rmi_f30_is_led(f30, pin)) + continue; + + led = devm_kzalloc(&fn->dev, sizeof(*led), GFP_KERNEL); + if (!led) + return -ENOMEM; + + led->fn = fn; + led->f30 = f30; + led->pin = pin; + led->cdev.name = devm_kasprintf(&fn->dev, GFP_KERNEL, "%s::led%u", + dev_name(&fn->dev), pin); + if (!led->cdev.name) + return -ENOMEM; + + led->cdev.max_brightness = U8_MAX; + led->cdev.brightness_set_blocking = rmi_f30_led_set; + if (f30->ctrl[4].regs[pin >> 3] & BIT(pin & 0x07)) + led->cdev.brightness = f30->ctrl[6].regs[pin]; + + rmi_dbg(RMI_DEBUG_FN, &fn->dev, + "%s: LED on pin %u, on %#x, brightness %#x\n", __func__, + pin, f30->ctrl[4].regs[pin >> 3], f30->ctrl[6].regs[pin]); + + error = devm_led_classdev_register(&fn->dev, &led->cdev); + if (error) { + dev_err(&fn->dev, "Failed to register LED %u: %d\n", + pin, error); + return error; + } + } + + return 0; +} + static int rmi_f30_probe(struct rmi_function *fn) { struct rmi_device *rmi_dev = fn->rmi_dev; @@ -386,12 +488,17 @@ static int rmi_f30_probe(struct rmi_function *fn) f30->input = drv_data->input; + error = devm_mutex_init(&fn->dev, &f30->ctrl_mutex); + if (error) + return error; + error = rmi_f30_initialize(fn, f30); if (error) return error; dev_set_drvdata(&fn->dev, f30); - return 0; + + return rmi_f30_register_leds(fn, f30); } struct rmi_function_handler rmi_f30_handler = { -- 2.53.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] Input: synaptics-rmi4 - support the LEDs of function $30 2026-12-03 12:50 ` [PATCH 1/2] Input: synaptics-rmi4 - support the LEDs of function $30 ahmad baghereslami @ 2026-12-03 13:06 ` sashiko-bot 0 siblings, 0 replies; 4+ messages in thread From: sashiko-bot @ 2026-12-03 13:06 UTC (permalink / raw) To: ahmad baghereslami; +Cc: linux-input, dmitry.torokhov Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [High] input: rmi4: dangling input->keycode UAF when rmi_f30_register_leds() fails - [Medium] input: rmi4: missing LED_CORE_SUSPENDRESUME allows LED writes while suspended - [Medium] input: rmi4: rmi_f30_led_set() mutates ctrl[4] cache before rmi_write() - [Low] input: rmi4: unlocked read of ctrl[4] byte in rmi_f30_register_leds() - [Low] input: rmi4: non-standard sysfs LED naming format in rmi_f30_register_leds() -- commit f9ec26fc6f5ccca7c6290c03ae86094eeccdb79b Author: ahmad baghereslami <ahmad.b1995@gmail.com> Input: synaptics-rmi4 - support the LEDs of function $30 This patch registers an LED class device for each LED pin of Synaptics RMI4 function $30 and serializes LED control register updates with rmi_f30_config() using a mutex. > diff --git a/drivers/input/rmi4/rmi_f30.c b/drivers/input/rmi4/rmi_f30.c > index 2fd009be774c7..724c820f7dbe9 100644 > --- a/drivers/input/rmi4/rmi_f30.c > +++ b/drivers/input/rmi4/rmi_f30.c [ ... ] > @@ -362,6 +378,92 @@ static int rmi_f30_initialize(struct rmi_function *fn, struct f30_data *f30) > return 0; > } > > +/* > + * Control 4 has a bit per pin that turns the LED on that pin on, and > + * control 6 a byte per pin with the brightness of its LED. The values are > + * kept in ctrl_regs, which rmi_f30_config() writes back after a reset. > + */ > +static int rmi_f30_led_set(struct led_classdev *cdev, > + enum led_brightness value) > +{ > + struct rmi_f30_led *led = container_of(cdev, struct rmi_f30_led, cdev); > + struct rmi_device *rmi_dev = led->fn->rmi_dev; > + struct rmi_f30_ctrl_data *on = &led->f30->ctrl[4]; > + struct rmi_f30_ctrl_data *level = &led->f30->ctrl[6]; > + unsigned int reg = led->pin >> 3; > + u8 mask = BIT(led->pin & 0x07); > + int error; > + > + guard(mutex)(&led->f30->ctrl_mutex); > + > + if (value) { > + error = rmi_write(rmi_dev, level->address + led->pin, value); > + if (error) > + return error; > + > + level->regs[led->pin] = value; > + on->regs[reg] |= mask; > + } else { > + on->regs[reg] &= ~mask; > + } > + > + return rmi_write(rmi_dev, on->address + reg, on->regs[reg]); > +} [Severity: Medium] Should on->regs[reg] only be updated after rmi_write() succeeds, as is done for level->regs[led->pin]? If the control 4 write fails, on->regs[reg] is left modified in f30->ctrl_regs, so a later rmi_f30_config() or an update to another LED in the same 8-pin bank will silently push the failed pin's uncommitted state to hardware. Computing the new byte in a local variable and storing it into on->regs[reg] only after rmi_write() returns 0 keeps the cache consistent. [ ... ] > +static int rmi_f30_register_leds(struct rmi_function *fn, struct f30_data *f30) > +{ > + struct rmi_f30_led *led; > + unsigned int pin; > + int error; > + > + if (!IS_REACHABLE(CONFIG_LEDS_CLASS) || !f30->has_led) > + return 0; > + > + for (pin = 0; pin < f30->gpioled_count; pin++) { > + if (!rmi_f30_is_led(f30, pin)) > + continue; > + > + led = devm_kzalloc(&fn->dev, sizeof(*led), GFP_KERNEL); > + if (!led) > + return -ENOMEM; > + > + led->fn = fn; > + led->f30 = f30; > + led->pin = pin; > + led->cdev.name = devm_kasprintf(&fn->dev, GFP_KERNEL, "%s::led%u", > + dev_name(&fn->dev), pin); [Severity: Low] Should the LED name use a standard LED_FUNCTION_* constant with a "-%u" suffix instead of "led%u"? Documentation/leds/leds-class.rst specifies the devicename:color:function format using LED_FUNCTION_* definitions from include/dt-bindings/leds/common.h (such as LED_FUNCTION_INDICATOR with "-%u" for multiple LEDs). Since sysfs LED names become userspace ABI, aligning the name before merge avoids exposing a non-standard "::ledN" interface. > + if (!led->cdev.name) > + return -ENOMEM; > + > + led->cdev.max_brightness = U8_MAX; > + led->cdev.brightness_set_blocking = rmi_f30_led_set; [Severity: Medium] Should led->cdev.flags set LED_CORE_SUSPENDRESUME? Without LED_CORE_SUSPENDRESUME, led_suspend() neither sets LED_SUSPENDED nor flushes set_brightness_work before the parent RMI4 transport suspends. Because brightness_set_blocking queues work on the non-freezable leds_wq, an active trigger or software blink can still run rmi_f30_led_set() -> rmi_write() after rmi_i2c_suspend() disables sensor regulators or after the I2C/SMBus adapter suspends (triggering "Transfer while suspended" warnings and -ESHUTDOWN), or race with rmi_smb_reset() during resume. > + if (f30->ctrl[4].regs[pin >> 3] & BIT(pin & 0x07)) > + led->cdev.brightness = f30->ctrl[6].regs[pin]; > + > + rmi_dbg(RMI_DEBUG_FN, &fn->dev, > + "%s: LED on pin %u, on %#x, brightness %#x\n", __func__, > + pin, f30->ctrl[4].regs[pin >> 3], f30->ctrl[6].regs[pin]); > + > + error = devm_led_classdev_register(&fn->dev, &led->cdev); [Severity: Low] Can reading f30->ctrl[4].regs[pin >> 3] here race with rmi_f30_led_set() on multi-LED devices? Once an earlier loop iteration registers a pin via devm_led_classdev_register(), a sysfs write or trigger can run rmi_f30_led_set() under f30->ctrl_mutex and modify that same control 4 byte while a later iteration reads it unlocked. Reading the initial control 4 and control 6 values under f30->ctrl_mutex avoids the data race. [ ... ] > @@ -385,12 +487,17 @@ static int rmi_f30_probe(struct rmi_function *fn) > > f30->input = drv_data->input; > > + error = devm_mutex_init(&fn->dev, &f30->ctrl_mutex); > + if (error) > + return error; > + > error = rmi_f30_initialize(fn, f30); > if (error) > return error; > > dev_set_drvdata(&fn->dev, f30); > - return 0; > + > + return rmi_f30_register_leds(fn, f30); > } [Severity: High] Does returning an error from rmi_f30_register_leds() leave a dangling input->keycode pointer and cause a use-after-free? rmi_f30_initialize() -> rmi_f30_map_gpios() allocates f30->gpioled_key_map with devm on &fn->dev and installs it into the longer-lived parent input device: drivers/input/rmi4/rmi_f30.c:rmi_f30_map_gpios() { ... input->keycode = f30->gpioled_key_map; input->keycodesize = sizeof(f30->gpioled_key_map[0]); input->keycodemax = f30->gpioled_count; ... } If rmi_f30_register_leds() fails, driver core unwinds &fn->dev devres and frees f30->gpioled_key_map, but device_add(&fn->dev) still returns 0 so rmi_driver_probe() registers data->input with the freed keycode pointer. Any local user able to open the evdev device can then trigger a heap use-after-free read or 16-bit write via EVIOCGKEYCODE / EVIOCSKEYCODE (input_default_setkeycode()), and aborting probe also loses all F30 touchpad and trackstick buttons when optional LED registration fails. Clearing input->keycode, input->keycodesize, and input->keycodemax on error (or treating LED registration failure as non-fatal with a warning) would avoid both. -- Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796302238.git.ahmad.b1995@gmail.com?part=1 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] Input: synaptics - enable SMBus for HP ZBook 17 G3 2026-12-03 12:50 [PATCH 0/2] Input: drive the HP ZBook 17 G3 touchpad LED through RMI4 ahmad baghereslami 2026-12-03 12:50 ` [PATCH 1/2] Input: synaptics-rmi4 - support the LEDs of function $30 ahmad baghereslami @ 2026-12-03 12:50 ` ahmad baghereslami 1 sibling, 0 replies; 4+ messages in thread From: ahmad baghereslami @ 2026-12-03 12:50 UTC (permalink / raw) To: dmitry.torokhov; +Cc: linux-input, linux-kernel, ahmad baghereslami The touchpad on the HP ZBook 17 G3 (PNP: SYN3040 SYN0100 SYN0002 PNP0f13, board id 2706, fw id 2017334) reports that it supports InterTouch, and the kernel suggests reporting it: psmouse serio3: synaptics: Your touchpad (PNP: SYN3040 SYN0100 SYN0002 PNP0f13) says it can support a different bus. If i2c-hid and hid-rmi are not used, you might want to try setting psmouse.synaptics_intertouch to 1 and report this to linux-input@vger.kernel.org. With psmouse.synaptics_intertouch=1 it binds over SMBus as "Synaptics TM2706-002" through rmi4_smbus (i2c-i801). Pointer motion, tapping, the physical buttons, two-finger scrolling and the pointing stick with its three buttons all work, as they do over PS/2, and the LED in the top left corner of the touchpad is available through rmi_f30. Over SMBus the touchpad's reports no longer pass through the embedded controller, which turns the keyboard backlight back on when it sees PS/2 input after the backlight timed out; touching the touchpad no longer does that, typing still does. Add its PNP ID to smbus_pnp_ids so it uses SMBus by default. Tested on an HP ZBook 17 G3 (BIOS N81 01.62) with Ubuntu's 7.0.0 kernel and psmouse.synaptics_intertouch=1. Assisted-by: LLM Signed-off-by: ahmad baghereslami <ahmad.b1995@gmail.com> --- drivers/input/mouse/synaptics.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c index b007e642e..62765222a 100644 --- a/drivers/input/mouse/synaptics.c +++ b/drivers/input/mouse/synaptics.c @@ -198,6 +198,7 @@ static const char * const smbus_pnp_ids[] = { "SYN1221", /* TUXEDO InfinityBook Pro 14 v5 */ "SYN3003", /* HP EliteBook 850 G1 */ "SYN3015", /* HP EliteBook 840 G2 */ + "SYN3040", /* HP ZBook 17 G3 */ "SYN3052", /* HP EliteBook 840 G4 */ "SYN3221", /* HP 15-ay000 */ "SYN323d", /* HP Spectre X360 13-w013dx */ -- 2.53.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-03 13:06 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-12-03 12:50 [PATCH 0/2] Input: drive the HP ZBook 17 G3 touchpad LED through RMI4 ahmad baghereslami 2026-12-03 12:50 ` [PATCH 1/2] Input: synaptics-rmi4 - support the LEDs of function $30 ahmad baghereslami 2026-12-03 13:06 ` sashiko-bot 2026-12-03 12:50 ` [PATCH 2/2] Input: synaptics - enable SMBus for HP ZBook 17 G3 ahmad baghereslami
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox