* [PATCH v1 0/2] Handle return value and remove unnecessary check
@ 2020-03-23 6:53 Rayagonda Kokatanur
2020-03-23 6:53 ` [PATCH v1 1/2] pwm: bcm-iproc: handle clk_get_rate() return Rayagonda Kokatanur
2020-03-23 6:53 ` [PATCH v1 2/2] pwm: bcm-iproc: remove unnecessary check of 'duty' Rayagonda Kokatanur
0 siblings, 2 replies; 7+ messages in thread
From: Rayagonda Kokatanur @ 2020-03-23 6:53 UTC (permalink / raw)
To: Thierry Reding, Uwe Kleine-König, Ray Jui, Scott Branden,
bcm-kernel-feedback-list, Yendapally Reddy Dhananjaya Reddy,
linux-pwm, linux-arm-kernel, linux-kernel
Cc: Rayagonda Kokatanur
This patch series contains following changes,
1. Handle clk_get_rate() return
2. remove unnecessary check of 'duty'
Rayagonda Kokatanur (2):
pwm: bcm-iproc: handle clk_get_rate() return
pwm: bcm-iproc: remove unnecessary check of 'duty'
drivers/pwm/pwm-bcm-iproc.c | 35 ++++++++++++++++++++---------------
1 file changed, 20 insertions(+), 15 deletions(-)
--
2.17.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v1 1/2] pwm: bcm-iproc: handle clk_get_rate() return
2020-03-23 6:53 [PATCH v1 0/2] Handle return value and remove unnecessary check Rayagonda Kokatanur
@ 2020-03-23 6:53 ` Rayagonda Kokatanur
2020-03-23 8:25 ` Uwe Kleine-König
2020-03-23 6:53 ` [PATCH v1 2/2] pwm: bcm-iproc: remove unnecessary check of 'duty' Rayagonda Kokatanur
1 sibling, 1 reply; 7+ messages in thread
From: Rayagonda Kokatanur @ 2020-03-23 6:53 UTC (permalink / raw)
To: Thierry Reding, Uwe Kleine-König, Ray Jui, Scott Branden,
bcm-kernel-feedback-list, Yendapally Reddy Dhananjaya Reddy,
linux-pwm, linux-arm-kernel, linux-kernel
Cc: Rayagonda Kokatanur
Handle clk_get_rate() returning <= 0 condition to avoid
possible division by zero.
Fixes: daa5abc41c80 ("pwm: Add support for Broadcom iProc PWM controller")
Signed-off-by: Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>
---
drivers/pwm/pwm-bcm-iproc.c | 32 +++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)
diff --git a/drivers/pwm/pwm-bcm-iproc.c b/drivers/pwm/pwm-bcm-iproc.c
index 1f829edd8ee7..8bbd2a04fead 100644
--- a/drivers/pwm/pwm-bcm-iproc.c
+++ b/drivers/pwm/pwm-bcm-iproc.c
@@ -99,19 +99,25 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
else
state->polarity = PWM_POLARITY_INVERSED;
- value = readl(ip->base + IPROC_PWM_PRESCALE_OFFSET);
- prescale = value >> IPROC_PWM_PRESCALE_SHIFT(pwm->hwpwm);
- prescale &= IPROC_PWM_PRESCALE_MAX;
-
- multi = NSEC_PER_SEC * (prescale + 1);
-
- value = readl(ip->base + IPROC_PWM_PERIOD_OFFSET(pwm->hwpwm));
- tmp = (value & IPROC_PWM_PERIOD_MAX) * multi;
- state->period = div64_u64(tmp, rate);
-
- value = readl(ip->base + IPROC_PWM_DUTY_CYCLE_OFFSET(pwm->hwpwm));
- tmp = (value & IPROC_PWM_PERIOD_MAX) * multi;
- state->duty_cycle = div64_u64(tmp, rate);
+ if (rate == 0) {
+ state->period = 0;
+ state->duty_cycle = 0;
+ } else {
+ value = readl(ip->base + IPROC_PWM_PRESCALE_OFFSET);
+ prescale = value >> IPROC_PWM_PRESCALE_SHIFT(pwm->hwpwm);
+ prescale &= IPROC_PWM_PRESCALE_MAX;
+
+ multi = NSEC_PER_SEC * (prescale + 1);
+
+ value = readl(ip->base + IPROC_PWM_PERIOD_OFFSET(pwm->hwpwm));
+ tmp = (value & IPROC_PWM_PERIOD_MAX) * multi;
+ state->period = div64_u64(tmp, rate);
+
+ value = readl(ip->base +
+ IPROC_PWM_DUTY_CYCLE_OFFSET(pwm->hwpwm));
+ tmp = (value & IPROC_PWM_PERIOD_MAX) * multi;
+ state->duty_cycle = div64_u64(tmp, rate);
+ }
}
static int iproc_pwmc_apply(struct pwm_chip *chip, struct pwm_device *pwm,
--
2.17.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v1 2/2] pwm: bcm-iproc: remove unnecessary check of 'duty'
2020-03-23 6:53 [PATCH v1 0/2] Handle return value and remove unnecessary check Rayagonda Kokatanur
2020-03-23 6:53 ` [PATCH v1 1/2] pwm: bcm-iproc: handle clk_get_rate() return Rayagonda Kokatanur
@ 2020-03-23 6:53 ` Rayagonda Kokatanur
2020-03-23 8:28 ` Uwe Kleine-König
1 sibling, 1 reply; 7+ messages in thread
From: Rayagonda Kokatanur @ 2020-03-23 6:53 UTC (permalink / raw)
To: Thierry Reding, Uwe Kleine-König, Ray Jui, Scott Branden,
bcm-kernel-feedback-list, Yendapally Reddy Dhananjaya Reddy,
linux-pwm, linux-arm-kernel, linux-kernel
Cc: Rayagonda Kokatanur
Variable 'duty' is u32. Hence the less-than zero
comparison is never true, remove the check.
Fixes: daa5abc41c80 ("pwm: Add support for Broadcom iProc PWM controller")
Signed-off-by: Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>
---
drivers/pwm/pwm-bcm-iproc.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/pwm/pwm-bcm-iproc.c b/drivers/pwm/pwm-bcm-iproc.c
index 8bbd2a04fead..1bb66721f985 100644
--- a/drivers/pwm/pwm-bcm-iproc.c
+++ b/drivers/pwm/pwm-bcm-iproc.c
@@ -149,8 +149,7 @@ static int iproc_pwmc_apply(struct pwm_chip *chip, struct pwm_device *pwm,
value = rate * state->duty_cycle;
duty = div64_u64(value, div);
- if (period < IPROC_PWM_PERIOD_MIN ||
- duty < IPROC_PWM_DUTY_CYCLE_MIN)
+ if (period < IPROC_PWM_PERIOD_MIN)
return -EINVAL;
if (period <= IPROC_PWM_PERIOD_MAX &&
--
2.17.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v1 1/2] pwm: bcm-iproc: handle clk_get_rate() return
2020-03-23 6:53 ` [PATCH v1 1/2] pwm: bcm-iproc: handle clk_get_rate() return Rayagonda Kokatanur
@ 2020-03-23 8:25 ` Uwe Kleine-König
2020-03-23 9:05 ` Rayagonda Kokatanur
0 siblings, 1 reply; 7+ messages in thread
From: Uwe Kleine-König @ 2020-03-23 8:25 UTC (permalink / raw)
To: Rayagonda Kokatanur
Cc: Thierry Reding, Ray Jui, Scott Branden, bcm-kernel-feedback-list,
Yendapally Reddy Dhananjaya Reddy, linux-pwm, linux-arm-kernel,
linux-kernel
On Mon, Mar 23, 2020 at 12:23:17PM +0530, Rayagonda Kokatanur wrote:
> Handle clk_get_rate() returning <= 0 condition to avoid
> possible division by zero.
Was this noticed during a review and is more theoretic. Or does this
(depending on pre-boot state) result in a kernel crash?
> Fixes: daa5abc41c80 ("pwm: Add support for Broadcom iProc PWM controller")
> Signed-off-by: Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>
> ---
> drivers/pwm/pwm-bcm-iproc.c | 32 +++++++++++++++++++-------------
> 1 file changed, 19 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/pwm/pwm-bcm-iproc.c b/drivers/pwm/pwm-bcm-iproc.c
> index 1f829edd8ee7..8bbd2a04fead 100644
> --- a/drivers/pwm/pwm-bcm-iproc.c
> +++ b/drivers/pwm/pwm-bcm-iproc.c
> @@ -99,19 +99,25 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
> else
> state->polarity = PWM_POLARITY_INVERSED;
>
> - value = readl(ip->base + IPROC_PWM_PRESCALE_OFFSET);
> - prescale = value >> IPROC_PWM_PRESCALE_SHIFT(pwm->hwpwm);
> - prescale &= IPROC_PWM_PRESCALE_MAX;
> -
> - multi = NSEC_PER_SEC * (prescale + 1);
> -
> - value = readl(ip->base + IPROC_PWM_PERIOD_OFFSET(pwm->hwpwm));
> - tmp = (value & IPROC_PWM_PERIOD_MAX) * multi;
> - state->period = div64_u64(tmp, rate);
> -
> - value = readl(ip->base + IPROC_PWM_DUTY_CYCLE_OFFSET(pwm->hwpwm));
> - tmp = (value & IPROC_PWM_PERIOD_MAX) * multi;
> - state->duty_cycle = div64_u64(tmp, rate);
> + if (rate == 0) {
> + state->period = 0;
> + state->duty_cycle = 0;
> + } else {
> + value = readl(ip->base + IPROC_PWM_PRESCALE_OFFSET);
> + prescale = value >> IPROC_PWM_PRESCALE_SHIFT(pwm->hwpwm);
> + prescale &= IPROC_PWM_PRESCALE_MAX;
> +
> + multi = NSEC_PER_SEC * (prescale + 1);
> +
> + value = readl(ip->base + IPROC_PWM_PERIOD_OFFSET(pwm->hwpwm));
> + tmp = (value & IPROC_PWM_PERIOD_MAX) * multi;
> + state->period = div64_u64(tmp, rate);
> +
> + value = readl(ip->base +
> + IPROC_PWM_DUTY_CYCLE_OFFSET(pwm->hwpwm));
> + tmp = (value & IPROC_PWM_PERIOD_MAX) * multi;
> + state->duty_cycle = div64_u64(tmp, rate);
> + }
The change looks fine.
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | https://www.pengutronix.de/ |
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 2/2] pwm: bcm-iproc: remove unnecessary check of 'duty'
2020-03-23 6:53 ` [PATCH v1 2/2] pwm: bcm-iproc: remove unnecessary check of 'duty' Rayagonda Kokatanur
@ 2020-03-23 8:28 ` Uwe Kleine-König
2020-03-23 9:13 ` Rayagonda Kokatanur
0 siblings, 1 reply; 7+ messages in thread
From: Uwe Kleine-König @ 2020-03-23 8:28 UTC (permalink / raw)
To: Rayagonda Kokatanur
Cc: Thierry Reding, Ray Jui, Scott Branden, bcm-kernel-feedback-list,
Yendapally Reddy Dhananjaya Reddy, linux-pwm, linux-arm-kernel,
linux-kernel
On Mon, Mar 23, 2020 at 12:23:18PM +0530, Rayagonda Kokatanur wrote:
> Variable 'duty' is u32. Hence the less-than zero
> comparison is never true, remove the check.
How did you find that one? I assume it was a compiler warning you fixed
here? In this case quoting the warning improves the commit log.
Also the commit log suggests that IPROC_PWM_DUTY_CYCLE_MIN is zero.
Maybe mentioning that explicitly is a nice addition, too.
> Fixes: daa5abc41c80 ("pwm: Add support for Broadcom iProc PWM controller")
> Signed-off-by: Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>
> ---
> drivers/pwm/pwm-bcm-iproc.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/pwm/pwm-bcm-iproc.c b/drivers/pwm/pwm-bcm-iproc.c
> index 8bbd2a04fead..1bb66721f985 100644
> --- a/drivers/pwm/pwm-bcm-iproc.c
> +++ b/drivers/pwm/pwm-bcm-iproc.c
> @@ -149,8 +149,7 @@ static int iproc_pwmc_apply(struct pwm_chip *chip, struct pwm_device *pwm,
> value = rate * state->duty_cycle;
> duty = div64_u64(value, div);
>
> - if (period < IPROC_PWM_PERIOD_MIN ||
> - duty < IPROC_PWM_DUTY_CYCLE_MIN)
> + if (period < IPROC_PWM_PERIOD_MIN)
> return -EINVAL;
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | https://www.pengutronix.de/ |
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 1/2] pwm: bcm-iproc: handle clk_get_rate() return
2020-03-23 8:25 ` Uwe Kleine-König
@ 2020-03-23 9:05 ` Rayagonda Kokatanur
0 siblings, 0 replies; 7+ messages in thread
From: Rayagonda Kokatanur @ 2020-03-23 9:05 UTC (permalink / raw)
To: Uwe Kleine-König
Cc: Thierry Reding, Ray Jui, Scott Branden, BCM Kernel Feedback,
Yendapally Reddy Dhananjaya Reddy, linux-pwm, linux-arm-kernel,
Linux Kernel Mailing List
On Mon, Mar 23, 2020 at 1:55 PM Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
>
> On Mon, Mar 23, 2020 at 12:23:17PM +0530, Rayagonda Kokatanur wrote:
> > Handle clk_get_rate() returning <= 0 condition to avoid
> > possible division by zero.
>
> Was this noticed during a review and is more theoretic. Or does this
> (depending on pre-boot state) result in a kernel crash?
This is reported by internal coverity tool.
>
> > Fixes: daa5abc41c80 ("pwm: Add support for Broadcom iProc PWM controller")
> > Signed-off-by: Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>
> > ---
> > drivers/pwm/pwm-bcm-iproc.c | 32 +++++++++++++++++++-------------
> > 1 file changed, 19 insertions(+), 13 deletions(-)
> >
> > diff --git a/drivers/pwm/pwm-bcm-iproc.c b/drivers/pwm/pwm-bcm-iproc.c
> > index 1f829edd8ee7..8bbd2a04fead 100644
> > --- a/drivers/pwm/pwm-bcm-iproc.c
> > +++ b/drivers/pwm/pwm-bcm-iproc.c
> > @@ -99,19 +99,25 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
> > else
> > state->polarity = PWM_POLARITY_INVERSED;
> >
> > - value = readl(ip->base + IPROC_PWM_PRESCALE_OFFSET);
> > - prescale = value >> IPROC_PWM_PRESCALE_SHIFT(pwm->hwpwm);
> > - prescale &= IPROC_PWM_PRESCALE_MAX;
> > -
> > - multi = NSEC_PER_SEC * (prescale + 1);
> > -
> > - value = readl(ip->base + IPROC_PWM_PERIOD_OFFSET(pwm->hwpwm));
> > - tmp = (value & IPROC_PWM_PERIOD_MAX) * multi;
> > - state->period = div64_u64(tmp, rate);
> > -
> > - value = readl(ip->base + IPROC_PWM_DUTY_CYCLE_OFFSET(pwm->hwpwm));
> > - tmp = (value & IPROC_PWM_PERIOD_MAX) * multi;
> > - state->duty_cycle = div64_u64(tmp, rate);
> > + if (rate == 0) {
> > + state->period = 0;
> > + state->duty_cycle = 0;
> > + } else {
> > + value = readl(ip->base + IPROC_PWM_PRESCALE_OFFSET);
> > + prescale = value >> IPROC_PWM_PRESCALE_SHIFT(pwm->hwpwm);
> > + prescale &= IPROC_PWM_PRESCALE_MAX;
> > +
> > + multi = NSEC_PER_SEC * (prescale + 1);
> > +
> > + value = readl(ip->base + IPROC_PWM_PERIOD_OFFSET(pwm->hwpwm));
> > + tmp = (value & IPROC_PWM_PERIOD_MAX) * multi;
> > + state->period = div64_u64(tmp, rate);
> > +
> > + value = readl(ip->base +
> > + IPROC_PWM_DUTY_CYCLE_OFFSET(pwm->hwpwm));
> > + tmp = (value & IPROC_PWM_PERIOD_MAX) * multi;
> > + state->duty_cycle = div64_u64(tmp, rate);
> > + }
>
> The change looks fine.
>
> Best regards
> Uwe
>
> --
> Pengutronix e.K. | Uwe Kleine-König |
> Industrial Linux Solutions | https://www.pengutronix.de/ |
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 2/2] pwm: bcm-iproc: remove unnecessary check of 'duty'
2020-03-23 8:28 ` Uwe Kleine-König
@ 2020-03-23 9:13 ` Rayagonda Kokatanur
0 siblings, 0 replies; 7+ messages in thread
From: Rayagonda Kokatanur @ 2020-03-23 9:13 UTC (permalink / raw)
To: Uwe Kleine-König
Cc: Thierry Reding, Ray Jui, Scott Branden, BCM Kernel Feedback,
Yendapally Reddy Dhananjaya Reddy, linux-pwm, linux-arm-kernel,
Linux Kernel Mailing List
On Mon, Mar 23, 2020 at 1:58 PM Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
>
> On Mon, Mar 23, 2020 at 12:23:18PM +0530, Rayagonda Kokatanur wrote:
> > Variable 'duty' is u32. Hence the less-than zero
> > comparison is never true, remove the check.
>
> How did you find that one? I assume it was a compiler warning you fixed
> here? In this case quoting the warning improves the commit log.
Its reported by internal coverity tool.
>
> Also the commit log suggests that IPROC_PWM_DUTY_CYCLE_MIN is zero.
> Maybe mentioning that explicitly is a nice addition, too.
Okay, will add this to commit message. Thanks.
>
> > Fixes: daa5abc41c80 ("pwm: Add support for Broadcom iProc PWM controller")
> > Signed-off-by: Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>
> > ---
> > drivers/pwm/pwm-bcm-iproc.c | 3 +--
> > 1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/drivers/pwm/pwm-bcm-iproc.c b/drivers/pwm/pwm-bcm-iproc.c
> > index 8bbd2a04fead..1bb66721f985 100644
> > --- a/drivers/pwm/pwm-bcm-iproc.c
> > +++ b/drivers/pwm/pwm-bcm-iproc.c
> > @@ -149,8 +149,7 @@ static int iproc_pwmc_apply(struct pwm_chip *chip, struct pwm_device *pwm,
> > value = rate * state->duty_cycle;
> > duty = div64_u64(value, div);
> >
> > - if (period < IPROC_PWM_PERIOD_MIN ||
> > - duty < IPROC_PWM_DUTY_CYCLE_MIN)
> > + if (period < IPROC_PWM_PERIOD_MIN)
> > return -EINVAL;
>
> Best regards
> Uwe
>
> --
> Pengutronix e.K. | Uwe Kleine-König |
> Industrial Linux Solutions | https://www.pengutronix.de/ |
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-03-23 9:14 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-23 6:53 [PATCH v1 0/2] Handle return value and remove unnecessary check Rayagonda Kokatanur
2020-03-23 6:53 ` [PATCH v1 1/2] pwm: bcm-iproc: handle clk_get_rate() return Rayagonda Kokatanur
2020-03-23 8:25 ` Uwe Kleine-König
2020-03-23 9:05 ` Rayagonda Kokatanur
2020-03-23 6:53 ` [PATCH v1 2/2] pwm: bcm-iproc: remove unnecessary check of 'duty' Rayagonda Kokatanur
2020-03-23 8:28 ` Uwe Kleine-König
2020-03-23 9:13 ` Rayagonda Kokatanur
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).