linux-pwm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pwm: pwm-meson: fix handling of period/duty if greater than UINT_MAX
@ 2023-05-03 19:58 Heiner Kallweit
  2023-05-03 20:24 ` Uwe Kleine-König
  2023-05-08 19:46 ` Martin Blumenstingl
  0 siblings, 2 replies; 6+ messages in thread
From: Heiner Kallweit @ 2023-05-03 19:58 UTC (permalink / raw)
  To: Jerome Brunet, Martin Blumenstingl, Neil Armstrong, Kevin Hilman,
	Uwe Kleine-König, thierry.reding
  Cc: linux-arm-kernel, open list:ARM/Amlogic Meson..., linux-pwm

state->period/duty are of type u64, and if their value is greater than
UINT_MAX, then the cast to uint will cause problems. Fix this by
changing the type of the respective local variables to u64.

Fixes: b79c3670e120 ("pwm: meson: Don't duplicate the polarity internally")
Cc: stable@vger.kernel.org
Suggested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/pwm/pwm-meson.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c
index 3865538dd..33107204a 100644
--- a/drivers/pwm/pwm-meson.c
+++ b/drivers/pwm/pwm-meson.c
@@ -156,8 +156,9 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm,
 			  const struct pwm_state *state)
 {
 	struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm];
-	unsigned int duty, period, pre_div, cnt, duty_cnt;
+	unsigned int pre_div, cnt, duty_cnt;
 	unsigned long fin_freq;
+	u64 duty, period;
 
 	duty = state->duty_cycle;
 	period = state->period;
@@ -179,19 +180,19 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm,
 
 	dev_dbg(meson->chip.dev, "fin_freq: %lu Hz\n", fin_freq);
 
-	pre_div = div64_u64(fin_freq * (u64)period, NSEC_PER_SEC * 0xffffLL);
+	pre_div = div64_u64(fin_freq * period, NSEC_PER_SEC * 0xffffLL);
 	if (pre_div > MISC_CLK_DIV_MASK) {
 		dev_err(meson->chip.dev, "unable to get period pre_div\n");
 		return -EINVAL;
 	}
 
-	cnt = div64_u64(fin_freq * (u64)period, NSEC_PER_SEC * (pre_div + 1));
+	cnt = div64_u64(fin_freq * period, NSEC_PER_SEC * (pre_div + 1));
 	if (cnt > 0xffff) {
 		dev_err(meson->chip.dev, "unable to get period cnt\n");
 		return -EINVAL;
 	}
 
-	dev_dbg(meson->chip.dev, "period=%u pre_div=%u cnt=%u\n", period,
+	dev_dbg(meson->chip.dev, "period=%llu pre_div=%u cnt=%u\n", period,
 		pre_div, cnt);
 
 	if (duty == period) {
@@ -204,14 +205,13 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm,
 		channel->lo = cnt;
 	} else {
 		/* Then check is we can have the duty with the same pre_div */
-		duty_cnt = div64_u64(fin_freq * (u64)duty,
-				     NSEC_PER_SEC * (pre_div + 1));
+		duty_cnt = div64_u64(fin_freq * duty, NSEC_PER_SEC * (pre_div + 1));
 		if (duty_cnt > 0xffff) {
 			dev_err(meson->chip.dev, "unable to get duty cycle\n");
 			return -EINVAL;
 		}
 
-		dev_dbg(meson->chip.dev, "duty=%u pre_div=%u duty_cnt=%u\n",
+		dev_dbg(meson->chip.dev, "duty=%llu pre_div=%u duty_cnt=%u\n",
 			duty, pre_div, duty_cnt);
 
 		channel->pre_div = pre_div;
-- 
2.40.1


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

* Re: [PATCH] pwm: pwm-meson: fix handling of period/duty if greater than UINT_MAX
  2023-05-03 19:58 [PATCH] pwm: pwm-meson: fix handling of period/duty if greater than UINT_MAX Heiner Kallweit
@ 2023-05-03 20:24 ` Uwe Kleine-König
  2023-05-08 19:46 ` Martin Blumenstingl
  1 sibling, 0 replies; 6+ messages in thread
From: Uwe Kleine-König @ 2023-05-03 20:24 UTC (permalink / raw)
  To: Heiner Kallweit
  Cc: Jerome Brunet, Martin Blumenstingl, Neil Armstrong, Kevin Hilman,
	thierry.reding, linux-arm-kernel, open list:ARM/Amlogic Meson...,
	linux-pwm

[-- Attachment #1: Type: text/plain, Size: 759 bytes --]

hello,

On Wed, May 03, 2023 at 09:58:17PM +0200, Heiner Kallweit wrote:
> state->period/duty are of type u64, and if their value is greater than
> UINT_MAX, then the cast to uint will cause problems. Fix this by
> changing the type of the respective local variables to u64.
> 
> Fixes: b79c3670e120 ("pwm: meson: Don't duplicate the polarity internally")
> Cc: stable@vger.kernel.org
> Suggested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>

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

Thanks!
Uwe

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

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

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

* Re: [PATCH] pwm: pwm-meson: fix handling of period/duty if greater than UINT_MAX
  2023-05-03 19:58 [PATCH] pwm: pwm-meson: fix handling of period/duty if greater than UINT_MAX Heiner Kallweit
  2023-05-03 20:24 ` Uwe Kleine-König
@ 2023-05-08 19:46 ` Martin Blumenstingl
  2023-05-15 20:32   ` Heiner Kallweit
  1 sibling, 1 reply; 6+ messages in thread
From: Martin Blumenstingl @ 2023-05-08 19:46 UTC (permalink / raw)
  To: Heiner Kallweit
  Cc: Jerome Brunet, Neil Armstrong, Kevin Hilman,
	Uwe Kleine-König, thierry.reding, linux-arm-kernel,
	open list:ARM/Amlogic Meson...,
	linux-pwm

On Wed, May 3, 2023 at 9:58 PM Heiner Kallweit <hkallweit1@gmail.com> wrote:
>
> state->period/duty are of type u64, and if their value is greater than
> UINT_MAX, then the cast to uint will cause problems. Fix this by
> changing the type of the respective local variables to u64.
>
> Fixes: b79c3670e120 ("pwm: meson: Don't duplicate the polarity internally")
> Cc: stable@vger.kernel.org
> Suggested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Reviewed-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>

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

* Re: [PATCH] pwm: pwm-meson: fix handling of period/duty if greater than UINT_MAX
  2023-05-08 19:46 ` Martin Blumenstingl
@ 2023-05-15 20:32   ` Heiner Kallweit
  2023-05-23 20:51     ` Martin Blumenstingl
  0 siblings, 1 reply; 6+ messages in thread
From: Heiner Kallweit @ 2023-05-15 20:32 UTC (permalink / raw)
  To: Uwe Kleine-König, thierry.reding
  Cc: Jerome Brunet, Neil Armstrong, Kevin Hilman, linux-arm-kernel,
	open list:ARM/Amlogic Meson...,
	linux-pwm, Martin Blumenstingl

On 08.05.2023 21:46, Martin Blumenstingl wrote:
> On Wed, May 3, 2023 at 9:58 PM Heiner Kallweit <hkallweit1@gmail.com> wrote:
>>
>> state->period/duty are of type u64, and if their value is greater than
>> UINT_MAX, then the cast to uint will cause problems. Fix this by
>> changing the type of the respective local variables to u64.
>>
>> Fixes: b79c3670e120 ("pwm: meson: Don't duplicate the polarity internally")
>> Cc: stable@vger.kernel.org
>> Suggested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> Reviewed-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>

Not sure about the process in pwm subsystem: When will these patches make
it to linux-next? Because I'd like to submit follow-ups with a dependency
only after pending patches have been applied.


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

* Re: [PATCH] pwm: pwm-meson: fix handling of period/duty if greater than UINT_MAX
  2023-05-15 20:32   ` Heiner Kallweit
@ 2023-05-23 20:51     ` Martin Blumenstingl
  2023-05-24 19:11       ` Heiner Kallweit
  0 siblings, 1 reply; 6+ messages in thread
From: Martin Blumenstingl @ 2023-05-23 20:51 UTC (permalink / raw)
  To: Heiner Kallweit
  Cc: Uwe Kleine-König, thierry.reding, Jerome Brunet,
	Neil Armstrong, Kevin Hilman, linux-arm-kernel,
	open list:ARM/Amlogic Meson...,
	linux-pwm

On Mon, May 15, 2023 at 10:32 PM Heiner Kallweit <hkallweit1@gmail.com> wrote:
>
> On 08.05.2023 21:46, Martin Blumenstingl wrote:
> > On Wed, May 3, 2023 at 9:58 PM Heiner Kallweit <hkallweit1@gmail.com> wrote:
> >>
> >> state->period/duty are of type u64, and if their value is greater than
> >> UINT_MAX, then the cast to uint will cause problems. Fix this by
> >> changing the type of the respective local variables to u64.
> >>
> >> Fixes: b79c3670e120 ("pwm: meson: Don't duplicate the polarity internally")
> >> Cc: stable@vger.kernel.org
> >> Suggested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> >> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> > Reviewed-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
>
> Not sure about the process in pwm subsystem: When will these patches make
> it to linux-next? Because I'd like to submit follow-ups with a dependency
> only after pending patches have been applied.
I'm also not sure. Personally I would take all patches that fix the
existing driver code, bundle them into a series and re-send that
(collecting all Reviewed-by, etc. along the way). The idea is to make
Thierry's life easier as he just has to apply the series (no need to
worry about the patch order, ...).

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

* Re: [PATCH] pwm: pwm-meson: fix handling of period/duty if greater than UINT_MAX
  2023-05-23 20:51     ` Martin Blumenstingl
@ 2023-05-24 19:11       ` Heiner Kallweit
  0 siblings, 0 replies; 6+ messages in thread
From: Heiner Kallweit @ 2023-05-24 19:11 UTC (permalink / raw)
  To: Martin Blumenstingl
  Cc: Uwe Kleine-König, thierry.reding, Jerome Brunet,
	Neil Armstrong, Kevin Hilman, linux-arm-kernel,
	open list:ARM/Amlogic Meson...,
	linux-pwm

On 23.05.2023 22:51, Martin Blumenstingl wrote:
> On Mon, May 15, 2023 at 10:32 PM Heiner Kallweit <hkallweit1@gmail.com> wrote:
>>
>> On 08.05.2023 21:46, Martin Blumenstingl wrote:
>>> On Wed, May 3, 2023 at 9:58 PM Heiner Kallweit <hkallweit1@gmail.com> wrote:
>>>>
>>>> state->period/duty are of type u64, and if their value is greater than
>>>> UINT_MAX, then the cast to uint will cause problems. Fix this by
>>>> changing the type of the respective local variables to u64.
>>>>
>>>> Fixes: b79c3670e120 ("pwm: meson: Don't duplicate the polarity internally")
>>>> Cc: stable@vger.kernel.org
>>>> Suggested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
>>>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
>>> Reviewed-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
>>
>> Not sure about the process in pwm subsystem: When will these patches make
>> it to linux-next? Because I'd like to submit follow-ups with a dependency
>> only after pending patches have been applied.
> I'm also not sure. Personally I would take all patches that fix the
> existing driver code, bundle them into a series and re-send that
> (collecting all Reviewed-by, etc. along the way). The idea is to make
> Thierry's life easier as he just has to apply the series (no need to
> worry about the patch order, ...).

Sounds like a plan, I think I'll follow this suggestion.

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

end of thread, other threads:[~2023-05-24 19:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-03 19:58 [PATCH] pwm: pwm-meson: fix handling of period/duty if greater than UINT_MAX Heiner Kallweit
2023-05-03 20:24 ` Uwe Kleine-König
2023-05-08 19:46 ` Martin Blumenstingl
2023-05-15 20:32   ` Heiner Kallweit
2023-05-23 20:51     ` Martin Blumenstingl
2023-05-24 19:11       ` Heiner Kallweit

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).