From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758038AbbJ2XAt (ORCPT ); Thu, 29 Oct 2015 19:00:49 -0400 Received: from mx2.parallels.com ([199.115.105.18]:51068 "EHLO mx2.parallels.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756856AbbJ2XAs (ORCPT ); Thu, 29 Oct 2015 19:00:48 -0400 From: James Bottomley To: "vkuznets@redhat.com" CC: "ulf.hansson@linaro.org" , "linux@rasmusvillemoes.dk" , "andriy.shevchenko@linux.intel.com" , "keescook@chromium.org" , "linux-kernel@vger.kernel.org" , "akpm@linux-foundation.org" Subject: Re: [PATCH v3 2/4] lib/string_helpers.c: protect string_get_size() against blk_size=0 Thread-Topic: [PATCH v3 2/4] lib/string_helpers.c: protect string_get_size() against blk_size=0 Thread-Index: AQHREmcyuq98ZTg6HkG6bAUDyFTYep6Di8sA Date: Thu, 29 Oct 2015 23:00:39 +0000 Message-ID: <1446159638.25009.5.camel@Odin.com> References: <1446136250-11507-1-git-send-email-vkuznets@redhat.com> <1446136250-11507-3-git-send-email-vkuznets@redhat.com> In-Reply-To: <1446136250-11507-3-git-send-email-vkuznets@redhat.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: Evolution 3.12.11 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [61.115.201.89] Content-Type: text/plain; charset="utf-8" Content-ID: MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id t9TN0rhs016798 On Thu, 2015-10-29 at 17:30 +0100, Vitaly Kuznetsov wrote: > Division by zero happens if blk_size=0 is supplied to string_get_size(). > Add WARN_ON() and set size to 0 to report '0 B'. > > Signed-off-by: Vitaly Kuznetsov > --- > lib/string_helpers.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/lib/string_helpers.c b/lib/string_helpers.c > index f6c27dc..ff3575b 100644 > --- a/lib/string_helpers.c > +++ b/lib/string_helpers.c > @@ -50,6 +50,11 @@ void string_get_size(u64 size, u32 blk_size, const enum string_size_units units, > > tmp[0] = '\0'; > i = 0; > + > + /* Calling string_get_size() with blk_size=0 is wrong! */ > + if (WARN_ON(!blk_size)) Get rid of the WARN_ON; it's the standard thing to do for a partially connected device. Seeing zero is standard in a whole variety of situations. SCSI shims the zero but most other drivers don't. James {.n++%ݶw{.n+{G{ayʇڙ,jfhz_(階ݢj"mG?&~iOzv^m ?I