lkml.org 
[lkml]   [2023]   [Oct]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH 03/11] firmware: qcom-scm: atomically assign and read the global __scm pointer
From


On 8/29/2023 12:54 AM, Bartosz Golaszewski wrote:
> Checking for the availability of SCM bridge can happen from any context.
> It's only by chance that we haven't run into concurrency issues but with
> the upcoming SHM Bridge driver that will be initiated at the same
> initcall level, we need to assure the assignment and readback of the
> __scm pointer is atomic.
>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> ---
> drivers/firmware/qcom_scm.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/firmware/qcom_scm.c b/drivers/firmware/qcom_scm.c
> index 980fcfa20b9f..422de70faff8 100644
> --- a/drivers/firmware/qcom_scm.c
> +++ b/drivers/firmware/qcom_scm.c
> @@ -1331,7 +1331,7 @@ static int qcom_scm_find_dload_address(struct device *dev, u64 *addr)
> */
> bool qcom_scm_is_available(void)
> {
> - return !!__scm;
> + return !!READ_ONCE(__scm);
> }
> EXPORT_SYMBOL(qcom_scm_is_available);
>
> @@ -1477,8 +1477,8 @@ static int qcom_scm_probe(struct platform_device *pdev)
> if (ret)
> return ret;
>
> - __scm = scm;
> - __scm->dev = &pdev->dev;
> + scm->dev = &pdev->dev;
> + WRITE_ONCE(__scm, scm);

In my opinion "__scm = scm;" assignment should be done at the end of
probe function success so that qcom_scm_is_available() return true only
when probe is completed.

Other changes may not be needed.

> init_completion(&__scm->waitq_comp);
>

\
 
 \ /
  Last update: 2023-10-17 10:26    [W:0.361 / U:0.096 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site