Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: greybus/timesync: avoid divide by zero on X86 Qemu

A system configured without CONFIG_CPUFREQ will return 0 for cpufreq_get().
greybus-timesync can subsequently then do a divide-by-zero as result. This
patch fixes by checking for a zero return value from cpufreq_get() and
setting to a default value of 19.2MHz.

Reported-by: Rui Miguel Silva <rmfrfs@gmail.com>
Signed-off-by: Bryan O'Donoghue <pure.logic@nexus-software.ie>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Bryan O'Donoghue and committed by
Greg Kroah-Hartman
659849cd 3d7f3588

+7 -2
+7 -2
drivers/staging/greybus/timesync_platform.c
··· 20 20 #include "greybus.h" 21 21 #include "arche_platform.h" 22 22 23 + #define DEFAULT_FRAMETIME_CLOCK_HZ 19200000 24 + 23 25 static u32 gb_timesync_clock_frequency; 24 26 int (*arche_platform_change_state_cb)(enum arche_platform_state state, 25 27 struct gb_timesync_svc *pdata); ··· 34 32 35 33 u32 gb_timesync_platform_get_clock_rate(void) 36 34 { 37 - if (unlikely(!gb_timesync_clock_frequency)) 38 - return cpufreq_get(0); 35 + if (unlikely(!gb_timesync_clock_frequency)) { 36 + gb_timesync_clock_frequency = cpufreq_get(0); 37 + if (!gb_timesync_clock_frequency) 38 + gb_timesync_clock_frequency = DEFAULT_FRAMETIME_CLOCK_HZ; 39 + } 39 40 40 41 return gb_timesync_clock_frequency; 41 42 }