From 3f818ef30e4a8ae756f43890c9f3738a514fa89e Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Thu, 12 Nov 2015 22:17:59 +0000 Subject: [PATCH] scst_lib: Avoid using 64-bit divisions Reported-by: Sebastian Herbszt git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6686 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_lib.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index c026d02e0..8cd269cc7 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -6131,11 +6131,12 @@ static int scst_ws_sg_init(struct scatterlist **ws_sg, int ws_sg_cnt, static int scst_ws_sg_tails_get(struct scst_data_descriptor *where, struct scst_write_same_priv *wsp) { int i; + uint64_t n; TRACE_ENTRY(); for (i = 0; where[i].sdd_blocks != 0; i++) { - if (where[i].sdd_blocks / wsp->ws_max_each != 0) { + if (where[i].sdd_blocks >= wsp->ws_max_each) { wsp->ws_sg_full_cnt = wsp->ws_max_each; break; } @@ -6150,8 +6151,10 @@ static int scst_ws_sg_tails_get(struct scst_data_descriptor *where, struct scst_ sizeof(*wsp->ws_sg_tails)*i); return -ENOMEM; } - for (i = 0; where[i].sdd_blocks != 0; i++) - wsp->ws_sg_tails[i].sg_cnt = where[i].sdd_blocks % wsp->ws_max_each; + for (i = 0; where[i].sdd_blocks != 0; i++) { + n = where[i].sdd_blocks; + wsp->ws_sg_tails[i].sg_cnt = do_div(n, wsp->ws_max_each); + } TRACE_EXIT(); return 0;