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=1796231067; b=U5sun7TCiWyE8KdELWPM5pr+fr2X6+3xpi5eIbxUxqVYgZCzt8/Um6z+4ID6q9cEpvGh CeRwXriMPnV6pOkeQRexlZmtxWKzpo8oQq887r1ECeECA9C+d92kElK5MTc/Ibv1ZaUz1 InlY+zgNUTktMHfWbzME+P2zMnEnO4bttfFu3wRlA1vIiwjHw7kXxVk0DdHSzvp6DopVD ueUXoi+AACS1GEdILoS8n5fucj0LBHgjIiV6G7jp410OCC69bxN9g7C5PhBkRds3r2N9X P/ca3PhNZTMfVJEe113wu33S8lIWTNUe4JNz+MX+K530yV5PTJR+YYTsuY3+1BYwNdg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796231067; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=/Yk3W0nIlwzMoD1kx+82gd65aWS5AksaqyIPDzCEpIo=; b=a4K/XH4uoqbf02fX7e1GlWTK6NGcquXzLdFJ1fgFdujVP9sjIwsTWkLDitX7XnEE3X4n uAzrBAAm0/9uh8I9Z4ic1wZiugGyDWLK/3hmwZw4bdAVYqEi+qHL0RH5cUC6/Fcn/7xIe lyJsgWq4lM8uGFx2RWpJ/ehsxk1NLjthaoNZJ7AaS1Rz+LWxo6tmiJc79HDca+xq2DWoa xMoVNJrViQE9TnTC2IIdyr52H2Eze6+2BtiSUNn5XcW+gc28aEI4yHQZwC1kVY6fn8JSV NO+hdHAK8Yx0khoyXIqLAESBXOaxH+FZgM82caJ0bPQ6F+BNf1w/K3iHJDrs1ue7BVA== 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=RtEKKFTu; 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 EC570606A323; Wed, 2 Dec 2026 17:04:26 +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=RtEKKFTu Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A3941F0089F; Wed, 2 Dec 2026 17:04:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796231066; bh=/Yk3W0nIlwzMoD1kx+82gd65aWS5AksaqyIPDzCEpIo=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=RtEKKFTuFVbQQzh8Be9Pl7GOt3F+MUKSs9iGFYkJbbF2dOp/U+qvZGEJybI6ABhjX EPUrkixS2LzaJU2Kk0qG5jSVLus2w7M+HgLkZ77gg00xNdJfOSDE8PIxlSH4vwjRzX ZgjSLvhqevNbNXQyonsw2k4GRASIkIFaWcs9wXUTtkE5uZuxw6p/ro6gtnZN8arcsM KJKixiAASwQXx5/IB5toKWsQy1BiVi1HbMfPaXpd4XvOM2fQ13VvoEYP1ZeM0Lc19z SuKrJmvVCnyK66My1BFMFUr9qfxwjberAWHcMDd3qmv3I2SjS+Q6fpp+OStmg7gTeB Y5mNnngjOcJ7A== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v8 2/2] Input: add OnePlus/OPPO Pad pogo-pin keyboard serdev driver Reply-To: sashiko-reviews@lists.linux.dev To: wyibo6109@gmail.com, linux-input@vger.kernel.org Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org, dmitry.torokhov@gmail.com In-Reply-To: <20261202164457.1577424-3-wyibo6109@gmail.com> References: <20261202164457.1577424-1-wyibo6109@gmail.com> <20261202164457.1577424-3-wyibo6109@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 17:04:25 +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 15 potential issues to consider: - [High] Input: oneplus-pogo-kbd: wake_irq left enabled in pogo_detect_work() - [High] Input: oneplus-pogo-kbd: unsynchronized wake_irq_enabled in pogo_remove() - [High] Input: oneplus-pogo-kbd: always-on power fails in pogo_detect_work() - [Medium] Input: oneplus-pogo-kbd: missing ABS_MT_TOOL_TYPE in pogo_register_inputs() - [Medium] Input: oneplus-pogo-kbd: unbalanced regulator_disable() in pogo_power_off() - [Medium] Input: oneplus-pogo-kbd: battery frames hijack replies in pogo_handle_frame() - [Medium] Input: oneplus-pogo-kbd: lockless response race in pogo_xfer() - [Medium] Input: oneplus-pogo-kbd: unlocked state updates in pogo_handle_sync() - [Medium] Input: oneplus-pogo-kbd: stuck keys and touches on replug in pogo_plug_work() - [Medium] Input: oneplus-pogo-kbd: unrecoverable plug_work error and sync fallthrough - [Medium] Input: oneplus-pogo-kbd: work cancellation race in pogo_remove() and probe - [Medium] Input: oneplus-pogo-kbd: unsynchronized UART TX across power-off and remove - [Low] Input: oneplus-pogo-kbd: Kconfig selects non-existent INPUT_MT symbol - [Low] Input: oneplus-pogo-kbd: unhandled GPIO error in pogo_detect_work() - [Low] Input: oneplus-pogo-kbd: 2-byte truncation of max-length replies in resp -- commit 611ce95078d79beb5bc1fcb1313e1abec7174a8c Author: Yibo Wang Input: add OnePlus/OPPO Pad pogo-pin keyboard serdev driver This commit adds a serdev input and LED backlight driver for the magnetic pogo-pin keyboard and touchpad used on OnePlus and OPPO Pad tablets. > diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kcon= fig > index 07790614e27fc..3cf1928f85057 100644 > --- a/drivers/input/keyboard/Kconfig > +++ b/drivers/input/keyboard/Kconfig > @@ -757,4 +757,17 @@ config KEYBOARD_CYPRESS_SF > To compile this driver as a module, choose M here: the > module will be called cypress-sf. > =20 > +config KEYBOARD_ONEPLUS_POGO > + tristate "OnePlus/OPPO Pad pogo-pin keyboard" > + depends on SERIAL_DEV_BUS && GPIOLIB > + depends on LEDS_CLASS > + select INPUT_MT [Severity: Low] Does Kconfig define an INPUT_MT symbol? input-mt.o is built into input-core.o unconditionally under CONFIG_INPUT, so selecting INPUT_MT triggers a Kconfig undefined-symbol warning. [ ... ] > diff --git a/drivers/input/keyboard/oneplus-pogo-kbd.c b/drivers/input/ke= yboard/oneplus-pogo-kbd.c > new file mode 100644 > index 0000000000000..6208eda984c67 > --- /dev/null > +++ b/drivers/input/keyboard/oneplus-pogo-kbd.c > @@ -0,0 +1,1272 @@ [ ... ] > + /* host -> keyboard transfers */ > + struct mutex io_lock; > + struct mutex state_lock; > + struct completion echo_done; > + struct completion resp_done; > + u8 tx_cmd; > + bool tx_pending; > + bool quitting; > + u8 resp[OWB_MAX_PAYLOAD]; > + unsigned int resp_len; [Severity: Low] Should resp[] be sized OWB_MAX_PAYLOAD + 2? pogo_handle_frame() copies cmd, len and payload (len + 2 bytes, up to 130 bytes) into kb->resp and clamps to sizeof(kb->resp), which truncates the last two bytes of a maximum-length reply. [ ... ] > +static int pogo_xfer(struct pogo_kbd *kb, u8 cmd, const u8 *payload, u8 = len, > + u8 *resp, unsigned int resp_size) > +{ > + u8 frame[OWB_TX_BUF_LEN]; > + unsigned int frame_len; > + int attempt, ret =3D -ETIMEDOUT; > + > + if (len > OWB_MAX_PAYLOAD) > + return -EINVAL; > + > + frame_len =3D owb_build_frame(frame, cmd, payload, len); > + print_hex_dump_debug("pogo tx: ", DUMP_PREFIX_NONE, 32, 1, frame, frame= _len, false); > + > + mutex_lock(&kb->io_lock); > + for (attempt =3D 0; attempt < POGO_XFER_RETRIES; attempt++) { > + bool echoed; > + > + /* > + * Drop any late echo/reply of the previous attempt: with > + * tx_pending cleared the RX path ignores frames until the > + * transfer below re-arms, so a delayed reply cannot complete > + * the fresh iteration or race the resp buffer. > + */ > + WRITE_ONCE(kb->tx_pending, false); > + reinit_completion(&kb->echo_done); > + reinit_completion(&kb->resp_done); > + kb->tx_cmd =3D cmd; > + WRITE_ONCE(kb->tx_pending, true); > + > + gpiod_set_value_cansleep(kb->tx_en_gpio, 1); > + usleep_range(POGO_TX_GATE_ON_US, POGO_TX_GATE_ON_US + 50); > + > + ret =3D serdev_device_write(kb->serdev, frame, frame_len, > + msecs_to_jiffies(POGO_RESP_TIMEOUT_MS)); > + if (ret >=3D 0) > + serdev_device_wait_until_sent(kb->serdev, > + msecs_to_jiffies(20)); > + > + /* > + * Release the wire as soon as the last bit is out: the MCU > + * answers within a few hundred microseconds and would collide > + * with our idle-high TX driver otherwise. The echo is only > + * checked afterwards, it is already queued in the tty buffer. > + */ > + usleep_range(POGO_TX_GATE_OFF_US, POGO_TX_GATE_OFF_US + 50); > + gpiod_set_value_cansleep(kb->tx_en_gpio, 0); > + > + echoed =3D wait_for_completion_timeout(&kb->echo_done, > + msecs_to_jiffies(POGO_ECHO_TIMEOUT_MS)) !=3D 0; > + > + if (ret < 0) { > + dev_warn(kb->dev, "cmd 0x%02x write failed: %d\n", cmd, ret); > + continue; > + } > + if (!echoed) { > + dev_dbg(kb->dev, "cmd 0x%02x: no echo\n", cmd); > + ret =3D -EIO; > + continue; > + } > + if (!resp) { > + ret =3D 0; > + break; > + } > + if (wait_for_completion_timeout(&kb->resp_done, > + msecs_to_jiffies(POGO_RESP_TIMEOUT_MS))) { > + unsigned int n =3D min(kb->resp_len, resp_size); > + > + /* stop the RX path before copying the reply out */ > + WRITE_ONCE(kb->tx_pending, false); > + memcpy(resp, kb->resp, n); > + ret =3D n; > + break; > + } [Severity: Medium] Can a late echo or reply from a timed-out attempt race with the next retry or with the response copy in pogo_xfer()? CPU0 (pogo_xfer) CPU1 (pogo_handle_frame) wait_for_completion_timeout() /* times out */ WRITE_ONCE(kb->tx_pending, false) reinit_completion(&kb->echo_done) reinit_completion(&kb->resp_done) kb->tx_cmd =3D cmd WRITE_ONCE(kb->tx_pending, true) /* late reply from attempt 0 */ if (READ_ONCE(kb->tx_pending) && ...) memcpy(kb->resp, ...) complete(&kb->resp_done) gpiod_set_value_cansleep(..., 1) serdev_device_write(...) ... wait_for_completion_timeout(&kb->resp_done) /* returns immediately on stale reply */ n =3D min(kb->resp_len, resp_size) WRITE_ONCE(kb->tx_pending, false) /* actual reply for attempt 1 */ kb->resp_len =3D ... memcpy(kb->resp, ...) <-- data race memcpy(resp, kb->resp, n) tx_pending is re-armed at the top of the retry loop before the new frame is transmitted, and pogo_handle_frame() neither holds a lock nor clears tx_pending when writing kb->resp_len and kb->resp. Guarding tx_pending, resp_len and resp with a spinlock will serialize the RX callback against retry setup and reply copying. [ ... ] > + tp->name =3D kb->tp_name; > + tp->phys =3D "pogo/input1"; > + tp->dev.parent =3D kb->dev; > + tp->id.bustype =3D BUS_HOST; > + tp->id.vendor =3D 0x22d9; > + tp->id.product =3D 0x3869; > + tp->id.version =3D 0x0010; > + input_set_drvdata(tp, kb); > + __set_bit(EV_KEY, tp->evbit); > + __set_bit(BTN_LEFT, tp->keybit); > + __set_bit(INPUT_PROP_POINTER, tp->propbit); > + __set_bit(INPUT_PROP_BUTTONPAD, tp->propbit); > + input_set_abs_params(tp, ABS_MT_POSITION_X, 0, kb->hw->tp_max_x, 0, 0); > + input_set_abs_params(tp, ABS_MT_POSITION_Y, 0, kb->hw->tp_max_y, 0, 0); > + input_abs_set_res(tp, ABS_MT_POSITION_X, kb->hw->tp_res_x); > + input_abs_set_res(tp, ABS_MT_POSITION_Y, kb->hw->tp_res_y); > + ret =3D input_mt_init_slots(tp, POGO_TOUCH_FINGERS, > + INPUT_MT_POINTER | INPUT_MT_DROP_UNUSED); [Severity: Medium] Does pogo_register_inputs() need to register ABS_MT_TOOL_TYPE on tp? pogo_report_touchpad() passes MT_TOOL_PALM or MT_TOOL_FINGER to input_mt_report_slot_state(), which emits ABS_MT_TOOL_TYPE. Because input_mt_init_slots() only sets up ABS_MT_SLOT and ABS_MT_TRACKING_ID, the input core drops ABS_MT_TOOL_TYPE events unless input_set_abs_params(tp, ABS_MT_TOOL_TYPE, 0, MT_TOOL_PALM, 0, 0) is called, leaving palm contacts indistinguishable from finger touches. [ ... ] > +static void pogo_handle_sync(struct pogo_kbd *kb, const u8 *p, unsigned = int len) > +{ > + bool replug =3D false; > + > + if (len < 2) > + return; > + > + if (p[0] =3D=3D OWB_SYNC_PLUG_IN && p[1] =3D=3D 0x02 && len >=3D 9) { > + kb->brand =3D p[2]; > + memcpy(kb->mac, &p[3], POGO_MAC_LEN); > + /* > + * The MCU repeats this frame until the host has talked to it; > + * only a plug-in frame after regular heartbeats is a re-plug. > + */ > + replug =3D kb->connected && kb->hb_seen; > + } else if (p[0] =3D=3D OWB_SYNC_HEARTBEAT && p[1] =3D=3D 0x02 && len >= =3D 10) { > + kb->brand =3D p[3]; > + memcpy(kb->mac, &p[4], POGO_MAC_LEN); > + kb->hb_seen =3D true; > + } > + > + if (!kb->connected || replug) { > + kb->connected =3D true; > + kb->hb_seen =3D false; > + kb->retry_ms =3D POGO_RETRY_MIN_MS; > + if (!READ_ONCE(kb->quitting)) > + schedule_work(&kb->plug_work); > + } > +} [Severity: Medium] Can a queued sync frame processed concurrently with pogo_power_off() leave kb->connected stuck at true while kb->powered is false? CPU0 (pogo_hb_work) CPU1 (pogo_receive_buf) pogo_power_off() mutex_lock(&kb->state_lock) kb->connected =3D false kb->powered =3D false mutex_unlock(&kb->state_lock) pogo_handle_sync() if (!kb->connected || replug) kb->connected =3D true schedule_work(&kb->plug_work) pogo_plug_work() if (... || !kb->powered || ...) return; <-- kb->connected left true pogo_handle_sync() updates kb->connected and kb->hb_seen without holding kb->state_lock or checking kb->powered. Once kb->connected is left true with kb->powered false, sysfs reports the detached keyboard as connected and LED or backlight updates attempt UART transfers on an unpowered bus. Also, neither pogo_power_off() nor pogo_power_on() resets kb->in_frame or kb->sync_cnt across power cycles. > + > +static void pogo_handle_frame(struct pogo_kbd *kb, const u8 *f, unsigned= int n) > +{ [ ... ] > + default: > + if (cmd =3D=3D OWB_CMD_GENERAL_ACK && len >=3D 4 && > + payload[0] =3D=3D OWB_GEN_BATTERY_STATUS) > + kb->battery_level =3D payload[2]; > + > + if (READ_ONCE(kb->tx_pending) && cmd =3D=3D kb->tx_cmd + 1) { > + /* reply layout for callers: cmd, len, payload */ > + kb->resp_len =3D min_t(unsigned int, len + 2, sizeof(kb->resp)); > + memcpy(kb->resp, &f[3], kb->resp_len); > + complete(&kb->resp_done); > + } else { > + dev_dbg(kb->dev, "unhandled frame cmd 0x%02x len %u\n", > + cmd, len); > + } > + break; > + } > +} [Severity: Medium] Should the unsolicited OWB_GEN_BATTERY_STATUS check break out of the switch? Because it falls through into the tx_pending check and carries OWB_CMD_GENERAL_ACK (OWB_CMD_GENERAL + 1), an unsolicited battery frame arriving while pogo_set_general() is waiting for a reply overwrites kb->resp and completes kb->resp_done, causing pogo_set_general() to fail with -EPROTO (resp[2] !=3D sub). [ ... ] > +static void pogo_wake_irq_enable(struct pogo_kbd *kb, bool enable) > +{ > + if (enable =3D=3D kb->wake_irq_enabled) > + return; > + if (enable) { > + /* > + * Update the state before enabling: the ISR may fire on > + * another CPU the moment enable_irq() runs and flip the > + * state to false; assigning after enable_irq() would > + * clobber that and desynchronise software and hardware. > + */ > + kb->wake_irq_enabled =3D true; > + enable_irq(kb->wake_irq); > + } else { > + /* disable_irq() waits for a running ISR before returning */ > + disable_irq(kb->wake_irq); > + kb->wake_irq_enabled =3D false; > + } > +} [Severity: High] Can unsynchronized accesses to kb->wake_irq_enabled race between pogo_wake_isr(), pogo_wake_irq_enable() and pogo_remove()? CPU0 (pogo_remove) CPU1 ( pogo_wake_isr) disable_irq_nosync(irq) kb->wake_irq_enabled =3D false if (!READ_ONCE(kb->quitting)) WRITE_ONCE(kb->quitting, true) pogo_wake_irq_enable(kb, false) if (enable =3D=3D kb->wake_irq_enabled) return; /* skips disable_irq() */ cancel_delayed_work_sync(&kb->detect_work) ... mod_delayed_work(..., &kb->detect_work,= ...) <-- queued after cancel, use-after-fr= ee If pogo_wake_isr() clears kb->wake_irq_enabled before pogo_remove() calls pogo_wake_irq_enable(kb, false), pogo_wake_irq_enable() returns early without calling disable_irq() to wait for the running ISR. Conversely, if pogo_wake_isr() fires after pogo_wake_irq_enable(kb, false) checks kb->wake_irq_enabled, both disable_irq_nosync() and disable_irq() run, bumping the IRQ disable depth to 2 so a subsequent enable_irq() leaves wake_irq disabled. In addition, pogo_detect_work() does not re-check kb->quitting after its 120 ms sampling loop before calling pogo_power_on() or pogo_wake_irq_enable(kb, true). > + > +static void pogo_power_on(struct pogo_kbd *kb) > +{ > + int ret; > + > + dev_dbg(kb->dev, "power on\n"); > + mutex_lock(&kb->state_lock); > + kb->connected =3D false; > + kb->hb_seen =3D false; > + kb->battery_level =3D -1; > + kb->last_rx =3D jiffies; > + kb->powered =3D true; > + mutex_unlock(&kb->state_lock); > + if (kb->vdd) { > + ret =3D regulator_enable(kb->vdd); > + if (ret) > + dev_warn(kb->dev, "failed to enable vdd: %d\n", ret); > + } > + if (kb->enable_gpio) > + gpiod_set_value_cansleep(kb->enable_gpio, 1); > + mod_delayed_work(system_dfl_wq, &kb->hb_work, > + msecs_to_jiffies(POGO_HB_POLL_MS)); > +} > + > +static void pogo_power_off(struct pogo_kbd *kb) > +{ > + bool was_connected; > + > + mutex_lock(&kb->state_lock); > + was_connected =3D kb->connected; > + kb->connected =3D false; > + kb->powered =3D false; > + mutex_unlock(&kb->state_lock); > + > + dev_dbg(kb->dev, "power off\n"); > + if (kb->enable_gpio) > + gpiod_set_value_cansleep(kb->enable_gpio, 0); > + if (kb->vdd && regulator_disable(kb->vdd)) > + dev_warn(kb->dev, "failed to disable vdd\n"); [Severity: Medium] Does pogo_power_off() call regulator_disable(kb->vdd) even when kb->powered is already false? pogo_remove() unconditionally calls pogo_power_off(kb). When the driver is unbound while no keyboard is attached (or after pogo_hb_work() has already powered it off), kb->powered is false and regulator_disable() is called on an already disabled regulator, triggering an unbalanced regulator disable WARN in _regulator_disable(). The same imbalance occurs if regulator_enable() fails in pogo_power_on(), which still sets kb->powered =3D true and schedules hb_work. > + if (was_connected) > + dev_info(kb->dev, "keyboard detached\n"); > + > + /* > + * Unregister whenever the devices exist, not only when connected: > + * pogo_plug_work() can race a disconnect and register them after > + * this function already ran once, and pogo_remove() relies on this > + * to release them. No-op when already unregistered. > + */ > + pogo_unregister_inputs(kb); > +} > + > +static void pogo_detect_work(struct work_struct *work) > +{ > + struct pogo_kbd *kb =3D container_of(work, struct pogo_kbd, > + detect_work.work); > + > + int i; > + > + if (READ_ONCE(kb->quitting) || kb->powered) > + return; > + > + /* the unpowered keyboard holds the wire low; require a stable level */ > + for (i =3D 0; i < POGO_DETECT_SAMPLES; i++) {\n> + if (!gpiod_get_valu= e_cansleep(kb->wake_gpio)) > + break; > + msleep(POGO_DETECT_SAMPLE_MS); > + } [Severity: Low] Can a negative error code from gpiod_get_value_cansleep(kb->wake_gpio) be treated as an active wake signal here and in the re-check below? Checking gpiod_get_value_cansleep(kb->wake_gpio) <=3D 0 in the loop (and > 0 below) avoids powering on or rescheduling detect_work on a GPIO read error. > + if (i =3D=3D POGO_DETECT_SAMPLES) { > + pogo_power_on(kb); > + return; > + } [Severity: High] Can kb->powered ever become true on boards where neither vdd-supply nor enable-gpios is provided? The commit message notes that boards providing neither keep keyboard power always-on. However, as the comment above states, only an unpowered keyboard holds the shared wire continuously low across 6 x 20 ms samples; an already-powered MCU holds the UART wire idle-high between 0.3 ms sync frames. As a result, pogo_detect_work() never reaches POGO_DETECT_SAMPLES to call pogo_power_on(), kb->powered stays false, and pogo_plug_work() always bails out at !kb->powered without registering the input devices. > + > + kb->retry_ms =3D POGO_RETRY_MIN_MS; > + pogo_wake_irq_enable(kb, true); > + /* the edge may have happened before the irq was armed */ > + if (!READ_ONCE(kb->quitting) && gpiod_get_value_cansleep(kb->wake_gpio)) > + mod_delayed_work(system_dfl_wq, &kb->detect_work, > + msecs_to_jiffies(POGO_DETECT_DEBOUNCE_MS)); > +} [Severity: High] Does rescheduling detect_work here leave wake_irq enabled across pogo_power_on()? If wake_gpio goes active just before pogo_wake_irq_enable(kb, true), wake_irq is enabled and detect_work is rescheduled for 120 ms later. Because the unpowered keyboard holds the line steady, pogo_wake_isr() does not fire in the meantime, and on the next run pogo_detect_work() sees 6 active samples and calls pogo_power_on(kb) without disabling wake_irq, leaving wake_irq enabled while 921600-baud UART traffic starts on the shared wire. > + > +static void pogo_hb_work(struct work_struct *work) > +{ > + struct pogo_kbd *kb =3D container_of(work, struct pogo_kbd, hb_work.wor= k); > + unsigned int timeout =3D kb->connected ? POGO_HB_TIMEOUT_MS : > + POGO_BOOT_TIMEOUT_MS; > + > + if (!kb->powered) > + return; > + > + if (time_before(jiffies, kb->last_rx + msecs_to_jiffies(timeout))) { > + if (!READ_ONCE(kb->quitting)) > + schedule_delayed_work(&kb->hb_work, > + msecs_to_jiffies(POGO_HB_POLL_MS)); > + return; > + } > + > + dev_dbg(kb->dev, "heartbeat lost (%s)\n", > + kb->connected ? "connected" : "booting"); > + pogo_power_off(kb); > + > + /* re-arm: retry while the wake line still reports a keyboard */ > + if (!READ_ONCE(kb->quitting)) > + schedule_delayed_work(&kb->detect_work, > + msecs_to_jiffies(kb->retry_ms)); > + kb->retry_ms =3D min(kb->retry_ms * 2, POGO_RETRY_MAX_MS); > +} [Severity: Medium] Can pogo_power_off() cut power while pogo_xfer() is still driving UART TX onto the shared wire? pogo_power_off() lowers enable_gpio and disables vdd without serializing against kb->io_lock or cancelling plug_work and led_work, and pogo_xfer() never checks kb->powered or kb->quitting across its 3 retries (which also causes pogo_remove() to stall waiting for all retries to time out after setting kb->quitting =3D true makes pogo_receive_buf() drop all echoes). In addition, scheduling detect_work after kb->retry_ms (1 s to 30 s) on heartbeat loss leaves wake_irq disabled for the entire backoff window after a normal detach. > + > +static void pogo_plug_work(struct work_struct *work) > +{ > + struct pogo_kbd *kb =3D container_of(work, struct pogo_kbd, plug_work); > + int ret; > + > + if (READ_ONCE(kb->quitting) || !kb->powered || !kb->connected) > + return; > + > + if (!kb->kbd) { > + ret =3D pogo_register_inputs(kb); > + if (ret) { > + dev_err(kb->dev, "failed to register input devices: %d\n", > + ret); > + return; > + } > + /* > + * A disconnect may have raced the registration: power_off() > + * could have run before kb->kbd was assigned and therefore > + * could not unregister. Re-check under state_lock and undo. > + */ > + mutex_lock(&kb->state_lock); > + if (!kb->powered) { > + mutex_unlock(&kb->state_lock); > + pogo_unregister_inputs(kb); > + return; > + } > + mutex_unlock(&kb->state_lock); > + dev_info(kb->dev, "keyboard attached: %s (brand %u, mac %pM)\n", > + kb->kbd_name, kb->brand, kb->mac); > + } [Severity: Medium] If a fast re-plug or MCU reset happens while kb->kbd is already registered, should pogo_plug_work() call pogo_release_all(kb) under kb->input_lock? When pogo_handle_sync() detects a re-plug before the 500 ms heartbeat timeout expires, kb->kbd is non-NULL so pogo_plug_work() skips registration and never releases keys or touchpad slots that were held down before the MCU reset, leaving them stuck pressed (and autorepeating). > + > + /* > + * Report the host as awake: this is what moves the MCU from the > + * repeated plug-in sync frames to regular heartbeats. Then restore > + * the host side state on the (possibly re-plugged) MCU. > + */ > + /* caihong era MCUs have no wake notification sub-command */ > + if (kb->hw->features & POGO_FEAT_WAKE_NOTIFY) { > + ret =3D pogo_set_general(kb, OWB_GEN_SLEEP, 0); > + if (ret) > + dev_warn(kb->dev, "wake notify failed: %d\n", ret); > + } [Severity: Medium] What happens if pogo_set_general(kb, OWB_GEN_SLEEP, 0) or pogo_register_inputs(kb) fails in pogo_plug_work()? pogo_handle_sync() already set kb->connected =3D true and kb->hb_seen =3D false before scheduling plug_work. If the wake notification fails, the MCU keeps sending OWB_SYNC_PLUG_IN every 100 ms (refreshing kb->last_rx so hb_work never times out), while pogo_handle_sync() sees kb->connected && !kb->hb_seen and never schedules plug_work again, leaving the link wedged. In pogo_handle_sync(), an unrecognized 0x2F frame with len >=3D 2 also falls through to mark kb->connected =3D true with uninitialized brand/MAC, and an initial OWB_SYNC_HEARTBEAT frame sets kb->hb_seen =3D true only for if (!kb->connected) to immediately overwrite it with false. [ ... ] > +static void pogo_remove(struct serdev_device *serdev) > +{ > + struct pogo_kbd *kb =3D serdev_device_get_drvdata(serdev); > + > + /* > + * Stop the world first: with quitting set, the RX path and the > + * works stop queueing each other, so the cancels below cannot be > + * undone again. The wake IRQ is disabled (and any in-flight ISR > + * finished) before detect_work is cancelled. > + */ > + WRITE_ONCE(kb->quitting, true); > + pogo_wake_irq_enable(kb, false); > + cancel_delayed_work_sync(&kb->detect_work); > + cancel_delayed_work_sync(&kb->hb_work); > + cancel_work_sync(&kb->plug_work); [Severity: Medium] Can pogo_hb_work() or pogo_receive_buf() re-queue work after cancel_*_work_sync() in pogo_remove() and pogo_probe()'s err_shutdown path? CPU0 (pogo_remove) CPU1 (kworker / serdev RX) pogo_hb_work() if (!READ_ONCE(kb->quitting)) WRITE_ONCE(kb->quitting, true) cancel_delayed_work_sync(&kb->detect_work) schedule_delayed_work(&kb->detect_wor= k, ...) cancel_delayed_work_sync(&kb->hb_work) ... /* devm frees kb while detect_work is still pending */ detect_work is cancelled before hb_work even though pogo_hb_work() queues detect_work, and serdev remains open until devres cleanup runs after pogo_remove() returns so an in-flight pogo_receive_buf() -> pogo_handle_sync() that just passed !READ_ONCE(kb->quitting) can likewise call schedule_work(&kb->plug_work) after cancel_work_sync(&kb->plug_work). Using disable_delayed_work_sync() and disable_work_sync() (and cancelling hb_work before detect_work) prevents work items from being re-queued during teardown. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202164457.1577= 424-1-wyibo6109@gmail.com?part=3D2