2024-04-03 03:11:18

by Dmitry Baryshkov

[permalink] [raw]
Subject: [PATCH v2 1/2] soc: qcom: pmic_glink: don't traverse clients list without a lock

Take the client_lock before traversing the clients list at the
pmic_glink_state_notify_clients() function. This is required to keep the
list traversal safe from concurrent modification.

Fixes: 58ef4ece1e41 ("soc: qcom: pmic_glink: Introduce base PMIC GLINK driver")
Signed-off-by: Dmitry Baryshkov <[email protected]>
---
drivers/soc/qcom/pmic_glink.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/soc/qcom/pmic_glink.c b/drivers/soc/qcom/pmic_glink.c
index f913e9bd57ed..2b2cdf479654 100644
--- a/drivers/soc/qcom/pmic_glink.c
+++ b/drivers/soc/qcom/pmic_glink.c
@@ -115,10 +115,12 @@ static int pmic_glink_rpmsg_callback(struct rpmsg_device *rpdev, void *data,

hdr = data;

+ mutex_lock(&pg->client_lock);
list_for_each_entry(client, &pg->clients, node) {
if (client->id == le32_to_cpu(hdr->owner))
client->cb(data, len, client->priv);
}
+ mutex_unlock(&pg->client_lock);

return 0;
}
@@ -168,8 +170,10 @@ static void pmic_glink_state_notify_clients(struct pmic_glink *pg)
}

if (new_state != pg->client_state) {
+ mutex_lock(&pg->client_lock);
list_for_each_entry(client, &pg->clients, node)
client->pdr_notify(client->priv, new_state);
+ mutex_unlock(&pg->client_lock);
pg->client_state = new_state;
}
}

--
2.39.2



2024-04-03 15:23:17

by Andrew Halaney

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] soc: qcom: pmic_glink: don't traverse clients list without a lock

On Wed, Apr 03, 2024 at 06:10:57AM +0300, Dmitry Baryshkov wrote:
> Take the client_lock before traversing the clients list at the
> pmic_glink_state_notify_clients() function. This is required to keep the
> list traversal safe from concurrent modification.
>
> Fixes: 58ef4ece1e41 ("soc: qcom: pmic_glink: Introduce base PMIC GLINK driver")

Reviewed-by: Andrew Halaney <[email protected]>

> Signed-off-by: Dmitry Baryshkov <[email protected]>
> ---
> drivers/soc/qcom/pmic_glink.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/soc/qcom/pmic_glink.c b/drivers/soc/qcom/pmic_glink.c
> index f913e9bd57ed..2b2cdf479654 100644
> --- a/drivers/soc/qcom/pmic_glink.c
> +++ b/drivers/soc/qcom/pmic_glink.c
> @@ -115,10 +115,12 @@ static int pmic_glink_rpmsg_callback(struct rpmsg_device *rpdev, void *data,
>
> hdr = data;
>
> + mutex_lock(&pg->client_lock);
> list_for_each_entry(client, &pg->clients, node) {
> if (client->id == le32_to_cpu(hdr->owner))
> client->cb(data, len, client->priv);
> }
> + mutex_unlock(&pg->client_lock);
>
> return 0;
> }
> @@ -168,8 +170,10 @@ static void pmic_glink_state_notify_clients(struct pmic_glink *pg)
> }
>
> if (new_state != pg->client_state) {
> + mutex_lock(&pg->client_lock);
> list_for_each_entry(client, &pg->clients, node)
> client->pdr_notify(client->priv, new_state);
> + mutex_unlock(&pg->client_lock);
> pg->client_state = new_state;
> }
> }
>
> --
> 2.39.2
>
>


2024-04-05 16:58:30

by Mukesh Ojha

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] soc: qcom: pmic_glink: don't traverse clients list without a lock



On 4/3/2024 8:40 AM, Dmitry Baryshkov wrote:
> Take the client_lock before traversing the clients list at the
> pmic_glink_state_notify_clients() function. This is required to keep the
> list traversal safe from concurrent modification.
>
> Fixes: 58ef4ece1e41 ("soc: qcom: pmic_glink: Introduce base PMIC GLINK driver")
> Signed-off-by: Dmitry Baryshkov <[email protected]>

Nice catch.

Reviewed-by: Mukesh Ojha <[email protected]>

-Mukesh