* [PATCH v2 0/2] meson pwm small fixes
@ 2024-04-24 13:24 George Stark
2024-04-24 13:24 ` [PATCH v2 1/2] pwm: meson: Drop unneeded check in .get_state() George Stark
2024-04-24 13:24 ` [PATCH v2 2/2] pwm: meson: Add check for error from clk_round_rate() George Stark
0 siblings, 2 replies; 4+ messages in thread
From: George Stark @ 2024-04-24 13:24 UTC (permalink / raw)
To: u.kleine-koenig, neil.armstrong, khilman, jbrunet,
martin.blumenstingl, thierry.reding, hkallweit1
Cc: linux-pwm, linux-amlogic, linux-arm-kernel, linux-kernel, kernel,
George Stark
Just some small fixes for meson pwm.
Changelog:
v1->v2:
pwm: meson: Drop unneeded check in .get_state()
- update commit message
- drop Fixes tag. It's not actually a bug
previous version: [1]
pwm: meson: Add check for error from clk_round_rate()
- update commit message
- change unsigned long fin_freq; to long fin_freq;
previous version: [2]
[1] https://lore.kernel.org/lkml/20240423161356.2522636-2-gnstark@salutedevices.com/T/#m6d1d5cf100dc5b77f85e2a7d01c0b0097b6a04da
[2] https://lore.kernel.org/lkml/20240423161356.2522636-2-gnstark@salutedevices.com/T/#ma84e2d490bf79bda12f8393773c1af37b48d5473
George Stark (2):
pwm: meson: Drop unneeded check in .get_state()
pwm: meson: Add check for error from clk_round_rate()
drivers/pwm/pwm-meson.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
--
2.25.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v2 1/2] pwm: meson: Drop unneeded check in .get_state() 2024-04-24 13:24 [PATCH v2 0/2] meson pwm small fixes George Stark @ 2024-04-24 13:24 ` George Stark 2024-04-24 13:24 ` [PATCH v2 2/2] pwm: meson: Add check for error from clk_round_rate() George Stark 1 sibling, 0 replies; 4+ messages in thread From: George Stark @ 2024-04-24 13:24 UTC (permalink / raw) To: u.kleine-koenig, neil.armstrong, khilman, jbrunet, martin.blumenstingl, thierry.reding, hkallweit1 Cc: linux-pwm, linux-amlogic, linux-arm-kernel, linux-kernel, kernel, George Stark, Dmitry Rokosov Drop checking state argument for NULL pointer in meson_pwm_get_state() due to it is called only from pwm core with always valid arguments. Signed-off-by: Dmitry Rokosov <ddrokosov@salutedevices.com> Signed-off-by: George Stark <gnstark@salutedevices.com> --- drivers/pwm/pwm-meson.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index ea96c5973488..f4d70da621ec 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -311,9 +311,6 @@ static int meson_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, struct meson_pwm_channel *channel; u32 value; - if (!state) - return 0; - channel = &meson->channels[pwm->hwpwm]; channel_data = &meson_pwm_per_channel_data[pwm->hwpwm]; -- 2.25.1 _______________________________________________ linux-amlogic mailing list linux-amlogic@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-amlogic ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] pwm: meson: Add check for error from clk_round_rate() 2024-04-24 13:24 [PATCH v2 0/2] meson pwm small fixes George Stark 2024-04-24 13:24 ` [PATCH v2 1/2] pwm: meson: Drop unneeded check in .get_state() George Stark @ 2024-04-24 13:24 ` George Stark 2024-04-24 14:19 ` Uwe Kleine-König 1 sibling, 1 reply; 4+ messages in thread From: George Stark @ 2024-04-24 13:24 UTC (permalink / raw) To: u.kleine-koenig, neil.armstrong, khilman, jbrunet, martin.blumenstingl, thierry.reding, hkallweit1 Cc: linux-pwm, linux-amlogic, linux-arm-kernel, linux-kernel, kernel, George Stark, Dmitry Rokosov clk_round_rate() can return not only zero if requested frequency can not be provided but also negative error code so add check for it too. Also change type of variable holding clk_round_rate() result from unsigned long to long. It's safe due to clk_round_rate() returns long. Fixes: 329db102a26d ("pwm: meson: make full use of common clock framework") Signed-off-by: Dmitry Rokosov <ddrokosov@salutedevices.com> Signed-off-by: George Stark <gnstark@salutedevices.com> --- drivers/pwm/pwm-meson.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index f4d70da621ec..d4228ac1e7ea 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -148,7 +148,7 @@ static int meson_pwm_calc(struct pwm_chip *chip, struct pwm_device *pwm, struct meson_pwm *meson = to_meson_pwm(chip); struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm]; unsigned int cnt, duty_cnt; - unsigned long fin_freq; + long fin_freq; u64 duty, period, freq; duty = state->duty_cycle; @@ -168,9 +168,10 @@ static int meson_pwm_calc(struct pwm_chip *chip, struct pwm_device *pwm, freq = ULONG_MAX; fin_freq = clk_round_rate(channel->clk, freq); - if (fin_freq == 0) { - dev_err(pwmchip_parent(chip), "invalid source clock frequency\n"); - return -EINVAL; + if (fin_freq <= 0) { + dev_err(pwmchip_parent(chip), + "invalid source clock frequency %llu\n", freq); + return fin_freq ? fin_freq : -EINVAL; } dev_dbg(pwmchip_parent(chip), "fin_freq: %lu Hz\n", fin_freq); -- 2.25.1 _______________________________________________ linux-amlogic mailing list linux-amlogic@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-amlogic ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/2] pwm: meson: Add check for error from clk_round_rate() 2024-04-24 13:24 ` [PATCH v2 2/2] pwm: meson: Add check for error from clk_round_rate() George Stark @ 2024-04-24 14:19 ` Uwe Kleine-König 0 siblings, 0 replies; 4+ messages in thread From: Uwe Kleine-König @ 2024-04-24 14:19 UTC (permalink / raw) To: George Stark Cc: neil.armstrong, khilman, jbrunet, martin.blumenstingl, thierry.reding, hkallweit1, linux-pwm, linux-amlogic, linux-arm-kernel, linux-kernel, kernel, Dmitry Rokosov [-- Attachment #1.1: Type: text/plain, Size: 2301 bytes --] On Wed, Apr 24, 2024 at 04:24:08PM +0300, George Stark wrote: > clk_round_rate() can return not only zero if requested frequency can not > be provided but also negative error code so add check for it too. > > Also change type of variable holding clk_round_rate() result from > unsigned long to long. It's safe due to clk_round_rate() returns long. > > Fixes: 329db102a26d ("pwm: meson: make full use of common clock framework") > Signed-off-by: Dmitry Rokosov <ddrokosov@salutedevices.com> > Signed-off-by: George Stark <gnstark@salutedevices.com> > --- > drivers/pwm/pwm-meson.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c > index f4d70da621ec..d4228ac1e7ea 100644 > --- a/drivers/pwm/pwm-meson.c > +++ b/drivers/pwm/pwm-meson.c > @@ -148,7 +148,7 @@ static int meson_pwm_calc(struct pwm_chip *chip, struct pwm_device *pwm, > struct meson_pwm *meson = to_meson_pwm(chip); > struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm]; > unsigned int cnt, duty_cnt; > - unsigned long fin_freq; > + long fin_freq; > u64 duty, period, freq; > > duty = state->duty_cycle; > @@ -168,9 +168,10 @@ static int meson_pwm_calc(struct pwm_chip *chip, struct pwm_device *pwm, > freq = ULONG_MAX; > > fin_freq = clk_round_rate(channel->clk, freq); > - if (fin_freq == 0) { > - dev_err(pwmchip_parent(chip), "invalid source clock frequency\n"); > - return -EINVAL; > + if (fin_freq <= 0) { > + dev_err(pwmchip_parent(chip), > + "invalid source clock frequency %llu\n", freq); > + return fin_freq ? fin_freq : -EINVAL; > } > > dev_dbg(pwmchip_parent(chip), "fin_freq: %lu Hz\n", fin_freq); ^ With fin_freq now being unsigned, this ------------' should be a 'd'. If you want to still extend your fixes series: A bit further below there is cnt = div_u64(fin_freq * period, NSEC_PER_SEC); . The multiplication there might overflow. This should better use mul_u64_u64_div_u64() (or one of it's variants). Best regards 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: 167 bytes --] _______________________________________________ linux-amlogic mailing list linux-amlogic@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-amlogic ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-04-24 14:19 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-04-24 13:24 [PATCH v2 0/2] meson pwm small fixes George Stark 2024-04-24 13:24 ` [PATCH v2 1/2] pwm: meson: Drop unneeded check in .get_state() George Stark 2024-04-24 13:24 ` [PATCH v2 2/2] pwm: meson: Add check for error from clk_round_rate() George Stark 2024-04-24 14:19 ` Uwe Kleine-König
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®