Re: [PATCH v6 1/3] i2c: xiic: preserve PEC byte length in SMBus block read setup
From: Abdurrahman Hussain
Date: Thu Sep 24 2026 - 20:09:49 EST
Hi Andi,
On Thu Sep 24, 2026 at 1:09 PM PDT, Andi Shyti wrote:
> what if rxmsg is 1? Before this could never happen because we
> were checking for rxmsg_len == 0 or 1 and we were ending up here
> for values greater than 1.
>
> In patch 2 you fix things, but we don't want to have dependencies
> between patches.
>
Confirmed. The widened condition makes the else branch reachable with
rxmsg_len < 2, where rfd_set = rxmsg_len - 2 wraps the u8. Traced on
hardware against a zero-length block read, sweeping pec_len:
pec_len: 0 1 2 3
v6 patch 1 rfd_set: 0 0 254 254
v7 patch 1 rfd_set: 0 0 0 1
It doesn't actually hang on my boards -- 254 lands in the 4-bit RFD
field as 14, and both slaves I have keep clocking past the end of the
block, so the FIFO still reaches 15. The programmed value is wrong
regardless.
Restoring the old "(rxmsg_len == 1) || (rxmsg_len == 0)" isn't right
either: pec_len isn't limited to 0 or 1, because i2c-dev sets msg->len
from caller-supplied buf[0]. At rxmsg_len == 1, pec_len == 2 the padded
branch would record smbus_actual_len = 4 while draining only 3.
So v7 moves the bounds into patch 1, where the arithmetic is introduced:
- the guard becomes (rxmsg_len + pec_len > IIC_RX_FIFO_DEPTH), which
is what keeps rfd_set inside the 4-bit field;
- the else branch becomes rfd_set = rxmsg_len + pec_len - 2, identical
to the old expression at pec_len == 0 and unable to underflow, since
the padded branch already takes everything below MIN_LEN total.
Patch 2 is then just - 2 to - 1. Resulting tree is identical to v6.
I also finally exercised the atomic trim you asked for in v5, by routing
transfers through xiic_xfer_atomic: it fires, and block lengths 0 to 32
read back correctly on that path.
Two notes from the per-patch run. Unpatched, pmbus_core creates no mfr_*
files for these devices and every PEC block read returns -EIO; with the
series they read correctly. But patch 1 alone isn't observable
end-to-end (patch 3's -EIO masks it), and patch 2 changes nothing I can
measure on my two slaves -- its bug needs one that NACKs promptly rather
than streaming.
While I have your attention: the other xiic patch, "i2c: xiic: restore
non-managed runtime PM to fix clk WARN flood", is still unapplied. Andy
acked it on 10 Sep and the review comment it had is closed. It fixes a
regression from my own 50c63491ff26, which is in both v7.1 and v7.2, so
7.3-rcX would be a good target if it looks right to you.
https://patch.msgid.link/20260821-i2c-xiic-restore-runtime-pm-teardown-v7-1-954e06765144@xxxxxxxxxx
Unrelated, for later: smbus_block_read is only cleared in the BNB
handler, which the atomic path never reaches.
Abdurrahman