Linux USB
 help / color / mirror / Atom feed
From: Lee Youngjoon <getfeus@gmail.com>
To: Pengyu Luo <mitltlatltl@gmail.com>,
	Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Hans de Goede" <hansg@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Bryan O'Donoghue" <bryan.odonoghue@linaro.org>,
	platform-driver-x86@vger.kernel.org, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH v5 1/3] usb: typec: ucsi: gaokun: Return connector numbers from refresh
Date: Sat,  5 Dec 2026 09:29:21 +0900	[thread overview]
Message-ID: <20261205002923.1370-2-getfeus@gmail.com> (raw)
In-Reply-To: <20261205002923.1370-1-getfeus@gmail.com>

The EC UCSI_REG_READ (0xd3) response contains a port count, an update
mask and per-port state. gaokun_ucsi_refresh() returns the same sentinel
for a failed read and for a successful read with an empty mask. The
caller sends an empty PAN acknowledgment in both cases.

Return a one-based connector number for a valid update. This leaves
zero for an empty mask and negative values for errors. Propagate a
negative read error, map a positive EC status to -EIO, and return
-ENODATA when the update names a port outside the reported range.
Only acknowledge an empty update when the read actually returned one.

Fixes: 00327d7f2c8c ("usb: typec: ucsi: add Huawei Matebook E Go ucsi driver")
Cc: stable@vger.kernel.org
Signed-off-by: Lee Youngjoon <getfeus@gmail.com>
---
 drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c | 25 ++++++++++++---------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c b/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c
index 56f8bbab9..8b322ec4a 100644
--- a/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c
+++ b/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c
@@ -273,6 +273,7 @@ static void gaokun_ucsi_port_update(struct gaokun_ucsi_port *port,
 	spin_unlock_irqrestore(&port->lock, flags);
 }
 
+/* Return a one-based connector number, zero for an empty mask, or an errno. */
 static int gaokun_ucsi_refresh(struct gaokun_ucsi *uec)
 {
 	struct gaokun_ucsi_reg ureg;
@@ -280,16 +281,18 @@ static int gaokun_ucsi_refresh(struct gaokun_ucsi *uec)
 
 	ret = gaokun_ec_ucsi_get_reg(uec->ec, &ureg);
 	if (ret)
-		return GAOKUN_UCSI_NO_PORT_UPDATE;
+		return ret < 0 ? ret : -EIO;
 
 	uec->num_ports = ureg.num_ports;
-	idx = GET_IDX(ureg.port_updt);
+	if (!ureg.port_updt)
+		return 0;
 
-	if (idx < 0 || idx >= ureg.num_ports)
-		return GAOKUN_UCSI_NO_PORT_UPDATE;
+	idx = GET_IDX(ureg.port_updt);
+	if (idx >= ureg.num_ports)
+		return -ENODATA;
 
 	gaokun_ucsi_port_update(&uec->ports[idx], ureg.port_data);
-	return idx;
+	return idx + 1;
 }
 
 static void gaokun_ucsi_handle_usb_mode(struct gaokun_ucsi_port *port)
@@ -326,18 +329,18 @@ static void gaokun_ucsi_handle_usb_mode(struct gaokun_ucsi_port *port)
 
 static void gaokun_ucsi_usb_notify_ind(struct gaokun_ucsi *uec)
 {
-	int idx;
+	int num;
 
 	if (!uec->ucsi->connector) { /* slow to register */
 		dev_err_ratelimited(uec->dev, "ucsi connector is not initialized yet\n");
 		return;
 	}
 
-	idx = gaokun_ucsi_refresh(uec);
-	if (idx == GAOKUN_UCSI_NO_PORT_UPDATE)
-		gaokun_ec_ucsi_pan_ack(uec->ec, idx); /* ack directly if no update */
-	else
-		gaokun_ucsi_handle_usb_mode(&uec->ports[idx]);
+	num = gaokun_ucsi_refresh(uec);
+	if (!num)
+		gaokun_ec_ucsi_pan_ack(uec->ec, GAOKUN_UCSI_NO_PORT_UPDATE);
+	else if (num > 0)
+		gaokun_ucsi_handle_usb_mode(&uec->ports[num - 1]);
 }
 
 /*
-- 
2.53.0


  reply	other threads:[~2026-12-05  1:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  0:29 [PATCH v5 0/3] usb: typec: ucsi: gaokun: Validate and defer port updates Lee Youngjoon
2026-12-05  0:29 ` Lee Youngjoon [this message]
2026-12-05  0:29 ` [PATCH v5 2/3] usb: typec: ucsi: gaokun: Validate port updates before acknowledging them Lee Youngjoon
2026-12-05  0:29 ` [PATCH v5 3/3] usb: typec: ucsi: gaokun: Defer missing USB events per connector Lee Youngjoon
2026-12-05  1:49 ` [PATCH v5 0/3] usb: typec: ucsi: gaokun: Validate and defer port updates sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261205002923.1370-2-getfeus@gmail.com \
    --to=getfeus@gmail.com \
    --cc=bryan.odonoghue@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hansg@kernel.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mitltlatltl@gmail.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox