Skip to contentSkip to conversation

pwm: Allow store 64-bit duty cycle from sysfs interface

PATCH Applied Jarkko Nikula 4 participants 4 messages Aug 24, 2020 – Sep 23, 2020 PWM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pwm: Allow store 64-bit duty cycle from sysfs interface

PWM core was converted to u64 by the commit a9d887dc1c60 ("pwm: Convert period and duty cycle to u64") but did not change the duty_cycle_store() so it will error out if trying to pass a numeric string bigger than 2^32-1.

Fix this by using u64 and kstrtou64() in duty_cycle_store().

---
I don't think this qualifies for a Fixes tag since original commit doesn't cause a regression while still might be good for v5.9 material.

---
 drivers/pwm/sysfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pwm/sysfs.c +2 -2
index 449dbc0f49ed..9903c3a7eced 100644
@@ -87,10 +87,10 @@ static ssize_t duty_cycle_store(struct device *child,
 	struct pwm_export *export = child_to_pwm_export(child);
 	struct pwm_device *pwm = export->pwm;
 	struct pwm_state state;
-	unsigned int val;
+	u64 val;
 	int ret;
 
-	ret = kstrtouint(buf, 0, &val);
+	ret = kstrtou64(buf, 0, &val);
 	if (ret)
 		return ret;
 
Signature · 1 line
2.28.0
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Jarkko Nikula

PWM core was converted to u64 by the commit a9d887dc1c60 ("pwm: Convert period and duty cycle to u64") but did not change the duty_cycle_store() so it will error out if trying to pass a numeric string bigger than 2^32-1.

Fix this by using u64 and kstrtou64() in duty_cycle_store().

I'd made the change to period_store(), but had missed doing the same for duty_cycle_store(). Thanks Jarkko for catching this.

Guru Das.

Quoted 27 lines

---
I don't think this qualifies for a Fixes tag since original commit doesn't cause a regression while still might be good for v5.9 material.

---
 drivers/pwm/sysfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pwm/sysfs.c +2 -2
index 449dbc0f49ed..9903c3a7eced 100644
@@ -87,10 +87,10 @@ static ssize_t duty_cycle_store(struct device *child,
 	struct pwm_export *export = child_to_pwm_export(child);
 	struct pwm_device *pwm = export->pwm;
 	struct pwm_state state;
-	unsigned int val;
+	u64 val;
 	int ret;
 
-	ret = kstrtouint(buf, 0, &val);
+	ret = kstrtou64(buf, 0, &val);
 	if (ret)
 		return ret;
 
Signature · 1 line
2.28.0
Acked-by on v1 1/1
#2 lore raw
In reply to Jarkko Nikula
Quoted 8 lines · Jarkko Nikula

PWM core was converted to u64 by the commit a9d887dc1c60 ("pwm: Convert period and duty cycle to u64") but did not change the duty_cycle_store() so it will error out if trying to pass a numeric string bigger than 2^32-1.

Fix this by using u64 and kstrtou64() in duty_cycle_store().

Thanks
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
#3 lore raw
In reply to Jarkko Nikula
Quoted 7 lines · Jarkko Nikula

PWM core was converted to u64 by the commit a9d887dc1c60 ("pwm: Convert period and duty cycle to u64") but did not change the duty_cycle_store() so it will error out if trying to pass a numeric string bigger than 2^32-1.

Fix this by using u64 and kstrtou64() in duty_cycle_store().

Quoted 7 lines

---
I don't think this qualifies for a Fixes tag since original commit doesn't cause a regression while still might be good for v5.9 material.

---
 drivers/pwm/sysfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Applied, thanks.

Thierry