linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pwm: sun4i: Propagate errors in .get_state() to the caller
@ 2022-12-01 15:22 Andre Przywara
  2022-12-01 15:48 ` Uwe Kleine-König
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Andre Przywara @ 2022-12-01 15:22 UTC (permalink / raw)
  To: Thierry Reding, Uwe Kleine-König
  Cc: Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, linux-pwm,
	linux-arm-kernel, linux-sunxi

.get_state() can return an error indication now. Make use of it to
propagate an impossible prescaler encoding, should that have sneaked in
somehow.
Also check the return value of clk_get_rate(). That's unlikely to fail,
but we use that in two divide operations down in the code, so let's
avoid a divide-by-zero condition on the way.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
Hi,

this goes on top of Uwe's series to introduce and observe .get_state
failures: https://lore.kernel.org/linux-pwm/20221130152148.2769768-12-u.kleine-koenig@pengutronix.de/T/#m9af39aa03bbd9bb7b31b3600f110c65ee0e8e70b
Actually it only relies on patch 01/11 from that.

Cheers,
Andre

 drivers/pwm/pwm-sun4i.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c
index 37d75e252d4e..b973da73e9ab 100644
--- a/drivers/pwm/pwm-sun4i.c
+++ b/drivers/pwm/pwm-sun4i.c
@@ -118,6 +118,8 @@ static int sun4i_pwm_get_state(struct pwm_chip *chip,
 	unsigned int prescaler;
 
 	clk_rate = clk_get_rate(sun4i_pwm->clk);
+	if (!clk_rate)
+		return -EINVAL;
 
 	val = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);
 
@@ -142,7 +144,7 @@ static int sun4i_pwm_get_state(struct pwm_chip *chip,
 		prescaler = prescaler_table[PWM_REG_PRESCAL(val, pwm->hwpwm)];
 
 	if (prescaler == 0)
-		return 0;
+		return -EINVAL;
 
 	if (val & BIT_CH(PWM_ACT_STATE, pwm->hwpwm))
 		state->polarity = PWM_POLARITY_NORMAL;
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] pwm: sun4i: Propagate errors in .get_state() to the caller
  2022-12-01 15:22 [PATCH] pwm: sun4i: Propagate errors in .get_state() to the caller Andre Przywara
@ 2022-12-01 15:48 ` Uwe Kleine-König
  2022-12-02 23:37   ` Andre Przywara
  2022-12-03  1:56 ` Samuel Holland
  2022-12-03  9:50 ` Jernej Škrabec
  2 siblings, 1 reply; 5+ messages in thread
From: Uwe Kleine-König @ 2022-12-01 15:48 UTC (permalink / raw)
  To: Andre Przywara
  Cc: Thierry Reding, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
	linux-pwm, linux-arm-kernel, linux-sunxi


[-- Attachment #1.1: Type: text/plain, Size: 1359 bytes --]

On Thu, Dec 01, 2022 at 03:22:23PM +0000, Andre Przywara wrote:
> .get_state() can return an error indication now. Make use of it to
> propagate an impossible prescaler encoding, should that have sneaked in
> somehow.
> Also check the return value of clk_get_rate(). That's unlikely to fail,
> but we use that in two divide operations down in the code, so let's
> avoid a divide-by-zero condition on the way.
> 
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> ---
> Hi,
> 
> this goes on top of Uwe's series to introduce and observe .get_state
> failures: https://lore.kernel.org/linux-pwm/20221130152148.2769768-12-u.kleine-koenig@pengutronix.de/T/#m9af39aa03bbd9bb7b31b3600f110c65ee0e8e70b
> Actually it only relies on patch 01/11 from that.

I recommend to put this info in machine-readable form into your patch.
If you applied my patch #1 on v6.1-rc1 and this on top, you'd do

	git format-patch -1 --base v6.1-rc1

This results in two additional lines that the build bots can evaluate,
to find the right setup to test your patch.

Apart from that:

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

and thanks to pick up on this topic,
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] pwm: sun4i: Propagate errors in .get_state() to the caller
  2022-12-01 15:48 ` Uwe Kleine-König
@ 2022-12-02 23:37   ` Andre Przywara
  0 siblings, 0 replies; 5+ messages in thread
From: Andre Przywara @ 2022-12-02 23:37 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Thierry Reding, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
	linux-pwm, linux-arm-kernel, linux-sunxi

On Thu, 1 Dec 2022 16:48:22 +0100
Uwe Kleine-König <u.kleine-koenig@pengutronix.de> wrote:

> On Thu, Dec 01, 2022 at 03:22:23PM +0000, Andre Przywara wrote:
> > .get_state() can return an error indication now. Make use of it to
> > propagate an impossible prescaler encoding, should that have sneaked in
> > somehow.
> > Also check the return value of clk_get_rate(). That's unlikely to fail,
> > but we use that in two divide operations down in the code, so let's
> > avoid a divide-by-zero condition on the way.
> > 
> > Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> > ---
> > Hi,
> > 
> > this goes on top of Uwe's series to introduce and observe .get_state
> > failures: https://lore.kernel.org/linux-pwm/20221130152148.2769768-12-u.kleine-koenig@pengutronix.de/T/#m9af39aa03bbd9bb7b31b3600f110c65ee0e8e70b
> > Actually it only relies on patch 01/11 from that.  
> 
> I recommend to put this info in machine-readable form into your patch.
> If you applied my patch #1 on v6.1-rc1 and this on top, you'd do
> 
> 	git format-patch -1 --base v6.1-rc1
> 
> This results in two additional lines that the build bots can evaluate,
> to find the right setup to test your patch.

Ah, nice one, didn't know about that. And just went I wanted to
complain that this relies on public branches and committed patches, I
learned that it doesn't.

So I got:
base-commit: eb7081409f94a9a8608593d0fb63a1aa3d6f95d8
prerequisite-patch-id: 3022328f2919301d79d852ef148c3f9dc4d723d6

Do you want me to resend the patch with this information?

> Apart from that:
> 
> Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Thanks for that!

Cheers,
Andre

> 
> and thanks to pick up on this topic,
> Uwe
> 


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] pwm: sun4i: Propagate errors in .get_state() to the caller
  2022-12-01 15:22 [PATCH] pwm: sun4i: Propagate errors in .get_state() to the caller Andre Przywara
  2022-12-01 15:48 ` Uwe Kleine-König
@ 2022-12-03  1:56 ` Samuel Holland
  2022-12-03  9:50 ` Jernej Škrabec
  2 siblings, 0 replies; 5+ messages in thread
From: Samuel Holland @ 2022-12-03  1:56 UTC (permalink / raw)
  To: Andre Przywara, Thierry Reding, Uwe Kleine-König
  Cc: Chen-Yu Tsai, Jernej Skrabec, linux-pwm, linux-arm-kernel, linux-sunxi

On 12/1/22 09:22, Andre Przywara wrote:
> .get_state() can return an error indication now. Make use of it to
> propagate an impossible prescaler encoding, should that have sneaked in
> somehow.
> Also check the return value of clk_get_rate(). That's unlikely to fail,
> but we use that in two divide operations down in the code, so let's
> avoid a divide-by-zero condition on the way.
> 
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> ---
> Hi,
> 
> this goes on top of Uwe's series to introduce and observe .get_state
> failures: https://lore.kernel.org/linux-pwm/20221130152148.2769768-12-u.kleine-koenig@pengutronix.de/T/#m9af39aa03bbd9bb7b31b3600f110c65ee0e8e70b
> Actually it only relies on patch 01/11 from that.
> 
> Cheers,
> Andre
> 
>  drivers/pwm/pwm-sun4i.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Reviewed-by: Samuel Holland <samuel@sholland.org>


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] pwm: sun4i: Propagate errors in .get_state() to the caller
  2022-12-01 15:22 [PATCH] pwm: sun4i: Propagate errors in .get_state() to the caller Andre Przywara
  2022-12-01 15:48 ` Uwe Kleine-König
  2022-12-03  1:56 ` Samuel Holland
@ 2022-12-03  9:50 ` Jernej Škrabec
  2 siblings, 0 replies; 5+ messages in thread
From: Jernej Škrabec @ 2022-12-03  9:50 UTC (permalink / raw)
  To: Thierry Reding, Uwe Kleine-König, Andre Przywara
  Cc: Chen-Yu Tsai, Samuel Holland, linux-pwm, linux-arm-kernel, linux-sunxi

Dne četrtek, 01. december 2022 ob 16:22:23 CET je Andre Przywara napisal(a):
> .get_state() can return an error indication now. Make use of it to
> propagate an impossible prescaler encoding, should that have sneaked in
> somehow.
> Also check the return value of clk_get_rate(). That's unlikely to fail,
> but we use that in two divide operations down in the code, so let's
> avoid a divide-by-zero condition on the way.
> 
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>

Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>

Best regards,
Jernej



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-12-03  9:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-01 15:22 [PATCH] pwm: sun4i: Propagate errors in .get_state() to the caller Andre Przywara
2022-12-01 15:48 ` Uwe Kleine-König
2022-12-02 23:37   ` Andre Przywara
2022-12-03  1:56 ` Samuel Holland
2022-12-03  9:50 ` Jernej Škrabec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).