From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Pengpeng Hou <pengpeng@iscas.ac.cn>
Cc: Pengyu Luo <mitltlatltl@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] usb: typec: ucsi: gaokun: unwind notifier on UCSI register failure
Date: Tue, 23 Jun 2026 15:10:34 +0300 [thread overview]
Message-ID: <ajp3uoW7wkrYQwW6@kuha> (raw)
In-Reply-To: <20260622153230.75195-1-pengpeng@iscas.ac.cn>
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
prev parent reply other threads:[~2026-06-23 12:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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=ajp3uoW7wkrYQwW6@kuha \
--to=heikki.krogerus@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mitltlatltl@gmail.com \
--cc=pengpeng@iscas.ac.cn \
/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