From: Johan Hovold <johan@kernel.org>
To: Bjorn Andersson <quic_bjorande@quicinc.com>
Cc: linux-arm-msm@vger.kernel.org
Subject: Re: [PATCH v3 1/3] soc: qcom: pmic_glink: Fix race during initialization
Date: Wed, 21 Aug 2024 08:52:42 +0200 [thread overview]
Message-ID: <ZsWOujOQsJtLcVf-@hovoldconsulting.com> (raw)
In-Reply-To: <20240820-pmic-glink-v6-11-races-v3-1-eec53c750a04@quicinc.com>
On Tue, Aug 20, 2024 at 01:29:30PM -0700, Bjorn Andersson wrote:
> As pointed out by Stephen Boyd it is possible that during initialization
> of the pmic_glink child drivers, the protection-domain notifiers fires,
> and the associated work is scheduled, before the client registration
> returns and as a result the local "client" pointer has been initialized.
>
> The outcome of this is a NULL pointer dereference as the "client"
> pointer is blindly dereferenced.
> Resolve this by splitting the allocation of the "client" object and the
> registration thereof into two operations.
It seems something went wrong when you posted v3 (using b4 automagic?)
so the cover letter and changelog is now missing and no one is on CC any
more.
Patches look good, though, with the exception of one nit below.
> diff --git a/drivers/power/supply/qcom_battmgr.c b/drivers/power/supply/qcom_battmgr.c
> index 49bef4a5ac3f..07758ab6ac1c 100644
> --- a/drivers/power/supply/qcom_battmgr.c
> +++ b/drivers/power/supply/qcom_battmgr.c
> @@ -1387,12 +1387,16 @@ static int qcom_battmgr_probe(struct auxiliary_device *adev,
> "failed to register wireless charing power supply\n");
> }
>
> - battmgr->client = devm_pmic_glink_register_client(dev,
> - PMIC_GLINK_OWNER_BATTMGR,
> - qcom_battmgr_callback,
> - qcom_battmgr_pdr_notify,
> - battmgr);
> - return PTR_ERR_OR_ZERO(battmgr->client);
> + battmgr->client = devm_pmic_glink_client_alloc(dev, PMIC_GLINK_OWNER_BATTMGR,
> + qcom_battmgr_callback,
> + qcom_battmgr_pdr_notify,
> + battmgr);
I'm not a fan of open-parenthesis alignment of arguments, but since this
driver uses it you need to adjust the alignment to the new symbol name
in v3.
> + if (IS_ERR(battmgr->client))
> + return PTR_ERR(battmgr->client);
> +
> + pmic_glink_client_register(battmgr->client);
> +
> + return 0;
> }
> diff --git a/drivers/soc/qcom/pmic_glink_altmode.c b/drivers/soc/qcom/pmic_glink_altmode.c
> index 1e0808b3cb93..c6f3d5188fc6 100644
> --- a/drivers/soc/qcom/pmic_glink_altmode.c
> +++ b/drivers/soc/qcom/pmic_glink_altmode.c
> @@ -520,12 +520,17 @@ static int pmic_glink_altmode_probe(struct auxiliary_device *adev,
> return ret;
> }
>
> - altmode->client = devm_pmic_glink_register_client(dev,
> - altmode->owner_id,
> - pmic_glink_altmode_callback,
> - pmic_glink_altmode_pdr_notify,
> - altmode);
> - return PTR_ERR_OR_ZERO(altmode->client);
> + altmode->client = devm_pmic_glink_client_alloc(dev,
> + altmode->owner_id,
> + pmic_glink_altmode_callback,
> + pmic_glink_altmode_pdr_notify,
> + altmode);
Same here.
> diff --git a/drivers/usb/typec/ucsi/ucsi_glink.c b/drivers/usb/typec/ucsi/ucsi_glink.c
> index 16c328497e0b..6425904f2bfc 100644
> --- a/drivers/usb/typec/ucsi/ucsi_glink.c
> +++ b/drivers/usb/typec/ucsi/ucsi_glink.c
> @@ -367,12 +367,16 @@ static int pmic_glink_ucsi_probe(struct auxiliary_device *adev,
> ucsi->port_orientation[port] = desc;
> }
>
> - ucsi->client = devm_pmic_glink_register_client(dev,
> - PMIC_GLINK_OWNER_USBC,
> - pmic_glink_ucsi_callback,
> - pmic_glink_ucsi_pdr_notify,
> - ucsi);
> - return PTR_ERR_OR_ZERO(ucsi->client);
> + ucsi->client = devm_pmic_glink_client_alloc(dev, PMIC_GLINK_OWNER_USBC,
> + pmic_glink_ucsi_callback,
> + pmic_glink_ucsi_pdr_notify,
> + ucsi);
And here.
> + if (IS_ERR(ucsi->client))
> + return PTR_ERR(ucsi->client);
> +
> + pmic_glink_client_register(ucsi->client);
> +
> + return 0;
> }
>
> static void pmic_glink_ucsi_remove(struct auxiliary_device *adev)
> diff --git a/include/linux/soc/qcom/pmic_glink.h b/include/linux/soc/qcom/pmic_glink.h
> index fd124aa18c81..4c68385b2765 100644
> --- a/include/linux/soc/qcom/pmic_glink.h
> +++ b/include/linux/soc/qcom/pmic_glink.h
> @@ -23,10 +23,11 @@ struct pmic_glink_hdr {
>
> int pmic_glink_send(struct pmic_glink_client *client, void *data, size_t len);
>
> -struct pmic_glink_client *devm_pmic_glink_register_client(struct device *dev,
> - unsigned int id,
> - void (*cb)(const void *, size_t, void *),
> - void (*pdr)(void *, int),
> - void *priv);
> +struct pmic_glink_client *devm_pmic_glink_client_alloc(struct device *dev,
> + unsigned int id,
> + void (*cb)(const void *, size_t, void *),
> + void (*pdr)(void *, int),
> + void *priv);
And here.
Johan
next prev parent reply other threads:[~2024-08-21 6:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-20 20:29 [PATCH v3 0/3] soc: qcom: pmic_glink: v6.11-rc bug fixes Bjorn Andersson
2024-08-20 20:29 ` [PATCH v3 1/3] soc: qcom: pmic_glink: Fix race during initialization Bjorn Andersson
2024-08-21 6:52 ` Johan Hovold [this message]
2024-08-20 20:29 ` [PATCH v3 2/3] usb: typec: ucsi: Move unregister out of atomic section Bjorn Andersson
2024-08-20 20:29 ` [PATCH v3 3/3] soc: qcom: pmic_glink: Actually communicate when remote goes down Bjorn Andersson
2024-08-20 22:12 ` [PATCH v3 0/3] soc: qcom: pmic_glink: v6.11-rc bug fixes Bjorn Andersson
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=ZsWOujOQsJtLcVf-@hovoldconsulting.com \
--to=johan@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=quic_bjorande@quicinc.com \
/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