coccinelle: semantic patch to check for inappropriate do_div() calls

do_div() does a 64-by-32 division.
When the divisor is unsigned long, u64, or s64,
do_div() truncates it to 32 bits, this means it
can test non-zero and be truncated to zero for division.
This semantic patch is inspired by Mateusz Guzik's patch:
commit b0ab99e7736a ("sched: Fix possible divide by zero in avg_atom() calculation")

Signed-off-by: Wen Yang <>
Signed-off-by: Julia Lawall <>
Cc: Gilles Muller <>
Cc: Nicolas Palix <>
Cc: Michal Marek <>
Cc: Matthias Maennich <>
Cc: Greg Kroah-Hartman <>
Cc: Masahiro Yamada <>
Cc: Thomas Gleixner <>
1 file changed