Re: [PATCH v1 2/2] platform: arm64: huawei-gaokun-ec: Validate the PAN ACK bit index
From: Pengyu Luo
Date: Sat Nov 28 2026 - 01:41:31 EST
On Thu, Nov 26, 2026 at 3:08 PM Lee Youngjoon <getfeus@xxxxxxxxx> wrote:
>
> The UCSI driver passes GAOKUN_UCSI_NO_PORT_UPDATE (-1) when the EC
> reports no port update. gaokun_ec_ucsi_pan_ack() shifts by port_id
> before checking the sentinel, so this normal path evaluates a negative
> shift even though it subsequently sends a zero mask.
>
> Initialize the one-byte mask to zero. For an actual port, check that
> the index fits in the mask before setting its bit. This preserves the
> empty ACK and rejects unrepresentable indices before contacting the EC.
>
> Fixes: 7636f090d02e ("platform: arm64: add Huawei Matebook E Go EC driver")
> Link: https://lore.kernel.org/r/20260607214621.9586A1F00893@xxxxxxxxxxxxxxx
> Signed-off-by: Lee Youngjoon <getfeus@xxxxxxxxx>
> ---
> drivers/platform/arm64/huawei-gaokun-ec.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/platform/arm64/huawei-gaokun-ec.c
> b/drivers/platform/arm64/huawei-gaokun-ec.c
> index abf05e7ec..95e867596 100644
> --- a/drivers/platform/arm64/huawei-gaokun-ec.c
> +++ b/drivers/platform/arm64/huawei-gaokun-ec.c
> @@ -458,10 +458,13 @@ EXPORT_SYMBOL_GPL(gaokun_ec_ucsi_get_reg);
> int gaokun_ec_ucsi_pan_ack(struct gaokun_ec *ec, int port_id)
> {
> u8 ec_req[] = MKREQ(0x03, UCSI_REG_WRITE, 1);
> - u8 data = 1 << port_id;
> + u8 data = 0;
>
> - if (port_id == GAOKUN_UCSI_NO_PORT_UPDATE)
> - data = 0;
> + if (port_id != GAOKUN_UCSI_NO_PORT_UPDATE) {
> + if (port_id < 0 || port_id >= BITS_PER_BYTE)
This is right in logic, but we should follow the hardware fact, this
tablet is designed with two connectors, even if a new product with the
same EC is released, it must not have 9 connectors, so using
BITS_PER_BYTE may confuse us.
Best wishes,
Pengyu
> + return -EINVAL;
> + data = BIT(port_id);
> + }
>
> refill_req_byte(ec_req, &data);