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=1795998375; b=lC5PdEe0tNhhe1ttVwjYz+cW+MFS0VOEuJ9obgijgPgmBig9sklNvQlVKZzlzYCQS3d8 HeVFKicqRBKAgEJYbjDfgg/GYQxWVsLXxc0PI1msgRAcjRFCndDxgCLAw4RU2bye/VTDR gEHAl2A6J1Z6lPKMnDs80J4MhwezgABw1/e59fbYB5K4SUpnPuSCsCJvmqTjyYILms1V4 OQPtEkPq2bCKkBPkljGPGe31lX28GL4GgjHVw7bRT0MKlYg4a1CHRlqWPiiaqnJcMfPcV gaB+ydegdXvyBt+8Xx8LCrp7taDuhGl7+cb52MLEWidcWEx4Ej8HM9f79LiFMBdjykg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795998375; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=7ktSyFkXy+eluxIqjav3M0VRIq6g69hP8+RliIQ4OHg=; b=KNEpfDaSFGmnCnbHmB/1oyNaJ0yHlEEYpDvzImOSOymnmqvEFY7cFiZappPScDFs3v0/ dNjg9P6+s0E10OT9PSOzHdDC+V/hdauyd1saIiP68D8FSgSOzly9Fs5403UNjxII/Mqfw CQ3wYORf8rbuR5TQri9dQ4RkndCJtXLqdqqrOnUG77NNuMudNvT15dIoe9Jrei5ef95QO aw0q2gyNqfeEr6Ip+Mqjog+/OdTXH484kbLNMyp/DkOPjv15H/Qf8Zw8Ub0uptd4IRr0V UTPEwAJx0LUHkrqwUVvRHwTYh1CB3MF7muo8EPuxhWUisC7ThyadrHJ2DYVo62GM+pw== 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="UYSK6IU/"; 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 A7554606A31C; Mon, 30 Nov 2026 00:26:15 +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=UYSK6IU/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2AB501F00897; Mon, 30 Nov 2026 00:26:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795998375; bh=7ktSyFkXy+eluxIqjav3M0VRIq6g69hP8+RliIQ4OHg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=UYSK6IU/gbfrAr1rlIxVmBwhgz3RHZnlKH7shZomegalBXQvTUePjAyhAZLHVam5O pw6ZPM59yLLaoGQxhTeH7rr3b5tMD83M5ra2hC7XZ5mLbSlI60wYCoLqWMS8k4MSky rddRQDk+fEKSZL/tRp+mR4VaI75g1dDVaoPTNZPqWmuMK7RQSsBtDtS1gN7srLpxbp L+dc9ItyMAlmwmlqOt9q3PHoMmumBXbKXjbJlbsIG3hWxhocIiNaRaQnVF5Aryb8xS flJ2Dd+3cP6A6vONHzzw6+3sum4y1sFcoMzJw172PvL/Gt6IxvmmucK7CGWGX5aef5 h1DWvJOa3VTtA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v8 3/9] Input: qcom-pmi8998-haptics - Add Qualcomm PMI8998 haptics driver Reply-To: sashiko-reviews@lists.linux.dev To: "David Heidelberg" Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, mfd@lists.linux.dev, robh@kernel.org, conor+dt@kernel.org, dmitry.torokhov@gmail.com, lee@kernel.org In-Reply-To: <20261130-qcom-pmi8998-haptics-v8-3-a64ecd72d3bb@ixit.cz> References: <20261130-qcom-pmi8998-haptics-v8-0-a64ecd72d3bb@ixit.cz> <20261130-qcom-pmi8998-haptics-v8-3-a64ecd72d3bb@ixit.cz> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 00:26:14 +0000 X-Mailing-List: devicetree@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 3 potential issues to consider: - [Medium] Input: race between pmi8998_haptics_work() and pmi8998_haptics_erase() - [Medium] Input: premature auto_res_work execution in pmi8998_haptics_auto_res_work() - [Low] Input: direct error return in multi-failure qcom-pmi8998-haptics helpers -- commit c3d9968584652dc5c9afb2487c36dd83fdc8de7f Author: David Heidelberg Input: qcom-pmi8998-haptics - Add Qualcomm PMI8998 haptics driver This commit adds an input force-feedback driver for the haptics module in the Qualcomm PMI8998 and PM660 PMICs, supporting LRA and ERM actuators in direct and buffer playback modes. > diff --git a/drivers/input/misc/qcom-pmi8998-haptics.c b/drivers/input/mi= sc/qcom-pmi8998-haptics.c > new file mode 100644 > index 0000000000000..480c56bc35f42 > --- /dev/null > +++ b/drivers/input/misc/qcom-pmi8998-haptics.c > @@ -0,0 +1,2025 @@ [ ... ] > +static int pmi8998_haptics_write_play_mode(struct pmi8998_haptics *hapti= cs, > + u8 source) > +{ > + u8 val; > + > + if (!is_haptics_idle(haptics)) > + return -EBUSY; > + > + val =3D FIELD_PREP(HAP_WF_SOURCE_MASK, source); > + return pmi8998_haptics_write_masked(haptics, HAP_SEL_REG, > + HAP_WF_SOURCE_MASK, val); > +} [ ... ] > +static void pmi8998_haptics_auto_res_work(struct work_struct *work) > +{ > + struct pmi8998_haptics *haptics =3D container_of(to_delayed_work(work), > + struct pmi8998_haptics, > + auto_res_work); > + > + guard(mutex)(&haptics->play_lock); > + > + if (!haptics->hw_enabled) > + return; > + > + if (!haptics->auto_res_enabled) { > + if (pmi8998_haptics_set_auto_res(haptics, true) < 0) > + return; > + if (haptics->data->hw_auto_res) > + return; > + } else { > + pmi8998_haptics_update_rate(haptics); > + if (!haptics->auto_res_enabled) > + return; > + } > + > + mod_delayed_work(system_percpu_wq, &haptics->auto_res_work, > + msecs_to_jiffies(HAP_AUTO_RES_POLL_MS)); > +} [ ... ] > +static int pm660_haptics_init_chip(struct pmi8998_haptics *haptics) > +{ > + u8 val =3D HAP_EN_CTL3_DEFAULT; > + int err; > + > + err =3D pmi8998_haptics_write(haptics, HAP_EN_CTL3_REG, &val, 1); > + if (err < 0) > + return err; > + > + return pmi8998_haptics_write_masked(haptics, HAP_ZX_CFG_REG, > + HAP_ZX_DET_DEB_MASK, > + HAP_ZX_DET_DEB_80US); > +} > + > +static int pm660_haptics_config_auto_res(struct pmi8998_haptics *haptics) > +{ > + u8 val, mask; > + int err; > + > + if (haptics->auto_res_mode =3D=3D QCOM_LRA_AUTO_RES_MODE_QWD) { > + val =3D FIELD_PREP(PM660_AUTO_RES_MODE_MASK, PM660_AUTO_RES_QWD) | > + FIELD_PREP(PM660_CAL_DURATION_MASK, haptics->lra_high_z); > + } else { > + u8 cal_period =3D ilog2(haptics->res_cal_period / > + HAP_RES_CAL_PERIOD_MIN) + 1; > + > + val =3D FIELD_PREP(PM660_AUTO_RES_MODE_MASK, PM660_AUTO_RES_ZXD) | > + FIELD_PREP(PM660_CAL_DURATION_MASK, haptics->lra_high_z) | > + PM660_CAL_EOP_EN_BIT | > + FIELD_PREP(PM660_LRA_RES_CAL_MASK, cal_period); > + } > + > + mask =3D PM660_AUTO_RES_MODE_MASK | PM660_CAL_DURATION_MASK | > + PM660_CAL_EOP_EN_BIT | PM660_LRA_RES_CAL_MASK; > + > + err =3D pmi8998_haptics_write_masked(haptics, HAP_LRA_AUTO_RES_REG, > + mask, val); > + if (err < 0) > + return err; > + > + val =3D HAP_SEL_AUTO_RES_PERIOD_BIT | > + FIELD_PREP(HAP_AUTO_RES_CNT_ERR_DELTA_MASK, > + HAP_AUTO_RES_CNT_ERR_DELTA_DEF) | > + HAP_AUTO_RES_ERR_RECOVERY_BIT | > + FIELD_PREP(HAP_AUTO_RES_EN_DLY_MASK, HAP_AUTO_RES_EN_DLY_DEF); > + > + return pmi8998_haptics_write(haptics, HAP_AUTO_RES_CTRL_REG, &val, 1); > +} [Severity: Low] This isn't a bug, but input subsystem style prefers that functions with multiple failure points (pmi8998_haptics_write_play_mode(), pm660_haptics_init_chip(), and pm660_haptics_config_auto_res()) check the final call's error and explicitly return 0 on the success path rather than ending with "return action(...);". [ ... ] > +static int pmi8998_haptics_hw_start_locked(struct pmi8998_haptics *hapti= cs) > +{ > + int err; > + > + lockdep_assert_held(&haptics->play_lock); > + > + cancel_delayed_work(&haptics->auto_res_work); [ ... ] > + if (haptics->act_type =3D=3D HAP_TYPE_LRA) { > + if (haptics->auto_res_mode =3D=3D QCOM_LRA_AUTO_RES_MODE_QWD) { > + /* > + * With the quarter-wave detection mode the high impedance is > + * applied for every LRA cycle, so there is not enough back-EMF > + * at the start of the playback. Defer enabling auto resonance > + * until the actuator has vibrated for a few cycles. > + */ > + mod_delayed_work(system_percpu_wq, &haptics->auto_res_work, > + msecs_to_jiffies(HAPTICS_BACK_EMF_DELAY_MS)); > + } else { > + err =3D pmi8998_haptics_set_auto_res(haptics, true); > + if (err < 0) { > + dev_err(haptics->dev, "Error enabling auto_res, err=3D%d\n", > + err); > + goto out_disable; > + } > + > + /* > + * Follow the resonance of the actuator while it is driven, the > + * measured drive period is read back from the hardware. > + */ > + if (!haptics->data->hw_auto_res) > + mod_delayed_work(system_percpu_wq, > + &haptics->auto_res_work, > + msecs_to_jiffies(HAP_AUTO_RES_POLL_MS)); > + } > + } [Severity: Medium] Can an already-dispatched pmi8998_haptics_auto_res_work() run immediately after pmi8998_haptics_hw_start_locked() releases haptics->play_lock, skipping the back-EMF or calibration delay? CPU0 CPU1 (kworker) pmi8998_haptics_work() lock(&haptics->play_lock) pmi8998_haptics_auto_res_work() lock(&haptics->play_lock) [blocks] pmi8998_haptics_hw_start_locked() cancel_delayed_work(&auto_res_work) pmi8998_haptics_set_auto_res(false) ... mod_delayed_work(..., 20 ms) unlock(&haptics->play_lock) [acquires play_lock at t =3D 0 ms] if (!haptics->auto_res_enabled) pmi8998_haptics_set_auto_res(tr= ue) <-- enables before back-EMF d= elay cancel_delayed_work() cannot cancel a worker already blocked on haptics->play_lock, and unlike pmi8998_haptics_stop_work(), pmi8998_haptics_auto_res_work() does not check a readiness timestamp after acquiring the lock. In QWD mode, the waiting worker enables auto-resonance at 0 ms without waiting HAPTICS_BACK_EMF_DELAY_MS; on PM660 (where hw_auto_res is true), it also leaves the 20 ms timer armed, which later sees auto_res_enabled =3D=3D= true and starts software polling via pmi8998_haptics_update_rate(). In ZXD_EOP mode, the waiting worker calls pmi8998_haptics_update_rate() at 0 ms before haptics->auto_res_ready has elapsed, reading an uncalibrated period that can disable auto-resonance. Checking time_after_eq(jiffies, haptics->auto_res_ready) in pmi8998_haptics_auto_res_work() (and setting auto_res_ready when arming the QWD back-EMF delay) would prevent the stale worker from acting early. [ ... ] > +static void pmi8998_haptics_work(struct work_struct *work) > +{ > + struct pmi8998_haptics *haptics =3D container_of(work, > + struct pmi8998_haptics, > + work); > + > + for (;;) { > + struct pmi8998_haptics_effect *eff =3D NULL; > + int effect_id; > + bool play; > + int err =3D 0; > + > + scoped_guard(spinlock_irqsave, &haptics->req_lock) { > + if (!list_empty(&haptics->play_queue)) { > + eff =3D list_first_entry(&haptics->play_queue, > + struct pmi8998_haptics_effect, > + play_node); > + list_del_init(&eff->play_node); > + play =3D eff->play_req; > + } > + } > + > + if (!eff) > + return; > + > + effect_id =3D eff - haptics->effects; > + dev_dbg(haptics->dev, "%s: effect: %d play: %d\n", > + __func__, effect_id, play); > + > + scoped_guard(mutex, &haptics->play_lock) { > + if (play) > + err =3D pmi8998_haptics_enable_locked(haptics, > + effect_id); > + else if (haptics->active_effect_id =3D=3D effect_id) > + err =3D pmi8998_haptics_disable_locked(haptics); > + } > + > + if (err < 0) > + dev_err(haptics->dev, "Error setting haptics, err=3D%d\n", > + err); > + } > +} [ ... ] > +static int pmi8998_haptics_erase(struct input_dev *dev, int effect_id) > +{ > + struct pmi8998_haptics *haptics =3D input_get_drvdata(dev); > + struct pmi8998_haptics_effect *eff; > + > + if (effect_id < 0 || effect_id >=3D HAPTICS_MAX_EFFECTS) > + return -EINVAL; > + > + guard(mutex)(&haptics->play_lock); > + > + eff =3D &haptics->effects[effect_id]; > + > + scoped_guard(spinlock_irqsave, &haptics->req_lock) > + list_del_init(&eff->play_node); > + > + if (haptics->active_effect_id =3D=3D effect_id) > + pmi8998_haptics_disable_locked(haptics); > + > + eff->mode =3D PMI8998_HAPTICS_MODE_NONE; [Severity: Medium] Can pmi8998_haptics_work() race with pmi8998_haptics_erase() (or a stop request) by popping eff->play_node and snapshotting play =3D eff->play_req before acquiring haptics->play_lock? CPU0 (kworker) CPU1 pmi8998_haptics_work() lock(&haptics->req_lock) list_del_init(&eff->play_node) play =3D eff->play_req; /* true */ unlock(&haptics->req_lock) erase_effect() pmi8998_haptics_playback(..., 0) eff->play_req =3D false list_add_tail(&eff->play_node, = ...) pmi8998_haptics_erase() lock(&haptics->play_lock) list_del_init(&eff->play_node) eff->mode =3D PMI8998_HAPTICS_M= ODE_NONE unlock(&haptics->play_lock) lock(&haptics->play_lock) if (play) pmi8998_haptics_enable_locked() <-- runs after erase When pmi8998_haptics_work() finally acquires haptics->play_lock with its stale play =3D=3D true snapshot, pmi8998_haptics_enable_locked() either fai= ls with -EINVAL and logs a spurious dev_err(), or, if a new effect has already been uploaded into the freed slot, starts vibrating the new effect after its stop request was deleted by pmi8998_haptics_erase(). Popping eff->play_node before acquiring haptics->play_lock also prevents start/stop requests from coalescing in play_queue while play_lock is held across SPMI writes and pmi8998_haptics_wait_idle(). Since pmi8998_haptics_erase() already nests req_lock inside play_lock, acquiring play_lock before taking req_lock to dequeue from play_queue in pmi8998_haptics_work() would avoid this race and keep request coalescing intact. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130-qcom-pmi89= 98-haptics-v8-0-a64ecd72d3bb@ixit.cz?part=3D3