lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAGp9Lzq+NQhguSoc5DE4kyUgi2uSNOkURuAeAFpGuizcaXUXew@mail.gmail.com>
Date:   Tue, 16 Mar 2021 13:05:44 +0800
From:   Sean Wang <sean.wang@...nel.org>
To:     Zhiyong Tao <zhiyong.tao@...iatek.com>
Cc:     Rob Herring <robh+dt@...nel.org>,
        Linus Walleij <linus.walleij@...aro.org>,
        Mark Rutland <mark.rutland@....com>,
        Matthias Brugger <matthias.bgg@...il.com>,
        srv_heupstream <srv_heupstream@...iatek.com>,
        hui.liu@...iatek.com,
        Eddie Huang (黃智傑) 
        <eddie.huang@...iatek.com>, jg_poxu@...iatek.com,
        Biao Huang <biao.huang@...iatek.com>,
        Hongzhou Yang <hongzhou.yang@...iatek.com>,
        Erin Lo (羅雅齡) <erin.lo@...iatek.com>,
        Sean Wang (王志亘) <sean.wang@...iatek.com>,
        seiya.wang@...iatek.com, sj.huang@...iatek.com,
        "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" 
        <devicetree@...r.kernel.org>, lkml <linux-kernel@...r.kernel.org>,
        linux-arm Mailing List <linux-arm-kernel@...ts.infradead.org>,
        "moderated list:ARM/Mediatek SoC support" 
        <linux-mediatek@...ts.infradead.org>,
        "open list:GPIO SUBSYSTEM" <linux-gpio@...r.kernel.org>
Subject: Re: [PATCH] pinctrl: add lock in mtk_rmw function.

Hi Zhiyong,

On Fri, Mar 12, 2021 at 2:35 PM Zhiyong Tao <zhiyong.tao@...iatek.com> wrote:
>
> When multiple threads operate on the same register resource
> which include multiple pin, It will make the register resource
> wrong to control. So we add lock to avoid the case.
>
> Signed-off-by: Zhiyong Tao <zhiyong.tao@...iatek.com>
> ---
>  drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c | 4 ++++
>  drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h | 2 ++
>  drivers/pinctrl/mediatek/pinctrl-paris.c         | 2 ++
>  3 files changed, 8 insertions(+)
>
> diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
> index 72f17f26acd8..fcf7c3eeee4a 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
> +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
> @@ -58,10 +58,14 @@ void mtk_rmw(struct mtk_pinctrl *pctl, u8 i, u32 reg, u32 mask, u32 set)
>  {
>         u32 val;
>
> +       mutex_lock(&pctl->lock);
> +
>         val = mtk_r32(pctl, i, reg);
>         val &= ~mask;
>         val |= set;
>         mtk_w32(pctl, i, reg, val);
> +
> +       mutex_unlock(&pctl->lock);
>  }
>
>  static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw,
> diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
> index e2aae285b5fc..65eac708a3b3 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
> +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
> @@ -251,6 +251,8 @@ struct mtk_pinctrl {
>         struct mtk_eint                 *eint;
>         struct mtk_pinctrl_group        *groups;
>         const char          **grp_names;
> +       /* lock pin's register resource to avoid multiple threads issue*/
> +       struct mutex lock;
>  };
>
>  void mtk_rmw(struct mtk_pinctrl *pctl, u8 i, u32 reg, u32 mask, u32 set);
> diff --git a/drivers/pinctrl/mediatek/pinctrl-paris.c b/drivers/pinctrl/mediatek/pinctrl-paris.c
> index da1f19288aa6..48e823f6d293 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-paris.c
> +++ b/drivers/pinctrl/mediatek/pinctrl-paris.c
> @@ -970,6 +970,8 @@ int mtk_paris_pinctrl_probe(struct platform_device *pdev,
>
>         hw->nbase = hw->soc->nbase_names;
>
> +       mutex_init(&hw->lock);
> +

Could you help add the mutex initialization into pinctrl-moore.c too?
and then the patch would look good to me.

>         err = mtk_pctrl_build_state(pdev);
>         if (err) {
>                 dev_err(&pdev->dev, "build state failed: %d\n", err);
> --
> 2.18.0
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ