* [PATCH] i2c: imx: fix divide by zero warning
@ 2024-11-25 14:15 carlos.song
2024-11-25 17:18 ` Frank Li
2024-12-05 12:49 ` Andi Shyti
0 siblings, 2 replies; 7+ messages in thread
From: carlos.song @ 2024-11-25 14:15 UTC (permalink / raw)
To: o.rempel, kernel, andi.shyti, shawnguo, s.hauer, festevam,
frank.li
Cc: linux-i2c, imx, linux-arm-kernel, linux-kernel
From: Carlos Song <carlos.song@nxp.com>
Add "i2c_clk_rate / 2" check to avoid "divide by zero warning".
i2c_clk_rate may be zero if i2c clock is disabled.
Signed-off-by: Carlos Song <carlos.song@nxp.com>
Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
---
drivers/i2c/busses/i2c-imx.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 2c782cdc26bd..5ed4cb61e262 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -623,8 +623,8 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
return 0;
}
-static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
- unsigned int i2c_clk_rate)
+static int i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
+ unsigned int i2c_clk_rate)
{
struct imx_i2c_clk_pair *i2c_clk_div = i2c_imx->hwdata->clk_div;
unsigned int div;
@@ -639,7 +639,11 @@ static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
/* Divider value calculation */
if (i2c_imx->cur_clk == i2c_clk_rate)
- return;
+ return 0;
+
+ /* Keep the denominator of the following program always NOT equal to 0. */
+ if (!(i2c_clk_rate / 2))
+ return -EINVAL;
i2c_imx->cur_clk = i2c_clk_rate;
@@ -670,6 +674,8 @@ static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
dev_dbg(&i2c_imx->adapter.dev, "IFDR[IC]=0x%x, REAL DIV=%d\n",
i2c_clk_div[i].val, i2c_clk_div[i].div);
#endif
+
+ return 0;
}
static int i2c_imx_clk_notifier_call(struct notifier_block *nb,
@@ -679,11 +685,12 @@ static int i2c_imx_clk_notifier_call(struct notifier_block *nb,
struct imx_i2c_struct *i2c_imx = container_of(nb,
struct imx_i2c_struct,
clk_change_nb);
+ int ret = 0;
if (action & POST_RATE_CHANGE)
- i2c_imx_set_clk(i2c_imx, ndata->new_rate);
+ ret = i2c_imx_set_clk(i2c_imx, ndata->new_rate);
- return NOTIFY_OK;
+ return notifier_from_errno(ret);
}
static int i2c_imx_start(struct imx_i2c_struct *i2c_imx, bool atomic)
@@ -1782,7 +1789,11 @@ static int i2c_imx_probe(struct platform_device *pdev)
i2c_imx->bitrate = pdata->bitrate;
i2c_imx->clk_change_nb.notifier_call = i2c_imx_clk_notifier_call;
clk_notifier_register(i2c_imx->clk, &i2c_imx->clk_change_nb);
- i2c_imx_set_clk(i2c_imx, clk_get_rate(i2c_imx->clk));
+ ret = i2c_imx_set_clk(i2c_imx, clk_get_rate(i2c_imx->clk));
+ if (ret < 0) {
+ dev_err(&pdev->dev, "can't get I2C clock\n");
+ goto clk_notifier_unregister;
+ }
i2c_imx_reset_regs(i2c_imx);
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH] i2c: imx: fix divide by zero warning
2024-11-25 14:15 [PATCH] i2c: imx: fix divide by zero warning carlos.song
@ 2024-11-25 17:18 ` Frank Li
2024-11-26 2:04 ` Carlos Song
2024-12-05 12:49 ` Andi Shyti
1 sibling, 1 reply; 7+ messages in thread
From: Frank Li @ 2024-11-25 17:18 UTC (permalink / raw)
To: carlos.song
Cc: o.rempel, kernel, andi.shyti, shawnguo, s.hauer, festevam,
linux-i2c, imx, linux-arm-kernel, linux-kernel
On Mon, Nov 25, 2024 at 10:15:21PM +0800, carlos.song@nxp.com wrote:
> From: Carlos Song <carlos.song@nxp.com>
>
> Add "i2c_clk_rate / 2" check to avoid "divide by zero warning".
> i2c_clk_rate may be zero if i2c clock is disabled.
>
> Signed-off-by: Carlos Song <carlos.song@nxp.com>
> Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
> Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
> ---
You sent this patch twice?
Reviewed-by: Frank Li <Frank.Li@nxp.com>
> drivers/i2c/busses/i2c-imx.c | 23 +++++++++++++++++------
> 1 file changed, 17 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index 2c782cdc26bd..5ed4cb61e262 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -623,8 +623,8 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
> return 0;
> }
>
> -static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
> - unsigned int i2c_clk_rate)
> +static int i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
> + unsigned int i2c_clk_rate)
> {
> struct imx_i2c_clk_pair *i2c_clk_div = i2c_imx->hwdata->clk_div;
> unsigned int div;
> @@ -639,7 +639,11 @@ static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
>
> /* Divider value calculation */
> if (i2c_imx->cur_clk == i2c_clk_rate)
> - return;
> + return 0;
> +
> + /* Keep the denominator of the following program always NOT equal to 0. */
> + if (!(i2c_clk_rate / 2))
> + return -EINVAL;
>
> i2c_imx->cur_clk = i2c_clk_rate;
>
> @@ -670,6 +674,8 @@ static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
> dev_dbg(&i2c_imx->adapter.dev, "IFDR[IC]=0x%x, REAL DIV=%d\n",
> i2c_clk_div[i].val, i2c_clk_div[i].div);
> #endif
> +
> + return 0;
> }
>
> static int i2c_imx_clk_notifier_call(struct notifier_block *nb,
> @@ -679,11 +685,12 @@ static int i2c_imx_clk_notifier_call(struct notifier_block *nb,
> struct imx_i2c_struct *i2c_imx = container_of(nb,
> struct imx_i2c_struct,
> clk_change_nb);
> + int ret = 0;
>
> if (action & POST_RATE_CHANGE)
> - i2c_imx_set_clk(i2c_imx, ndata->new_rate);
> + ret = i2c_imx_set_clk(i2c_imx, ndata->new_rate);
>
> - return NOTIFY_OK;
> + return notifier_from_errno(ret);
> }
>
> static int i2c_imx_start(struct imx_i2c_struct *i2c_imx, bool atomic)
> @@ -1782,7 +1789,11 @@ static int i2c_imx_probe(struct platform_device *pdev)
> i2c_imx->bitrate = pdata->bitrate;
> i2c_imx->clk_change_nb.notifier_call = i2c_imx_clk_notifier_call;
> clk_notifier_register(i2c_imx->clk, &i2c_imx->clk_change_nb);
> - i2c_imx_set_clk(i2c_imx, clk_get_rate(i2c_imx->clk));
> + ret = i2c_imx_set_clk(i2c_imx, clk_get_rate(i2c_imx->clk));
> + if (ret < 0) {
> + dev_err(&pdev->dev, "can't get I2C clock\n");
> + goto clk_notifier_unregister;
> + }
>
> i2c_imx_reset_regs(i2c_imx);
>
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 7+ messages in thread* RE: [PATCH] i2c: imx: fix divide by zero warning
2024-11-25 17:18 ` Frank Li
@ 2024-11-26 2:04 ` Carlos Song
2024-11-29 1:54 ` Wolfram Sang
0 siblings, 1 reply; 7+ messages in thread
From: Carlos Song @ 2024-11-26 2:04 UTC (permalink / raw)
To: Frank Li
Cc: o.rempel@pengutronix.de, kernel@pengutronix.de,
andi.shyti@kernel.org, shawnguo@kernel.org,
s.hauer@pengutronix.de, festevam@gmail.com,
linux-i2c@vger.kernel.org, imx@lists.linux.dev,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
> -----Original Message-----
> From: Frank Li <frank.li@nxp.com>
> Sent: Tuesday, November 26, 2024 1:18 AM
> To: Carlos Song <carlos.song@nxp.com>
> Cc: o.rempel@pengutronix.de; kernel@pengutronix.de; andi.shyti@kernel.org;
> shawnguo@kernel.org; s.hauer@pengutronix.de; festevam@gmail.com;
> linux-i2c@vger.kernel.org; imx@lists.linux.dev;
> linux-arm-kernel@lists.infradead.org; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH] i2c: imx: fix divide by zero warning
>
> On Mon, Nov 25, 2024 at 10:15:21PM +0800, carlos.song@nxp.com wrote:
> > From: Carlos Song <carlos.song@nxp.com>
> >
> > Add "i2c_clk_rate / 2" check to avoid "divide by zero warning".
> > i2c_clk_rate may be zero if i2c clock is disabled.
> >
> > Signed-off-by: Carlos Song <carlos.song@nxp.com>
> > Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
> > Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
> > ---
>
> You sent this patch twice?
>
Yes, because I meet a net error, I send the patch out and wait for a half of hour, but I don't see the mail in the mail list, so I send it again, but another one come in
after 1 hour.. You can dismiss the same one.
> Reviewed-by: Frank Li <Frank.Li@nxp.com>
>
> > drivers/i2c/busses/i2c-imx.c | 23 +++++++++++++++++------
> > 1 file changed, 17 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/i2c/busses/i2c-imx.c
> > b/drivers/i2c/busses/i2c-imx.c index 2c782cdc26bd..5ed4cb61e262 100644
> > --- a/drivers/i2c/busses/i2c-imx.c
> > +++ b/drivers/i2c/busses/i2c-imx.c
> > @@ -623,8 +623,8 @@ static int i2c_imx_acked(struct imx_i2c_struct
> *i2c_imx)
> > return 0;
> > }
> >
> > -static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
> > - unsigned int i2c_clk_rate)
> > +static int i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
> > + unsigned int i2c_clk_rate)
> > {
> > struct imx_i2c_clk_pair *i2c_clk_div = i2c_imx->hwdata->clk_div;
> > unsigned int div;
> > @@ -639,7 +639,11 @@ static void i2c_imx_set_clk(struct imx_i2c_struct
> > *i2c_imx,
> >
> > /* Divider value calculation */
> > if (i2c_imx->cur_clk == i2c_clk_rate)
> > - return;
> > + return 0;
> > +
> > + /* Keep the denominator of the following program always NOT equal to 0.
> */
> > + if (!(i2c_clk_rate / 2))
> > + return -EINVAL;
> >
> > i2c_imx->cur_clk = i2c_clk_rate;
> >
> > @@ -670,6 +674,8 @@ static void i2c_imx_set_clk(struct imx_i2c_struct
> *i2c_imx,
> > dev_dbg(&i2c_imx->adapter.dev, "IFDR[IC]=0x%x, REAL DIV=%d\n",
> > i2c_clk_div[i].val, i2c_clk_div[i].div); #endif
> > +
> > + return 0;
> > }
> >
> > static int i2c_imx_clk_notifier_call(struct notifier_block *nb, @@
> > -679,11 +685,12 @@ static int i2c_imx_clk_notifier_call(struct notifier_block
> *nb,
> > struct imx_i2c_struct *i2c_imx = container_of(nb,
> > struct imx_i2c_struct,
> > clk_change_nb);
> > + int ret = 0;
> >
> > if (action & POST_RATE_CHANGE)
> > - i2c_imx_set_clk(i2c_imx, ndata->new_rate);
> > + ret = i2c_imx_set_clk(i2c_imx, ndata->new_rate);
> >
> > - return NOTIFY_OK;
> > + return notifier_from_errno(ret);
> > }
> >
> > static int i2c_imx_start(struct imx_i2c_struct *i2c_imx, bool atomic)
> > @@ -1782,7 +1789,11 @@ static int i2c_imx_probe(struct platform_device
> *pdev)
> > i2c_imx->bitrate = pdata->bitrate;
> > i2c_imx->clk_change_nb.notifier_call = i2c_imx_clk_notifier_call;
> > clk_notifier_register(i2c_imx->clk, &i2c_imx->clk_change_nb);
> > - i2c_imx_set_clk(i2c_imx, clk_get_rate(i2c_imx->clk));
> > + ret = i2c_imx_set_clk(i2c_imx, clk_get_rate(i2c_imx->clk));
> > + if (ret < 0) {
> > + dev_err(&pdev->dev, "can't get I2C clock\n");
> > + goto clk_notifier_unregister;
> > + }
> >
> > i2c_imx_reset_regs(i2c_imx);
> >
> > --
> > 2.34.1
> >
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] i2c: imx: fix divide by zero warning
2024-11-26 2:04 ` Carlos Song
@ 2024-11-29 1:54 ` Wolfram Sang
2024-11-29 2:23 ` Carlos Song
0 siblings, 1 reply; 7+ messages in thread
From: Wolfram Sang @ 2024-11-29 1:54 UTC (permalink / raw)
To: Carlos Song
Cc: Frank Li, o.rempel@pengutronix.de, kernel@pengutronix.de,
andi.shyti@kernel.org, shawnguo@kernel.org,
s.hauer@pengutronix.de, festevam@gmail.com,
linux-i2c@vger.kernel.org, imx@lists.linux.dev,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
[-- Attachment #1: Type: text/plain, Size: 380 bytes --]
> > You sent this patch twice?
> >
> Yes, because I meet a net error, I send the patch out and wait for a
> half of hour, but I don't see the mail in the mail list, so I send it
> again, but another one come in after 1 hour.. You can dismiss the same
> one.
You can also check 'http://patchwork.ozlabs.org/project/linux-i2c/list/'
to see if it made it to the list.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] i2c: imx: fix divide by zero warning
2024-11-29 1:54 ` Wolfram Sang
@ 2024-11-29 2:23 ` Carlos Song
0 siblings, 0 replies; 7+ messages in thread
From: Carlos Song @ 2024-11-29 2:23 UTC (permalink / raw)
To: Wolfram Sang
Cc: Frank Li, o.rempel@pengutronix.de, kernel@pengutronix.de,
andi.shyti@kernel.org, shawnguo@kernel.org,
s.hauer@pengutronix.de, festevam@gmail.com,
linux-i2c@vger.kernel.org, imx@lists.linux.dev,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
> -----Original Message-----
> From: Wolfram Sang <wsa+renesas@sang-engineering.com>
> Sent: Friday, November 29, 2024 9:55 AM
> To: Carlos Song <carlos.song@nxp.com>
> Cc: Frank Li <frank.li@nxp.com>; o.rempel@pengutronix.de;
> kernel@pengutronix.de; andi.shyti@kernel.org; shawnguo@kernel.org;
> s.hauer@pengutronix.de; festevam@gmail.com; linux-i2c@vger.kernel.org;
> imx@lists.linux.dev; linux-arm-kernel@lists.infradead.org;
> linux-kernel@vger.kernel.org
> Subject: [EXT] Re: [PATCH] i2c: imx: fix divide by zero warning
>
>
> > > You sent this patch twice?
> > >
> > Yes, because I meet a net error, I send the patch out and wait for a
> > half of hour, but I don't see the mail in the mail list, so I send it
> > again, but another one come in after 1 hour.. You can dismiss the same
> > one.
>
> You can also check 'http://patchwork.ozlabs.org/project/linux-i2c/list/'
> to see if it made it to the list.
Thank you! I will check it when I meet issue next time:).
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] i2c: imx: fix divide by zero warning
2024-11-25 14:15 [PATCH] i2c: imx: fix divide by zero warning carlos.song
2024-11-25 17:18 ` Frank Li
@ 2024-12-05 12:49 ` Andi Shyti
1 sibling, 0 replies; 7+ messages in thread
From: Andi Shyti @ 2024-12-05 12:49 UTC (permalink / raw)
To: carlos.song
Cc: o.rempel, kernel, shawnguo, s.hauer, festevam, frank.li,
linux-i2c, imx, linux-arm-kernel, linux-kernel
Hi Carlos,
On Mon, Nov 25, 2024 at 10:15:21PM +0800, carlos.song@nxp.com wrote:
> From: Carlos Song <carlos.song@nxp.com>
>
> Add "i2c_clk_rate / 2" check to avoid "divide by zero warning".
> i2c_clk_rate may be zero if i2c clock is disabled.
>
> Signed-off-by: Carlos Song <carlos.song@nxp.com>
> Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
> Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
merged to i2c/i2c-host,
thanks,
Andi
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] i2c: imx: fix divide by zero warning
@ 2024-11-25 13:50 carlos.song
0 siblings, 0 replies; 7+ messages in thread
From: carlos.song @ 2024-11-25 13:50 UTC (permalink / raw)
To: o.rempel, kernel, andi.shyti, shawnguo, s.hauer, festevam,
frank.li
Cc: linux-i2c, imx, linux-arm-kernel, linux-kernel
From: Carlos Song <carlos.song@nxp.com>
Add "i2c_clk_rate / 2" check to avoid "divide by zero warning".
i2c_clk_rate may be zero if i2c clock is disabled.
Signed-off-by: Carlos Song <carlos.song@nxp.com>
Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
---
drivers/i2c/busses/i2c-imx.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 2c782cdc26bd..5ed4cb61e262 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -623,8 +623,8 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
return 0;
}
-static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
- unsigned int i2c_clk_rate)
+static int i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
+ unsigned int i2c_clk_rate)
{
struct imx_i2c_clk_pair *i2c_clk_div = i2c_imx->hwdata->clk_div;
unsigned int div;
@@ -639,7 +639,11 @@ static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
/* Divider value calculation */
if (i2c_imx->cur_clk == i2c_clk_rate)
- return;
+ return 0;
+
+ /* Keep the denominator of the following program always NOT equal to 0. */
+ if (!(i2c_clk_rate / 2))
+ return -EINVAL;
i2c_imx->cur_clk = i2c_clk_rate;
@@ -670,6 +674,8 @@ static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
dev_dbg(&i2c_imx->adapter.dev, "IFDR[IC]=0x%x, REAL DIV=%d\n",
i2c_clk_div[i].val, i2c_clk_div[i].div);
#endif
+
+ return 0;
}
static int i2c_imx_clk_notifier_call(struct notifier_block *nb,
@@ -679,11 +685,12 @@ static int i2c_imx_clk_notifier_call(struct notifier_block *nb,
struct imx_i2c_struct *i2c_imx = container_of(nb,
struct imx_i2c_struct,
clk_change_nb);
+ int ret = 0;
if (action & POST_RATE_CHANGE)
- i2c_imx_set_clk(i2c_imx, ndata->new_rate);
+ ret = i2c_imx_set_clk(i2c_imx, ndata->new_rate);
- return NOTIFY_OK;
+ return notifier_from_errno(ret);
}
static int i2c_imx_start(struct imx_i2c_struct *i2c_imx, bool atomic)
@@ -1782,7 +1789,11 @@ static int i2c_imx_probe(struct platform_device *pdev)
i2c_imx->bitrate = pdata->bitrate;
i2c_imx->clk_change_nb.notifier_call = i2c_imx_clk_notifier_call;
clk_notifier_register(i2c_imx->clk, &i2c_imx->clk_change_nb);
- i2c_imx_set_clk(i2c_imx, clk_get_rate(i2c_imx->clk));
+ ret = i2c_imx_set_clk(i2c_imx, clk_get_rate(i2c_imx->clk));
+ if (ret < 0) {
+ dev_err(&pdev->dev, "can't get I2C clock\n");
+ goto clk_notifier_unregister;
+ }
i2c_imx_reset_regs(i2c_imx);
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-12-05 12:49 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-25 14:15 [PATCH] i2c: imx: fix divide by zero warning carlos.song
2024-11-25 17:18 ` Frank Li
2024-11-26 2:04 ` Carlos Song
2024-11-29 1:54 ` Wolfram Sang
2024-11-29 2:23 ` Carlos Song
2024-12-05 12:49 ` Andi Shyti
-- strict thread matches above, loose matches on Subject: below --
2024-11-25 13:50 carlos.song
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox