From: Jonathan Cameron <jic23@kernel.org>
To: Fabrice Gasnier <fabrice.gasnier@st.com>
Cc: <linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, <mcoquelin.stm32@gmail.com>,
<alexandre.torgue@st.com>, <benjamin.gaignard@st.com>,
<benjamin.gaignard@linaro.org>, <linux-iio@vger.kernel.org>,
<lars@metafoo.de>, <knaack.h@gmx.de>, <pmeerw@pmeerw.net>
Subject: Re: [PATCH] iio: adc: stm32: add check on clock rate
Date: Sat, 21 Oct 2017 17:55:40 +0100 [thread overview]
Message-ID: <20171021175540.075a1722@archlinux> (raw)
In-Reply-To: <1508326812-24297-1-git-send-email-fabrice.gasnier@st.com>
On Wed, 18 Oct 2017 13:40:12 +0200
Fabrice Gasnier <fabrice.gasnier@st.com> wrote:
> Add check on STM32 ADC clock rate to report an explicit error.
> This may avoid division by 0 later in stm32-adc driver.
>
> Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com>
I've applied this via the slow path for the next merge window as you haven't
explicitly highlighted it as a fix. If you want it to go through for stable
etc then let me know...
I have no idea if this can be triggered in sensibly configured system or not!
Thanks,
Jonathan
> ---
> drivers/iio/adc/stm32-adc-core.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/drivers/iio/adc/stm32-adc-core.c b/drivers/iio/adc/stm32-adc-core.c
> index 804198e..6aefef9 100644
> --- a/drivers/iio/adc/stm32-adc-core.c
> +++ b/drivers/iio/adc/stm32-adc-core.c
> @@ -139,6 +139,11 @@ static int stm32f4_adc_clk_sel(struct platform_device *pdev,
> }
>
> rate = clk_get_rate(priv->aclk);
> + if (!rate) {
> + dev_err(&pdev->dev, "Invalid clock rate: 0\n");
> + return -EINVAL;
> + }
> +
> for (i = 0; i < ARRAY_SIZE(stm32f4_pclk_div); i++) {
> if ((rate / stm32f4_pclk_div[i]) <= STM32F4_ADC_MAX_CLK_RATE)
> break;
> @@ -216,6 +221,10 @@ static int stm32h7_adc_clk_sel(struct platform_device *pdev,
> * From spec: PLL output musn't exceed max rate
> */
> rate = clk_get_rate(priv->aclk);
> + if (!rate) {
> + dev_err(&pdev->dev, "Invalid adc clock rate: 0\n");
> + return -EINVAL;
> + }
>
> for (i = 0; i < ARRAY_SIZE(stm32h7_adc_ckmodes_spec); i++) {
> ckmode = stm32h7_adc_ckmodes_spec[i].ckmode;
> @@ -232,6 +241,10 @@ static int stm32h7_adc_clk_sel(struct platform_device *pdev,
>
> /* Synchronous clock modes (e.g. ckmode is 1, 2 or 3) */
> rate = clk_get_rate(priv->bclk);
> + if (!rate) {
> + dev_err(&pdev->dev, "Invalid bus clock rate: 0\n");
> + return -EINVAL;
> + }
>
> for (i = 0; i < ARRAY_SIZE(stm32h7_adc_ckmodes_spec); i++) {
> ckmode = stm32h7_adc_ckmodes_spec[i].ckmode;
WARNING: multiple messages have this Message-ID (diff)
From: jic23@kernel.org (Jonathan Cameron)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] iio: adc: stm32: add check on clock rate
Date: Sat, 21 Oct 2017 17:55:40 +0100 [thread overview]
Message-ID: <20171021175540.075a1722@archlinux> (raw)
In-Reply-To: <1508326812-24297-1-git-send-email-fabrice.gasnier@st.com>
On Wed, 18 Oct 2017 13:40:12 +0200
Fabrice Gasnier <fabrice.gasnier@st.com> wrote:
> Add check on STM32 ADC clock rate to report an explicit error.
> This may avoid division by 0 later in stm32-adc driver.
>
> Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com>
I've applied this via the slow path for the next merge window as you haven't
explicitly highlighted it as a fix. If you want it to go through for stable
etc then let me know...
I have no idea if this can be triggered in sensibly configured system or not!
Thanks,
Jonathan
> ---
> drivers/iio/adc/stm32-adc-core.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/drivers/iio/adc/stm32-adc-core.c b/drivers/iio/adc/stm32-adc-core.c
> index 804198e..6aefef9 100644
> --- a/drivers/iio/adc/stm32-adc-core.c
> +++ b/drivers/iio/adc/stm32-adc-core.c
> @@ -139,6 +139,11 @@ static int stm32f4_adc_clk_sel(struct platform_device *pdev,
> }
>
> rate = clk_get_rate(priv->aclk);
> + if (!rate) {
> + dev_err(&pdev->dev, "Invalid clock rate: 0\n");
> + return -EINVAL;
> + }
> +
> for (i = 0; i < ARRAY_SIZE(stm32f4_pclk_div); i++) {
> if ((rate / stm32f4_pclk_div[i]) <= STM32F4_ADC_MAX_CLK_RATE)
> break;
> @@ -216,6 +221,10 @@ static int stm32h7_adc_clk_sel(struct platform_device *pdev,
> * From spec: PLL output musn't exceed max rate
> */
> rate = clk_get_rate(priv->aclk);
> + if (!rate) {
> + dev_err(&pdev->dev, "Invalid adc clock rate: 0\n");
> + return -EINVAL;
> + }
>
> for (i = 0; i < ARRAY_SIZE(stm32h7_adc_ckmodes_spec); i++) {
> ckmode = stm32h7_adc_ckmodes_spec[i].ckmode;
> @@ -232,6 +241,10 @@ static int stm32h7_adc_clk_sel(struct platform_device *pdev,
>
> /* Synchronous clock modes (e.g. ckmode is 1, 2 or 3) */
> rate = clk_get_rate(priv->bclk);
> + if (!rate) {
> + dev_err(&pdev->dev, "Invalid bus clock rate: 0\n");
> + return -EINVAL;
> + }
>
> for (i = 0; i < ARRAY_SIZE(stm32h7_adc_ckmodes_spec); i++) {
> ckmode = stm32h7_adc_ckmodes_spec[i].ckmode;
next prev parent reply other threads:[~2017-10-21 16:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-18 11:40 [PATCH] iio: adc: stm32: add check on clock rate Fabrice Gasnier
2017-10-18 11:40 ` Fabrice Gasnier
2017-10-21 16:55 ` Jonathan Cameron [this message]
2017-10-21 16:55 ` Jonathan Cameron
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=20171021175540.075a1722@archlinux \
--to=jic23@kernel.org \
--cc=alexandre.torgue@st.com \
--cc=benjamin.gaignard@linaro.org \
--cc=benjamin.gaignard@st.com \
--cc=fabrice.gasnier@st.com \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mcoquelin.stm32@gmail.com \
--cc=pmeerw@pmeerw.net \
/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.