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

From: Lee Youngjoon

Date: Thu Nov 26 2026 - 02:08:16 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, 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)
+ return -EINVAL;
+ data = BIT(port_id);
+ }

refill_req_byte(ec_req, &data);