All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ray Jui <ray.jui@broadcom.com>
To: Scott Branden <scott.branden@broadcom.com>,
	Thierry Reding <thierry.reding@gmail.com>,
	Lee Jones <lee.jones@linaro.org>
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"BCM Kernel Feedback" <bcm-kernel-feedback-list@broadcom.com>,
	linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Rayagonda Kokatanur" <rayagonda.kokatanur@broadcom.com>
Subject: Re: [PATCH] pwm: bcm-iproc: handle clk_get_rate() return
Date: Fri, 17 Jul 2020 10:22:13 -0700	[thread overview]
Message-ID: <94f2aed1-d88d-3ee0-6e57-917f665951f2@broadcom.com> (raw)
In-Reply-To: <20200717170743.25466-1-scott.branden@broadcom.com>



On 7/17/2020 10:07 AM, Scott Branden wrote:
> From: Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>
> 
> 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>
> Signed-off-by: Scott Branden <scott.branden@broadcom.com>
> ---
>  drivers/pwm/pwm-bcm-iproc.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/pwm/pwm-bcm-iproc.c b/drivers/pwm/pwm-bcm-iproc.c
> index 1f829edd8ee7..72a8607b6c8d 100644
> --- a/drivers/pwm/pwm-bcm-iproc.c
> +++ b/drivers/pwm/pwm-bcm-iproc.c
> @@ -86,6 +86,11 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
>  	u32 value, prescale;
>  
>  	rate = clk_get_rate(ip->clk);
> +	if (rate == 0) {
> +		state->period = 0;
> +		state->duty_cycle = 0;
> +		return;
> +	}

Based on the pwm core code, 'get_state' expects the following fields to
be populated: 'polarity', 'enabled', 'period', and 'duty cycle'.

The above logic will leave 'polarity' and 'enabled' completely
unpopulated when clock rate is zero.

>  
>  	value = readl(ip->base + IPROC_PWM_CTRL_OFFSET);
>  
> 

  reply	other threads:[~2020-07-17 17:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-17 17:07 [PATCH] pwm: bcm-iproc: handle clk_get_rate() return Scott Branden
2020-07-17 17:22 ` Ray Jui [this message]
2020-07-17 18:24   ` Scott Branden

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=94f2aed1-d88d-3ee0-6e57-917f665951f2@broadcom.com \
    --to=ray.jui@broadcom.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=rayagonda.kokatanur@broadcom.com \
    --cc=scott.branden@broadcom.com \
    --cc=thierry.reding@gmail.com \
    --cc=u.kleine-koenig@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.