# Re: \[PATCH\] ftrace: Avoid potential division by zero in function\_stat\_show()

- From: Nikolay Kuratov \<hidden\>
- Date: 2025-02-06 08:57:22 
- List: linux-trace-kernel
- Page: https://ratatoskr.run/linux-trace-kernel/2025/02/2914170
- Thread: https://ratatoskr.run/linux-trace-kernel/2025/01/2907678/t.md

```text
I would suggest just fixing zerodiv for now because IMO the patch
fixing overflows properly on stddev path may or may not use macroconstants
at all. Also ns^2 overflow will always happen first. I don't know in advance
how this patch will look at the end and even not sure it's viable.
Steps to consider:
0) Infer some assumptions from the rest of tracing code like `nanoseconds
are stored in unsigned long, so on 32-bit machine function should not
execute more than ~ 2 s anyway`
1) unsigned long -> u64 conversion
2) ns^2 -> us^2 if possible, inevitable precision loss (how much?)
3) Compute stddev using some numerical trick. Now comment about Welford's
method is a bit misleading because its a plain variance formula. But maybe
it's a hint that we should convert to that method and problems are gone? ;)

I'll send the patch fixing zero division and simplifying code a bit as a
follow-up. It's up to you to choose what to apply. I'm Ok with any patch
fixing zerodiv and will look into overflow problem.

Again, thank you very much for the review and your time.
```
