Re: [PATCH] ftrace: Avoid potential division by zero in function_stat_show()
From: Nikolay Kuratov
Date: Tue Feb 04 2025 - 02:46:34 EST
Thank you for the review!
`counter > rec->counter` check does not protect us from overflows,
so this could mislead especially with the comment included.
I think we should either eliminate overflows or only protect from zero
division. To prevent overflows it is wise to split the division into
three and forget about it. But in 32-bit case overflows will still occur.
As for zero division protection, maybe this variant even more concise?
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
seq_puts(m, " ");
stddev = 0;
unsigned long denom = rec->counter * (rec->counter - 1) * 1000;
if (denom) {
stddev = rec->counter * rec->time_squared -
rec->time * rec->time;
stddev = div64_ul(stddev, denom);
}
trace_seq_init(&s);
trace_print_graph_duration(rec->time, &s);
--
My last attempt to get this email into lore with git-send-email, since
no luck with mutt. Sorry if you see this message twice or thrice in your
inbox. It won't happen again.