Vitaly Kuznetsov 62bef58a55 lib/string_helpers.c: fix infinite loop in string_get_size()
Some string_get_size() calls (e.g.:
 string_get_size(1, 512, STRING_UNITS_10, ..., ...)
 string_get_size(15, 64, STRING_UNITS_10, ..., ...)
) result in an infinite loop. The problem is that if size is equal to
divisor[units]/blk_size and is smaller than divisor[units] we'll end
up with size == 0 when we start doing sf_cap calculations:

For string_get_size(1, 512, STRING_UNITS_10, ..., ...) case:
   ...
   remainder = do_div(size, divisor[units]); -> size is 0, remainder is 1
   remainder *= blk_size; -> remainder is 512
   ...
   size *= blk_size; -> size is still 0
   size += remainder / divisor[units]; -> size is still 0

The caller causing the issue is sd_read_capacity(), the problem was
noticed on Hyper-V, such weird size was reported by host when scanning
collides with device removal.  This is probably a separate issue worth
fixing, this patch is intended to prevent the library routine from
infinite looping.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Acked-by: James Bottomley <JBottomley@Odin.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: "K. Y. Srinivasan" <kys@microsoft.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-09-17 21:16:07 -07:00
..
2014-10-09 11:35:48 +03:00
2015-08-25 21:13:16 +08:00
2015-07-27 14:06:24 +02:00
2011-03-11 14:25:50 +00:00
2015-05-28 11:31:52 +09:30
2011-10-29 21:20:22 +02:00
2014-04-30 19:49:37 +01:00
2012-10-06 03:04:57 +09:00
2014-08-06 18:01:25 -07:00
2015-02-12 18:54:15 -08:00
2015-07-17 16:39:53 -07:00
2015-02-12 18:54:15 -08:00
2014-05-05 09:09:14 +02:00
2015-09-08 14:35:59 -07:00
2014-08-08 15:57:25 -07:00
2015-07-28 08:50:42 +01:00
2015-02-12 18:54:15 -08:00
2015-02-12 18:54:15 -08:00
2012-07-30 17:25:16 -07:00
2014-06-25 17:45:43 -07:00
2015-09-08 14:35:59 -07:00
2015-02-12 18:54:16 -08:00
2015-03-23 22:12:08 -04:00
2015-06-25 17:00:40 -07:00
2015-06-25 17:00:40 -07:00
2013-04-29 18:28:42 -07:00
2015-07-20 10:52:48 -07:00