From: Sinan Kaya <okaya@codeaurora.org>
To: linux-scsi@vger.kernel.org, timur@codeaurora.org,
cov@codeaurora.org, jcm@redhat.com
Cc: agross@codeaurora.org, linux-arm-msm@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
Sinan Kaya <okaya@codeaurora.org>,
Doug Gilbert <dgilbert@interlog.com>,
"James E.J. Bottomley" <JBottomley@odin.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH V2 2/3] scsi: fix compiler warning for sg
Date: Sun, 8 Nov 2015 20:57:45 -0500 [thread overview]
Message-ID: <1447034266-28003-3-git-send-email-okaya@codeaurora.org> (raw)
In-Reply-To: <1447034266-28003-1-git-send-email-okaya@codeaurora.org>
The MULDIV macro has been designed for small numbers.
Compiler emits an overflow warning on 64 bit systems.
This patch uses 64 bit numbers in order to suppress
warning.
Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
---
drivers/scsi/sg.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 9d7b7db..112d8974 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -51,6 +51,7 @@ static int sg_version_num = 30536; /* 2 digits for each component */
#include <linux/atomic.h>
#include <linux/ratelimit.h>
#include <linux/uio.h>
+#include <asm/div64.h>
#include "scsi.h"
#include <scsi/scsi_dbg.h>
@@ -85,12 +86,17 @@ static void sg_proc_cleanup(void);
* Replacing muldiv(x) by muldiv(x)=((x % d) * m) / d + int(x / d) * m
* calculates the same, but prevents the overflow when both m and d
* are "small" numbers (like HZ and USER_HZ).
- * Of course an overflow is inavoidable if the result of muldiv doesn't fit
- * in 32 bits.
*/
-#define MULDIV(X,MUL,DIV) ((((X % DIV) * MUL) / DIV) + ((X / DIV) * MUL))
+static inline u64 mult_frac64(u64 x, u32 numer, u32 denom)
+{
+ u64 r1 = do_div(x, denom);
+ u64 r2 = r1 * numer;
+
+ do_div(r2, denom);
+ return (x * numer) + r2;
+}
-#define SG_DEFAULT_TIMEOUT MULDIV(SG_DEFAULT_TIMEOUT_USER, HZ, USER_HZ)
+#define SG_DEFAULT_TIMEOUT mult_frac64(SG_DEFAULT_TIMEOUT_USER, HZ, USER_HZ)
int sg_big_buff = SG_DEF_RESERVED_SIZE;
/* N.B. This variable is readable and writeable via
@@ -877,10 +883,10 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
return result;
if (val < 0)
return -EIO;
- if (val >= MULDIV (INT_MAX, USER_HZ, HZ))
- val = MULDIV (INT_MAX, USER_HZ, HZ);
+ if (val >= mult_frac64(INT_MAX, USER_HZ, HZ))
+ val = mult_frac64(INT_MAX, USER_HZ, HZ);
sfp->timeout_user = val;
- sfp->timeout = MULDIV (val, HZ, USER_HZ);
+ sfp->timeout = mult_frac64(val, HZ, USER_HZ);
return 0;
case SG_GET_TIMEOUT: /* N.B. User receives timeout as return value */
--
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
next prev parent reply other threads:[~2015-11-09 1:57 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-09 1:57 [PATCH V2 0/3] scsi: mptxsas: updates for ARM64 Sinan Kaya
2015-11-09 1:57 ` [PATCH V2 1/3] scsi: mptxsas: try 64 bit DMA when 32 bit DMA fails Sinan Kaya
2015-11-09 7:09 ` Hannes Reinecke
2015-11-09 8:59 ` Arnd Bergmann
2015-11-09 14:07 ` Sinan Kaya
2015-11-09 14:33 ` Arnd Bergmann
2015-11-09 23:22 ` Sinan Kaya
2015-11-09 23:29 ` Timur Tabi
2015-11-10 8:38 ` Arnd Bergmann
2015-11-10 16:06 ` Sinan Kaya
2015-11-10 16:47 ` Arnd Bergmann
2015-11-10 17:00 ` Timur Tabi
2015-11-10 19:13 ` Arnd Bergmann
2015-11-10 21:03 ` Timur Tabi
2015-11-10 21:54 ` Arnd Bergmann
2015-11-10 21:59 ` Timur Tabi
2015-11-10 22:08 ` Arnd Bergmann
2015-11-10 17:19 ` Sinan Kaya
2015-11-10 18:27 ` James Bottomley
2015-11-10 19:14 ` Sinan Kaya
2015-11-10 19:43 ` James Bottomley
2015-11-10 19:56 ` Sinan Kaya
2015-11-10 20:05 ` James Bottomley
2015-11-10 20:26 ` Sinan Kaya
2015-11-10 20:35 ` James Bottomley
2015-11-10 19:56 ` Arnd Bergmann
2015-11-10 20:58 ` Sinan Kaya
2015-11-10 22:06 ` Arnd Bergmann
2015-11-09 14:00 ` Sinan Kaya
2015-11-09 1:57 ` Sinan Kaya [this message]
2015-11-09 14:14 ` [PATCH V2 2/3] scsi: fix compiler warning for sg Andy Shevchenko
2015-11-10 3:21 ` Sinan Kaya
2015-11-10 3:26 ` Timur Tabi
2015-11-10 4:51 ` Sinan Kaya
2015-11-10 4:53 ` Timur Tabi
2015-11-10 9:23 ` Andy Shevchenko
2015-11-10 10:09 ` Arnd Bergmann
2015-11-09 1:57 ` [PATCH V2 3/3] scsi: mptxsas: offload IRQ execution Sinan Kaya
2015-11-09 7:15 ` Hannes Reinecke
2015-11-09 14:01 ` Sinan Kaya
2015-11-10 5:59 ` Sinan Kaya
2016-03-16 15:31 ` Christopher Covington
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1447034266-28003-3-git-send-email-okaya@codeaurora.org \
--to=okaya@codeaurora.org \
--cc=JBottomley@odin.com \
--cc=agross@codeaurora.org \
--cc=cov@codeaurora.org \
--cc=dgilbert@interlog.com \
--cc=jcm@redhat.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=timur@codeaurora.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).