From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759153AbbIDM4j (ORCPT ); Fri, 4 Sep 2015 08:56:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59537 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758680AbbIDM4h (ORCPT ); Fri, 4 Sep 2015 08:56:37 -0400 From: Vitaly Kuznetsov To: Andrew Morton Cc: Andy Shevchenko , Rasmus Villemoes , James Bottomley , linux-kernel@vger.kernel.org, "K. Y. Srinivasan" Subject: [PATCH] lib/string_helpers.c: fix infinite loop in string_get_size() Date: Fri, 4 Sep 2015 14:56:33 +0200 Message-Id: <1441371393-15030-1-git-send-email-vkuznets@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org string_get_size(1, 512, 0, ..., ...) call results in an infinite loop. The problem is that if size == 0 when we start calculating sf_cap this loop will never end. The caller causing the issue is sd_read_capacity(), the problem was noticed on Hyper-V. Signed-off-by: Vitaly Kuznetsov --- lib/string_helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/string_helpers.c b/lib/string_helpers.c index c98ae81..a155c7b 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -76,7 +76,7 @@ void string_get_size(u64 size, u64 blk_size, const enum string_size_units units, i++; } - sf_cap = size; + sf_cap = size ? size : 1; for (j = 0; sf_cap*10 < 1000; j++) sf_cap *= 10; -- 2.4.3