* [PATCH] net: ethernet: ti: Prevent divide-by-zero in cpts_calc_mult_shift()
@ 2025-08-28 9:22 Miaoqian Lin
2025-08-28 9:28 ` Greg Kroah-Hartman
2025-08-28 12:05 ` Vadim Fedorenko
0 siblings, 2 replies; 5+ messages in thread
From: Miaoqian Lin @ 2025-08-28 9:22 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Matthias Brugger, AngeloGioacchino Del Regno,
Greg Kroah-Hartman, Thomas Gleixner, Grygorii Strashko, netdev,
linux-kernel, linux-arm-kernel, linux-mediatek
Cc: linmq006
cpts_calc_mult_shift() has a potential divide-by-zero in this line:
do_div(maxsec, freq);
due to the fact that clk_get_rate() can return zero in certain error
conditions.
Add an explicit check to fix this.
Fixes: 88f0f0b0bebf ("net: ethernet: ti: cpts: calc mult and shift from refclk freq")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
This follows the same pattern as the fix in commit 7ca59947b5fc
("pwm: mediatek: Prevent divide-by-zero in pwm_mediatek_config()").
---
drivers/net/ethernet/ti/cpts.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c
index 2ba4c8795d60..e4e3409e7648 100644
--- a/drivers/net/ethernet/ti/cpts.c
+++ b/drivers/net/ethernet/ti/cpts.c
@@ -607,6 +607,8 @@ static void cpts_calc_mult_shift(struct cpts *cpts)
u32 freq;
freq = clk_get_rate(cpts->refclk);
+ if (!freq)
+ return;
/* Calc the maximum number of seconds which we can run before
* wrapping around.
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] net: ethernet: ti: Prevent divide-by-zero in cpts_calc_mult_shift()
2025-08-28 9:22 [PATCH] net: ethernet: ti: Prevent divide-by-zero in cpts_calc_mult_shift() Miaoqian Lin
@ 2025-08-28 9:28 ` Greg Kroah-Hartman
2025-08-28 12:05 ` Vadim Fedorenko
1 sibling, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2025-08-28 9:28 UTC (permalink / raw)
To: Miaoqian Lin
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Matthias Brugger, AngeloGioacchino Del Regno,
Thomas Gleixner, Grygorii Strashko, netdev, linux-kernel,
linux-arm-kernel, linux-mediatek
On Thu, Aug 28, 2025 at 05:22:23PM +0800, Miaoqian Lin wrote:
> cpts_calc_mult_shift() has a potential divide-by-zero in this line:
>
> do_div(maxsec, freq);
>
> due to the fact that clk_get_rate() can return zero in certain error
> conditions.
> Add an explicit check to fix this.
>
> Fixes: 88f0f0b0bebf ("net: ethernet: ti: cpts: calc mult and shift from refclk freq")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
> This follows the same pattern as the fix in commit 7ca59947b5fc
> ("pwm: mediatek: Prevent divide-by-zero in pwm_mediatek_config()").
> ---
> drivers/net/ethernet/ti/cpts.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c
> index 2ba4c8795d60..e4e3409e7648 100644
> --- a/drivers/net/ethernet/ti/cpts.c
> +++ b/drivers/net/ethernet/ti/cpts.c
> @@ -607,6 +607,8 @@ static void cpts_calc_mult_shift(struct cpts *cpts)
> u32 freq;
>
> freq = clk_get_rate(cpts->refclk);
> + if (!freq)
> + return;
>
> /* Calc the maximum number of seconds which we can run before
> * wrapping around.
> --
> 2.39.5 (Apple Git-154)
>
Hi,
This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him
a patch that has triggered this response. He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created. Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.
You are receiving this message because of the following common error(s)
as indicated below:
- You have marked a patch with a "Fixes:" tag for a commit that is in an
older released kernel, yet you do not have a cc: stable line in the
signed-off-by area at all, which means that the patch will not be
applied to any older kernel releases. To properly fix this, please
follow the documented rules in the
Documentation/process/stable-kernel-rules.rst file for how to resolve
this.
If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.
thanks,
greg k-h's patch email bot
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] net: ethernet: ti: Prevent divide-by-zero in cpts_calc_mult_shift()
2025-08-28 9:22 [PATCH] net: ethernet: ti: Prevent divide-by-zero in cpts_calc_mult_shift() Miaoqian Lin
2025-08-28 9:28 ` Greg Kroah-Hartman
@ 2025-08-28 12:05 ` Vadim Fedorenko
2025-08-28 12:38 ` 林妙倩
1 sibling, 1 reply; 5+ messages in thread
From: Vadim Fedorenko @ 2025-08-28 12:05 UTC (permalink / raw)
To: Miaoqian Lin, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Matthias Brugger,
AngeloGioacchino Del Regno, Thomas Gleixner, Grygorii Strashko,
netdev, linux-kernel, linux-arm-kernel, linux-mediatek
On 28/08/2025 10:22, Miaoqian Lin wrote:
> cpts_calc_mult_shift() has a potential divide-by-zero in this line:
>
> do_div(maxsec, freq);
>
> due to the fact that clk_get_rate() can return zero in certain error
> conditions.
Have you seen this happening in the real environment, or is it just
analysis of the code? I don't see a reason for these "certain error
conditions" to happen...
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] net: ethernet: ti: Prevent divide-by-zero in cpts_calc_mult_shift()
2025-08-28 12:05 ` Vadim Fedorenko
@ 2025-08-28 12:38 ` 林妙倩
2025-08-28 13:01 ` Vadim Fedorenko
0 siblings, 1 reply; 5+ messages in thread
From: 林妙倩 @ 2025-08-28 12:38 UTC (permalink / raw)
To: Vadim Fedorenko
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Matthias Brugger, AngeloGioacchino Del Regno,
Thomas Gleixner, Grygorii Strashko, netdev, linux-kernel,
linux-arm-kernel, linux-mediatek
Hi, Vadim
Vadim Fedorenko <vadim.fedorenko@linux.dev> 于2025年8月28日周四 20:06写道:
>
> On 28/08/2025 10:22, Miaoqian Lin wrote:
> > cpts_calc_mult_shift() has a potential divide-by-zero in this line:
> >
> > do_div(maxsec, freq);
> >
> > due to the fact that clk_get_rate() can return zero in certain error
> > conditions.
>
> Have you seen this happening in the real environment, or is it just
> analysis of the code? I don't see a reason for these "certain error
> conditions" to happen...
This is from code analysis, not from real environment.
The !CONFIG_HAVE_CLK version of clk_get_rate() returns zero.
With CONFIG_COMPILE_TEST && !CONFIG_HAVE_CLK could have the problem.
This may be theoretical.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] net: ethernet: ti: Prevent divide-by-zero in cpts_calc_mult_shift()
2025-08-28 12:38 ` 林妙倩
@ 2025-08-28 13:01 ` Vadim Fedorenko
0 siblings, 0 replies; 5+ messages in thread
From: Vadim Fedorenko @ 2025-08-28 13:01 UTC (permalink / raw)
To: 林妙倩
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Matthias Brugger, AngeloGioacchino Del Regno,
Thomas Gleixner, Grygorii Strashko, netdev, linux-kernel,
linux-arm-kernel, linux-mediatek
On 28/08/2025 13:38, æå¦å© wrote:
> Hi, Vadim
>
> Vadim Fedorenko <vadim.fedorenko@linux.dev> 于2025年8月28日周四 20:06写道:
>>
>> On 28/08/2025 10:22, Miaoqian Lin wrote:
>>> cpts_calc_mult_shift() has a potential divide-by-zero in this line:
>>>
>>> do_div(maxsec, freq);
>>>
>>> due to the fact that clk_get_rate() can return zero in certain error
>>> conditions.
>>
>> Have you seen this happening in the real environment, or is it just
>> analysis of the code? I don't see a reason for these "certain error
>> conditions" to happen...
>
> This is from code analysis, not from real environment.
> The !CONFIG_HAVE_CLK version of clk_get_rate() returns zero.
> With CONFIG_COMPILE_TEST && !CONFIG_HAVE_CLK could have the problem.
> This may be theoretical.
!CONFIG_HAVE_CLK will have cpts_create() doing nothing as defined in
cpts.h and it means the patch fixes impossible scenario.
NAck
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-08-28 17:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-28 9:22 [PATCH] net: ethernet: ti: Prevent divide-by-zero in cpts_calc_mult_shift() Miaoqian Lin
2025-08-28 9:28 ` Greg Kroah-Hartman
2025-08-28 12:05 ` Vadim Fedorenko
2025-08-28 12:38 ` 林妙倩
2025-08-28 13:01 ` Vadim Fedorenko
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).