Commit 1ffc12be authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman

greybus: loopback: fix 64-bit divisions

The code uses 64-bit divisions, which should be avoided, and also
prevents the module from loading on 32-bit systems:

	gb_loopback: Unknown symbol __aeabi_uldivmod (err 0)

Fix by using the kernel's 64-bit by 32-bit division implementation
do_div.

Compile tested only. I did not look very closely at the code itself.
Perhaps this could be worked around in some other way, but this silences
the linker warning and allows the module to be loaded.
Reviewed-by: default avatarAlex Elder <elder@linaro.org>
Signed-off-by: default avatarJohan Hovold <johan@hovoldconsulting.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent dcd1dadd
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/random.h> #include <linux/random.h>
#include <linux/sizes.h> #include <linux/sizes.h>
#include <asm/div64.h>
#include "greybus.h" #include "greybus.h"
struct gb_loopback_stats { struct gb_loopback_stats {
...@@ -248,12 +250,16 @@ static void gb_loopback_update_stats(struct gb_loopback_stats *stats, ...@@ -248,12 +250,16 @@ static void gb_loopback_update_stats(struct gb_loopback_stats *stats,
u64 elapsed_nsecs) u64 elapsed_nsecs)
{ {
u32 avg; u32 avg;
u64 tmp;
if (elapsed_nsecs >= NSEC_PER_SEC) { if (elapsed_nsecs >= NSEC_PER_SEC) {
if (!stats->count) if (!stats->count) {
avg = stats->sum * (elapsed_nsecs / NSEC_PER_SEC); tmp = elapsed_nsecs;
else do_div(tmp, NSEC_PER_SEC);
avg = stats->sum * tmp;
} else {
avg = stats->sum / stats->count; avg = stats->sum / stats->count;
}
if (stats->min > avg) if (stats->min > avg)
stats->min = avg; stats->min = avg;
if (stats->max < avg) if (stats->max < avg)
...@@ -281,10 +287,11 @@ static void gb_loopback_latency_update(struct gb_loopback *gb, ...@@ -281,10 +287,11 @@ static void gb_loopback_latency_update(struct gb_loopback *gb,
struct timeval *tlat) struct timeval *tlat)
{ {
u32 lat; u32 lat;
u64 nsecs; u64 tmp;
nsecs = timeval_to_ns(tlat); tmp = timeval_to_ns(tlat);
lat = nsecs / NSEC_PER_MSEC; do_div(tmp, NSEC_PER_MSEC);
lat = tmp;
if (gb->latency.min > lat) if (gb->latency.min > lat)
gb->latency.min = lat; gb->latency.min = lat;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment