* [PATCH v2] usb: typec: ucsi: gaokun: unwind notifier on UCSI register failure
@ 2026-06-22 15:32 Pengpeng Hou
2026-06-23 12:10 ` Heikki Krogerus
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Pengpeng Hou @ 2026-06-22 15:32 UTC (permalink / raw)
To: Pengyu Luo, Heikki Krogerus, Greg Kroah-Hartman
Cc: linux-usb, linux-kernel, pengpeng
gaokun_ucsi_register_worker() registers the EC notifier before calling
ucsi_register(). If ucsi_register() fails, the worker currently only logs
the error and leaves the notifier registered. Later EC events can then
call into an unpublished UCSI instance. The remove path also
unconditionally unregisters the notifier and UCSI device even if the
delayed worker failed before both were published.
Unregister the notifier immediately when ucsi_register() fails, and track
only the fully published state. The remove path then tears down the pair
only if both publication steps completed.
Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
---
Changes since v1:
- Drop the two-flag bookkeeping objected to by Greg Kroah-Hartman.
- Keep the existing registration order, but use a single flag that is set
only after both the notifier and UCSI device are published.
- Unregister the EC notifier immediately if ucsi_register() fails.
- Compile-tested only; no Gaokun hardware was available.
drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c b/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c
index ca749fde49bd..0dcbbff5f205 100644
--- a/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c
+++ b/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c
@@ -98,6 +98,7 @@ struct gaokun_ucsi {
struct device *dev;
struct delayed_work work;
struct notifier_block nb;
+ bool registered;
u16 version;
u8 num_ports;
};
@@ -457,8 +458,12 @@ static void gaokun_ucsi_register_worker(struct work_struct *work)
}
ret = ucsi_register(ucsi);
- if (ret)
+ if (ret) {
dev_err_probe(ucsi->dev, ret, "ucsi register failed\n");
+ gaokun_ec_unregister_notify(uec->ec, &uec->nb);
+ return;
+ }
+ uec->registered = true;
}
static int gaokun_ucsi_probe(struct auxiliary_device *adev,
@@ -504,8 +509,10 @@ static void gaokun_ucsi_remove(struct auxiliary_device *adev)
struct gaokun_ucsi *uec = auxiliary_get_drvdata(adev);
disable_delayed_work_sync(&uec->work);
- gaokun_ec_unregister_notify(uec->ec, &uec->nb);
- ucsi_unregister(uec->ucsi);
+ if (uec->registered) {
+ gaokun_ec_unregister_notify(uec->ec, &uec->nb);
+ ucsi_unregister(uec->ucsi);
+ }
ucsi_destroy(uec->ucsi);
}
--
2.50.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] usb: typec: ucsi: gaokun: unwind notifier on UCSI register failure
2026-06-22 15:32 [PATCH v2] usb: typec: ucsi: gaokun: unwind notifier on UCSI register failure Pengpeng Hou
@ 2026-06-23 12:10 ` Heikki Krogerus
2026-06-27 5:33 ` Pengyu Luo
2026-07-08 12:10 ` Greg Kroah-Hartman
2 siblings, 0 replies; 4+ messages in thread
From: Heikki Krogerus @ 2026-06-23 12:10 UTC (permalink / raw)
To: Pengpeng Hou; +Cc: Pengyu Luo, Greg Kroah-Hartman, linux-usb, linux-kernel
On Mon, Jun 22, 2026 at 11:32:30PM +0800, Pengpeng Hou wrote:
> gaokun_ucsi_register_worker() registers the EC notifier before calling
> ucsi_register(). If ucsi_register() fails, the worker currently only logs
> the error and leaves the notifier registered. Later EC events can then
> call into an unpublished UCSI instance. The remove path also
> unconditionally unregisters the notifier and UCSI device even if the
> delayed worker failed before both were published.
>
> Unregister the notifier immediately when ucsi_register() fails, and track
> only the fully published state. The remove path then tears down the pair
> only if both publication steps completed.
>
> Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
> Changes since v1:
> - Drop the two-flag bookkeeping objected to by Greg Kroah-Hartman.
> - Keep the existing registration order, but use a single flag that is set
> only after both the notifier and UCSI device are published.
> - Unregister the EC notifier immediately if ucsi_register() fails.
> - Compile-tested only; no Gaokun hardware was available.
>
> drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c | 13 ++++++++++---
> 1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c b/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c
> index ca749fde49bd..0dcbbff5f205 100644
> --- a/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c
> +++ b/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c
> @@ -98,6 +98,7 @@ struct gaokun_ucsi {
> struct device *dev;
> struct delayed_work work;
> struct notifier_block nb;
> + bool registered;
> u16 version;
> u8 num_ports;
> };
> @@ -457,8 +458,12 @@ static void gaokun_ucsi_register_worker(struct work_struct *work)
> }
>
> ret = ucsi_register(ucsi);
> - if (ret)
> + if (ret) {
> dev_err_probe(ucsi->dev, ret, "ucsi register failed\n");
> + gaokun_ec_unregister_notify(uec->ec, &uec->nb);
> + return;
> + }
> + uec->registered = true;
> }
>
> static int gaokun_ucsi_probe(struct auxiliary_device *adev,
> @@ -504,8 +509,10 @@ static void gaokun_ucsi_remove(struct auxiliary_device *adev)
> struct gaokun_ucsi *uec = auxiliary_get_drvdata(adev);
>
> disable_delayed_work_sync(&uec->work);
> - gaokun_ec_unregister_notify(uec->ec, &uec->nb);
> - ucsi_unregister(uec->ucsi);
> + if (uec->registered) {
> + gaokun_ec_unregister_notify(uec->ec, &uec->nb);
> + ucsi_unregister(uec->ucsi);
> + }
> ucsi_destroy(uec->ucsi);
> }
>
> --
> 2.50.1
--
heikki
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] usb: typec: ucsi: gaokun: unwind notifier on UCSI register failure
2026-06-22 15:32 [PATCH v2] usb: typec: ucsi: gaokun: unwind notifier on UCSI register failure Pengpeng Hou
2026-06-23 12:10 ` Heikki Krogerus
@ 2026-06-27 5:33 ` Pengyu Luo
2026-07-08 12:10 ` Greg Kroah-Hartman
2 siblings, 0 replies; 4+ messages in thread
From: Pengyu Luo @ 2026-06-27 5:33 UTC (permalink / raw)
To: Pengpeng Hou; +Cc: Heikki Krogerus, Greg Kroah-Hartman, linux-usb, linux-kernel
On Mon, Jun 22, 2026 at 11:32 PM Pengpeng Hou <pengpeng@iscas.ac.cn> wrote:
>
> gaokun_ucsi_register_worker() registers the EC notifier before calling
> ucsi_register(). If ucsi_register() fails, the worker currently only logs
> the error and leaves the notifier registered. Later EC events can then
> call into an unpublished UCSI instance. The remove path also
> unconditionally unregisters the notifier and UCSI device even if the
> delayed worker failed before both were published.
>
> Unregister the notifier immediately when ucsi_register() fails, and track
> only the fully published state. The remove path then tears down the pair
> only if both publication steps completed.
>
> Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
This makes things clearer.
Reviewed-by: Pengyu Luo <mitltlatltl@gmail.com>
FWIW, ucsi_register() would never fail since we hardcoded the ucsi
version, but nowadays ucsi init work is still a question. (failed to
register alt modes occasionally)
Best wishes,
Pengyu
> ---
> Changes since v1:
> - Drop the two-flag bookkeeping objected to by Greg Kroah-Hartman.
> - Keep the existing registration order, but use a single flag that is set
> only after both the notifier and UCSI device are published.
> - Unregister the EC notifier immediately if ucsi_register() fails.
> - Compile-tested only; no Gaokun hardware was available.
>
> drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c | 13 ++++++++++---
> 1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c b/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c
> index ca749fde49bd..0dcbbff5f205 100644
> --- a/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c
> +++ b/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c
> @@ -98,6 +98,7 @@ struct gaokun_ucsi {
> struct device *dev;
> struct delayed_work work;
> struct notifier_block nb;
> + bool registered;
> u16 version;
> u8 num_ports;
> };
> @@ -457,8 +458,12 @@ static void gaokun_ucsi_register_worker(struct work_struct *work)
> }
>
> ret = ucsi_register(ucsi);
> - if (ret)
> + if (ret) {
> dev_err_probe(ucsi->dev, ret, "ucsi register failed\n");
> + gaokun_ec_unregister_notify(uec->ec, &uec->nb);
> + return;
> + }
> + uec->registered = true;
> }
>
> static int gaokun_ucsi_probe(struct auxiliary_device *adev,
> @@ -504,8 +509,10 @@ static void gaokun_ucsi_remove(struct auxiliary_device *adev)
> struct gaokun_ucsi *uec = auxiliary_get_drvdata(adev);
>
> disable_delayed_work_sync(&uec->work);
> - gaokun_ec_unregister_notify(uec->ec, &uec->nb);
> - ucsi_unregister(uec->ucsi);
> + if (uec->registered) {
> + gaokun_ec_unregister_notify(uec->ec, &uec->nb);
> + ucsi_unregister(uec->ucsi);
> + }
> ucsi_destroy(uec->ucsi);
> }
>
> --
> 2.50.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] usb: typec: ucsi: gaokun: unwind notifier on UCSI register failure
2026-06-22 15:32 [PATCH v2] usb: typec: ucsi: gaokun: unwind notifier on UCSI register failure Pengpeng Hou
2026-06-23 12:10 ` Heikki Krogerus
2026-06-27 5:33 ` Pengyu Luo
@ 2026-07-08 12:10 ` Greg Kroah-Hartman
2 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2026-07-08 12:10 UTC (permalink / raw)
To: Pengpeng Hou; +Cc: Pengyu Luo, Heikki Krogerus, linux-usb, linux-kernel
On Mon, Jun 22, 2026 at 11:32:30PM +0800, Pengpeng Hou wrote:
> gaokun_ucsi_register_worker() registers the EC notifier before calling
> ucsi_register(). If ucsi_register() fails, the worker currently only logs
> the error and leaves the notifier registered. Later EC events can then
> call into an unpublished UCSI instance. The remove path also
> unconditionally unregisters the notifier and UCSI device even if the
> delayed worker failed before both were published.
>
> Unregister the notifier immediately when ucsi_register() fails, and track
> only the fully published state. The remove path then tears down the pair
> only if both publication steps completed.
>
> Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
> ---
> Changes since v1:
> - Drop the two-flag bookkeeping objected to by Greg Kroah-Hartman.
> - Keep the existing registration order, but use a single flag that is set
> only after both the notifier and UCSI device are published.
> - Unregister the EC notifier immediately if ucsi_register() fails.
> - Compile-tested only; no Gaokun hardware was available.
Does not apply against 7.2-rc2 :(
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-08 12:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-22 15:32 [PATCH v2] usb: typec: ucsi: gaokun: unwind notifier on UCSI register failure Pengpeng Hou
2026-06-23 12:10 ` Heikki Krogerus
2026-06-27 5:33 ` Pengyu Luo
2026-07-08 12:10 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox