[PATCH v2 2/2] platform: arm64: huawei-gaokun-ec: Validate the PAN ACK bit index

From: YoungJoon Lee

Date: Sat Nov 28 2026 - 04:07:03 EST


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, accept only
indices 0 and 1, corresponding to the two connectors on the MateBook
E Go. This preserves the empty ACK and rejects invalid port 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 | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/platform/arm64/huawei-gaokun-ec.c
b/drivers/platform/arm64/huawei-gaokun-ec.c
index abf05e7ec..bfcf7563e 100644
--- a/drivers/platform/arm64/huawei-gaokun-ec.c
+++ b/drivers/platform/arm64/huawei-gaokun-ec.c
@@ -56,6 +56,7 @@ enum gaokun_ec_ucsi_cmd {
UCSI_DATA_READ,
};

+#define GAOKUN_UCSI_NUM_PORTS 2
#define UCSI_REG_SIZE 7

/*
@@ -458,10 +459,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 >= GAOKUN_UCSI_NUM_PORTS)
+ return -EINVAL;
+ data = BIT(port_id);
+ }

refill_req_byte(ec_req, &data);

--
2.53.0



On Sat, 28 Nov 2026 04:06:44 -0500, YoungJoon Lee <getfeus@xxxxxxxxx> wrote:
> These two fixes address short I2C transfers and PAN ACK mask
> construction in the Huawei MateBook E Go EC driver.
>
> Changes in v2:
> - Patch 1 is unchanged.
> - Patch 2 validates against the two physical connectors, as suggested
> by Pengyu Luo. The no-port-update sentinel still sends a zero mask.
>
> An I2C stub and UBSan verified the empty ACK, both valid masks,
> rejection of invalid indices without an I2C transfer, and short
> transfer handling. The series builds as an arm64 Image and EC module.
>
> OpenAI Codex assisted with source inspection, regression testing and
> drafting.
>
> Lee Youngjoon (2):
> platform: arm64: huawei-gaokun-ec: Reject short I2C transfers
> platform: arm64: huawei-gaokun-ec: Validate the PAN ACK bit index
>
> drivers/platform/arm64/huawei-gaokun-ec.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
>
> base-commit: d4000e7b99e06e92f21a3c92098a0476d316e9d6
> --
> 2.53.0