meson pwm small fixes
Subsystems (2)
v3 cover meson pwm small fixes
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]
v2->v3:
pwm: meson: Add check for error from clk_round_rate()
- change format modifier in dev_dbg() for fin_freq var to %lu previous version: [3]
pwm: meson: Use mul_u64_u64_div_u64() for frequency calculating
new patch
[1] https://lore.kernel.org/lkml/[email protected]/T/#m6d1d5cf100dc5b77f85e2a7d01c0b0097b6a04da
[2] https://lore.kernel.org/lkml/[email protected]/T/#ma84e2d490bf79bda12f8393773c1af37b48d5473
[3] https://lore.kernel.org/linux-arm-kernel/[email protected]/T/#m52b7e5a34c3e8907235d73c2827b92cb13c93dd3
George Stark (3):
pwm: meson: Drop unneeded check in .get_state()
pwm: meson: Add check for error from clk_round_rate()
pwm: meson: Use mul_u64_u64_div_u64() for frequency calculating
drivers/pwm/pwm-meson.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
--
2.25.1
PATCH v3 1/3 pwm: meson: Drop unneeded check in .get_state()
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.
--- drivers/pwm/pwm-meson.c | 3 --- 1 file changed, 3 deletions(-)
drivers/pwm/pwm-meson.c +0 -3
@@ -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];
Signature · 1 line
2.25.1
PATCH v3 2/3 pwm: meson: Add check for error from clk_round_rate()
In reply to George Starkclk_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.
--- drivers/pwm/pwm-meson.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/pwm/pwm-meson.c +6 -5
@@ -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,12 +168,13 @@ 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); +dev_dbg (pwmchip_parent (chip),"fin_freq: %ld Hz\n" , fin_freq); cnt =div_u64 (fin_freq * period,NSEC_PER_SEC );if (cnt >0xffff ) {
Signature · 1 line
2.25.1
PATCH v3 3/3 pwm: meson: Use mul_u64_u64_div_u64() for frequency calculating
In reply to George StarkWhile calculating frequency for the given period u64 numbers are multiplied before division what can lead to overflow in theory so use secure mul_u64_u64_div_u64() which handles overflow correctly.
--- drivers/pwm/pwm-meson.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pwm/pwm-meson.c +2 -2
@@ -176,7 +176,7 @@ static int meson_pwm_calc(struct pwm_chip *chip, struct pwm_device *pwm,dev_dbg (pwmchip_parent (chip),"fin_freq: %ld Hz\n" , fin_freq); - cnt =div_u64 (fin_freq * period,NSEC_PER_SEC ); + cnt =mul_u64_u64_div_u64 (fin_freq, period,NSEC_PER_SEC );if (cnt >0xffff ) {dev_err (pwmchip_parent (chip),"unable to get period cnt\n" );return -EINVAL ;
@@ -191,7 +191,7 @@ static int meson_pwm_calc(struct pwm_chip *chip, struct pwm_device *pwm, channel->hi =0 ; channel->lo = cnt; }else { - duty_cnt =div_u64 (fin_freq * duty,NSEC_PER_SEC ); + duty_cnt =mul_u64_u64_div_u64 (fin_freq, duty,NSEC_PER_SEC );dev_dbg (pwmchip_parent (chip),"duty=%llu duty_cnt=%u\n" , duty, duty_cnt);
Signature · 1 line
2.25.1
Hello,
Quoted 1 line · George Stark
Just some small fixes for meson pwm.
Applied the series to
https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git pwm/for-next .
Thanks
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |