diff mbox series

[v2] pwm: mtk_disp: Fix the disable flow of disp_pwm

Message ID 20230518115258.14320-1-shuijing.li@mediatek.com (mailing list archive)
State New, archived
Headers show
Series [v2] pwm: mtk_disp: Fix the disable flow of disp_pwm | expand

Commit Message

Shuijing Li May 18, 2023, 11:52 a.m. UTC
There is a flow error in the original mtk_disp_pwm_apply() function.
If this function is called when the clock is disabled, there will be a
chance to operate the disp_pwm register, resulting in disp_pwm exception.
Fix this accordingly.

Signed-off-by: Shuijing Li <shuijing.li@mediatek.com>
---
Changes in v2:
Use
if (A && B) {
	something();
}
instead of
if (A) {
	if (B) {
		something();
	}
}
per suggestion from the previous thread:
https://lore.kernel.org/lkml/20230515140346.bxeu6xewi6a446nd@pengutronix.de/
---
 drivers/pwm/pwm-mtk-disp.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

Comments

Matthias Brugger May 29, 2023, 10:43 a.m. UTC | #1
On 18/05/2023 13:52, Shuijing Li wrote:
> There is a flow error in the original mtk_disp_pwm_apply() function.
> If this function is called when the clock is disabled, there will be a
> chance to operate the disp_pwm register, resulting in disp_pwm exception.
> Fix this accordingly.
> 
> Signed-off-by: Shuijing Li <shuijing.li@mediatek.com>

We are missing a fixes tag here.
Fixes: 888a623db5d0 ("pwm: mtk-disp: Implement atomic API .apply()")


with that:
Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com>

> ---
> Changes in v2:
> Use
> if (A && B) {
> 	something();
> }
> instead of
> if (A) {
> 	if (B) {
> 		something();
> 	}
> }
> per suggestion from the previous thread:
> https://lore.kernel.org/lkml/20230515140346.bxeu6xewi6a446nd@pengutronix.de/
> ---
>   drivers/pwm/pwm-mtk-disp.c | 13 +++++--------
>   1 file changed, 5 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-mtk-disp.c b/drivers/pwm/pwm-mtk-disp.c
> index 79e321e96f56..2401b6733241 100644
> --- a/drivers/pwm/pwm-mtk-disp.c
> +++ b/drivers/pwm/pwm-mtk-disp.c
> @@ -79,14 +79,11 @@ static int mtk_disp_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
>   	if (state->polarity != PWM_POLARITY_NORMAL)
>   		return -EINVAL;
>   
> -	if (!state->enabled) {
> -		mtk_disp_pwm_update_bits(mdp, DISP_PWM_EN, mdp->data->enable_mask,
> -					 0x0);
> -
> -		if (mdp->enabled) {
> -			clk_disable_unprepare(mdp->clk_mm);
> -			clk_disable_unprepare(mdp->clk_main);
> -		}
> +	if (!state->enabled && mdp->enabled) {
> +		mtk_disp_pwm_update_bits(mdp, DISP_PWM_EN,
> +					 mdp->data->enable_mask, 0x0);
> +		clk_disable_unprepare(mdp->clk_mm);
> +		clk_disable_unprepare(mdp->clk_main);
>   
>   		mdp->enabled = false;
>   		return 0;
Fei Shao May 30, 2023, 8:28 a.m. UTC | #2
On Mon, May 29, 2023 at 6:43 PM Matthias Brugger <matthias.bgg@gmail.com> wrote:
>
>
>
> On 18/05/2023 13:52, Shuijing Li wrote:
> > There is a flow error in the original mtk_disp_pwm_apply() function.
> > If this function is called when the clock is disabled, there will be a
> > chance to operate the disp_pwm register, resulting in disp_pwm exception.
> > Fix this accordingly.
> >
> > Signed-off-by: Shuijing Li <shuijing.li@mediatek.com>
>
> We are missing a fixes tag here.
> Fixes: 888a623db5d0 ("pwm: mtk-disp: Implement atomic API .apply()")
>
>
> with that:
> Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com>

Tested-by: Fei Shao <fshao@chromium.org>

>
> > ---
> > Changes in v2:
> > Use
> > if (A && B) {
> >       something();
> > }
> > instead of
> > if (A) {
> >       if (B) {
> >               something();
> >       }
> > }
> > per suggestion from the previous thread:
> > https://lore.kernel.org/lkml/20230515140346.bxeu6xewi6a446nd@pengutronix.de/
> > ---
> >   drivers/pwm/pwm-mtk-disp.c | 13 +++++--------
> >   1 file changed, 5 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/pwm/pwm-mtk-disp.c b/drivers/pwm/pwm-mtk-disp.c
> > index 79e321e96f56..2401b6733241 100644
> > --- a/drivers/pwm/pwm-mtk-disp.c
> > +++ b/drivers/pwm/pwm-mtk-disp.c
> > @@ -79,14 +79,11 @@ static int mtk_disp_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
> >       if (state->polarity != PWM_POLARITY_NORMAL)
> >               return -EINVAL;
> >
> > -     if (!state->enabled) {
> > -             mtk_disp_pwm_update_bits(mdp, DISP_PWM_EN, mdp->data->enable_mask,
> > -                                      0x0);
> > -
> > -             if (mdp->enabled) {
> > -                     clk_disable_unprepare(mdp->clk_mm);
> > -                     clk_disable_unprepare(mdp->clk_main);
> > -             }
> > +     if (!state->enabled && mdp->enabled) {
> > +             mtk_disp_pwm_update_bits(mdp, DISP_PWM_EN,
> > +                                      mdp->data->enable_mask, 0x0);
> > +             clk_disable_unprepare(mdp->clk_mm);
> > +             clk_disable_unprepare(mdp->clk_main);
> >
> >               mdp->enabled = false;
> >               return 0;
>
Uwe Kleine-König June 14, 2023, 9:01 a.m. UTC | #3
On Thu, May 18, 2023 at 07:52:58PM +0800, Shuijing Li wrote:
> There is a flow error in the original mtk_disp_pwm_apply() function.
> If this function is called when the clock is disabled, there will be a
> chance to operate the disp_pwm register, resulting in disp_pwm exception.
> Fix this accordingly.
> 
> Signed-off-by: Shuijing Li <shuijing.li@mediatek.com>

Acked-by: Uwe Kleine-König <u.kleine-kleine@pengutronix.de>

Best regards
Uwe
diff mbox series

Patch

diff --git a/drivers/pwm/pwm-mtk-disp.c b/drivers/pwm/pwm-mtk-disp.c
index 79e321e96f56..2401b6733241 100644
--- a/drivers/pwm/pwm-mtk-disp.c
+++ b/drivers/pwm/pwm-mtk-disp.c
@@ -79,14 +79,11 @@  static int mtk_disp_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
 	if (state->polarity != PWM_POLARITY_NORMAL)
 		return -EINVAL;
 
-	if (!state->enabled) {
-		mtk_disp_pwm_update_bits(mdp, DISP_PWM_EN, mdp->data->enable_mask,
-					 0x0);
-
-		if (mdp->enabled) {
-			clk_disable_unprepare(mdp->clk_mm);
-			clk_disable_unprepare(mdp->clk_main);
-		}
+	if (!state->enabled && mdp->enabled) {
+		mtk_disp_pwm_update_bits(mdp, DISP_PWM_EN,
+					 mdp->data->enable_mask, 0x0);
+		clk_disable_unprepare(mdp->clk_mm);
+		clk_disable_unprepare(mdp->clk_main);
 
 		mdp->enabled = false;
 		return 0;