From 4c192665f0183150cff38b6954687752f3461e13 Mon Sep 17 00:00:00 2001 From: Bryan O'Donoghue Date: Tue, 11 Aug 2015 13:50:53 +0100 Subject: [PATCH] greybus: loopback: functionally decompose calculation of turn-around times We have a pattern similar to this over and over again gb->elapsed_nsecs = timeval_to_ns(&te) - timeval_to_ns(&ts); good software practice dictates we functionally decompose this. This patch decomposes into gb_loopback_calc_latency(). Signed-off-by: Bryan O'Donoghue Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/loopback.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/staging/greybus/loopback.c b/drivers/staging/greybus/loopback.c index 88c329afd3ea..ac38644c4a48 100644 --- a/drivers/staging/greybus/loopback.c +++ b/drivers/staging/greybus/loopback.c @@ -219,6 +219,16 @@ static struct attribute *loopback_attrs[] = { }; ATTRIBUTE_GROUPS(loopback); +static void gb_loopback_calc_latency(struct gb_loopback *gb, + struct timeval *ts, struct timeval *te) +{ + u64 t1, t2; + + t1 = timeval_to_ns(ts); + t2 = timeval_to_ns(te); + gb->elapsed_nsecs = t2 - t1; +} + static int gb_loopback_sink(struct gb_loopback *gb, u32 len) { struct timeval ts, te; @@ -236,7 +246,7 @@ static int gb_loopback_sink(struct gb_loopback *gb, u32 len) request, len + sizeof(*request), NULL, 0); do_gettimeofday(&te); - gb->elapsed_nsecs = timeval_to_ns(&te) - timeval_to_ns(&ts); + gb_loopback_calc_latency(gb, &ts, &te); kfree(request); return retval; @@ -265,7 +275,7 @@ static int gb_loopback_transfer(struct gb_loopback *gb, u32 len) request, len + sizeof(*request), response, len + sizeof(*response)); do_gettimeofday(&te); - gb->elapsed_nsecs = timeval_to_ns(&te) - timeval_to_ns(&ts); + gb_loopback_calc_latency(gb, &ts, &te); if (retval) goto gb_error; @@ -289,7 +299,7 @@ static int gb_loopback_ping(struct gb_loopback *gb) retval = gb_operation_sync(gb->connection, GB_LOOPBACK_TYPE_PING, NULL, 0, NULL, 0); do_gettimeofday(&te); - gb->elapsed_nsecs = timeval_to_ns(&te) - timeval_to_ns(&ts); + gb_loopback_calc_latency(gb, &ts, &te); return retval; } -- 2.20.1