diff mbox series

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

Message ID 20200824145539.3160946-1-jarkko.nikula@linux.intel.com
State Accepted
Headers show
Series pwm: Allow store 64-bit duty cycle from sysfs interface | expand

Commit Message

Jarkko Nikula Aug. 24, 2020, 2:55 p.m. UTC
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().

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
---
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(-)

Comments

Guru Das Srinagesh Aug. 27, 2020, 8:37 p.m. UTC | #1
On Mon, Aug 24, 2020 at 05:55:39PM +0300, Jarkko Nikula wrote:
> 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().
> 
> Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>

Acked-by: Guru Das Srinagesh <gurus@codeaurora.org>

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.

> ---
> 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(-)
> 
> diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c
> index 449dbc0f49ed..9903c3a7eced 100644
> --- a/drivers/pwm/sysfs.c
> +++ b/drivers/pwm/sysfs.c
> @@ -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;
>  
> -- 
> 2.28.0
>
Uwe Kleine-König Sept. 7, 2020, 3:22 p.m. UTC | #2
On Mon, Aug 24, 2020 at 05:55:39PM +0300, Jarkko Nikula wrote:
> 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().
> 
> Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>

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

Thanks
Uwe
Thierry Reding Sept. 23, 2020, 12:11 p.m. UTC | #3
On Mon, Aug 24, 2020 at 05:55:39PM +0300, Jarkko Nikula wrote:
> 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().
> 
> Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
> ---
> 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
diff mbox series

Patch

diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c
index 449dbc0f49ed..9903c3a7eced 100644
--- a/drivers/pwm/sysfs.c
+++ b/drivers/pwm/sysfs.c
@@ -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;