Paul Burton
b9b6e80ad3
scsi: sg: Avoid overflow when USER_HZ > HZ
...
Calculating the maximum timeout that a user can set via the
SG_SET_TIMEOUT ioctl involves multiplying INT_MAX by USER_HZ/HZ. If
USER_HZ is larger than HZ then this results in an overflow when
performed as a 32 bit integer calculation, resulting in compiler
warnings such as the following:
drivers/scsi/sg.c: In function 'sg_ioctl':
drivers/scsi/sg.c:91:67: warning: integer overflow in expression [-Woverflow]
#define MULDIV(X,MUL,DIV) ((((X % DIV) * MUL) / DIV) + ((X / DIV) * MUL))
^
drivers/scsi/sg.c:887:14: note: in expansion of macro 'MULDIV'
if (val >= MULDIV (INT_MAX, USER_HZ, HZ))
^
drivers/scsi/sg.c:91:67: warning: integer overflow in expression [-Woverflow]
#define MULDIV(X,MUL,DIV) ((((X % DIV) * MUL) / DIV) + ((X / DIV) * MUL))
^
drivers/scsi/sg.c:888:13: note: in expansion of macro 'MULDIV'
val = MULDIV (INT_MAX, USER_HZ, HZ);
^
Avoid this overflow by performing the (constant) arithmetic on 64 bit
integers, which ensures that overflow from multiplying the 32 bit values
cannot occur. When converting the result back to a 32 bit integer use
min_t to ensure that we don't simply truncate a value beyond INT_MAX to
a 32 bit integer, but instead use INT_MAX where the result was larger
than it. As the values are all compile time constant the 64 bit
arithmetic should have no runtime cost.
Signed-off-by: Paul Burton <paul.burton@imgtec.com>
Acked-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2016-08-30 22:18:10 -04:00
..
2016-07-12 23:16:31 -04:00
2016-02-23 21:27:02 -05:00
2016-08-25 23:39:25 -04:00
2015-11-30 18:51:20 -05:00
2016-04-15 16:53:14 -04:00
2016-08-23 22:42:45 -04:00
2016-05-19 19:12:14 -07:00
2016-07-13 22:05:28 -04:00
2016-07-12 23:16:31 -04:00
2015-11-09 17:11:57 -08:00
2016-07-25 10:31:09 -07:00
2016-08-23 22:23:52 -04:00
2016-05-17 21:12:50 -04:00
2016-08-25 22:28:17 -04:00
2016-08-23 22:27:47 -04:00
2016-07-20 20:49:17 -04:00
2016-08-25 22:38:54 -04:00
2016-08-25 23:39:26 -04:00
2016-07-20 01:15:43 -07:00
2016-05-23 17:53:39 -07:00
2016-08-18 22:35:17 -04:00
2016-07-27 14:48:37 -07:00
2016-08-05 23:47:27 -04:00
2016-08-23 22:46:58 -04:00
2016-08-08 21:27:13 -04:00
2016-05-09 12:36:44 -04:00
2016-07-20 17:38:35 -06:00
2015-05-31 18:06:28 -07:00
2016-07-12 23:16:31 -04:00
2016-08-08 21:28:43 -04:00
2016-02-23 21:27:02 -05:00
2016-08-12 16:00:09 -04:00
2016-07-12 23:16:31 -04:00
2014-11-24 14:45:27 +01:00
2016-07-15 15:44:45 -04:00
2015-10-07 10:24:48 -07:00
2015-04-27 10:10:19 -07:00
2015-04-27 10:04:39 -07:00
2015-04-27 10:04:39 -07:00
2016-01-08 12:51:03 -05:00
2015-04-27 10:05:55 -07:00
2016-07-13 22:33:23 -04:00
2016-07-13 22:33:23 -04:00
2015-08-07 15:03:42 +02:00
2014-10-20 16:21:33 +02:00
2014-10-20 16:21:33 +02:00
2015-12-03 09:32:33 -08:00
2015-05-31 18:06:28 -07:00
2016-02-23 21:27:02 -05:00
2015-04-09 18:08:31 -07:00
2015-05-31 18:06:28 -07:00
2015-05-31 18:06:28 -07:00
2015-04-17 10:13:56 -07:00
2016-04-11 16:57:09 -04:00
2015-11-25 22:08:55 -05:00
2015-11-25 22:08:52 -05:00
2015-02-02 09:57:45 -08:00
2014-10-20 16:21:33 +02:00
2015-04-14 09:50:27 -07:00
2016-04-11 16:57:09 -04:00
2015-02-02 09:57:46 -08:00
2016-04-11 16:57:09 -04:00
2016-02-23 21:27:02 -05:00
2016-04-11 16:57:09 -04:00
2016-04-11 16:57:09 -04:00
2016-05-10 22:01:07 -04:00
2014-11-24 14:45:27 +01:00
2015-11-09 17:11:57 -08:00
2014-11-24 16:13:16 +01:00
2016-02-23 21:27:02 -05:00
2015-11-09 16:32:14 -08:00
2016-04-11 16:57:09 -04:00
2016-04-11 16:57:09 -04:00
2016-02-25 21:16:49 -05:00
2016-02-25 21:16:49 -05:00
2016-08-25 23:39:24 -04:00
2016-02-23 21:27:02 -05:00
2016-07-15 15:40:54 -04:00
2016-04-29 19:08:24 -04:00
2015-08-12 13:14:57 -07:00
2015-08-12 13:14:57 -07:00
2016-02-25 21:10:53 -05:00
2015-02-02 09:57:46 -08:00
2015-11-20 11:39:03 -05:00
2016-08-25 23:39:15 -04:00
2016-08-25 23:39:15 -04:00
2015-06-02 17:24:54 -07:00
2016-05-16 11:14:29 -04:00
2016-05-19 11:36:49 -07:00
2016-01-27 20:36:10 +08:00
2014-10-20 16:21:33 +02:00
2016-08-12 16:00:09 -04:00
2016-01-27 20:36:10 +08:00
2016-04-11 16:57:09 -04:00
2016-02-05 16:29:28 -06:00
2014-10-20 16:21:33 +02:00
2016-04-11 16:57:09 -04:00
2016-08-12 16:00:09 -04:00
2015-08-26 07:23:04 -07:00
2016-02-05 16:29:28 -06:00
2014-10-20 16:21:33 +02:00
2016-03-05 17:07:46 -05:00
2014-11-24 14:45:27 +01:00
2015-05-31 18:06:28 -07:00
2016-04-11 16:57:09 -04:00
2016-04-11 16:57:09 -04:00
2015-05-31 18:06:28 -07:00
2014-11-24 20:01:28 +01:00
2016-04-11 16:57:09 -04:00
2016-04-11 16:57:09 -04:00
2015-11-12 07:06:18 -05:00
2016-02-23 21:27:02 -05:00
2015-05-31 18:06:28 -07:00
2016-04-30 09:25:26 -07:00
2015-05-31 18:06:28 -07:00
2016-03-01 20:06:49 -05:00
2016-04-04 12:07:42 -04:00
2016-07-12 23:16:31 -04:00
2016-06-29 00:51:31 -04:00
2015-12-02 16:29:19 -05:00
2016-06-18 11:59:01 -07:00
2014-11-12 11:16:12 +01:00
2016-05-22 14:52:45 -04:00
2015-02-04 08:00:24 -08:00
2014-11-12 11:16:05 +01:00
2016-02-19 10:52:45 -05:00
2016-04-11 16:57:09 -04:00
2016-04-11 16:57:09 -04:00
2016-03-14 21:05:04 -04:00
2016-04-15 16:51:53 -04:00
2016-04-15 16:53:07 -04:00
2016-04-11 16:57:09 -04:00
2016-04-11 16:57:09 -04:00
2016-04-11 16:57:09 -04:00
2016-04-11 16:57:09 -04:00
2015-08-07 14:28:45 +02:00
2015-07-14 13:20:09 -04:00
2016-07-15 15:11:20 -04:00
2014-11-12 11:15:54 +01:00
2015-10-21 14:42:38 -06:00
2016-07-26 17:12:11 -07:00
2016-06-01 22:07:47 -04:00
2016-04-11 16:57:09 -04:00
2015-12-18 19:29:50 -08:00
2016-08-30 22:18:10 -04:00
2014-10-20 16:21:33 +02:00
2016-02-23 21:27:02 -05:00
2014-10-20 16:21:33 +02:00
2015-01-20 19:43:24 +01:00
2016-06-27 12:26:08 -07:00
2014-11-12 11:15:57 +01:00
2016-04-25 22:08:16 -04:00
2015-11-18 11:59:09 -05:00
2016-02-23 21:27:02 -05:00
2016-07-12 23:16:31 -04:00
2016-04-11 16:57:09 -04:00
2014-11-20 09:11:15 +01:00
2015-08-10 23:07:05 -04:00
2014-10-20 16:21:33 +02:00
2015-05-31 18:06:28 -07:00
2016-04-11 16:57:09 -04:00
2016-04-11 16:57:09 -04:00
2014-11-24 14:45:27 +01:00
2015-07-23 13:07:04 -07:00
2016-07-12 23:16:31 -04:00
2016-07-12 23:16:31 -04:00
2015-02-02 09:57:46 -08:00
2015-08-07 14:28:45 +02:00
2015-05-31 18:06:28 -07:00
2016-07-12 23:16:31 -04:00
2015-09-08 18:03:49 +01:00