From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966103AbbJ3Kl1 (ORCPT ); Fri, 30 Oct 2015 06:41:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48995 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965819AbbJ3Kl0 (ORCPT ); Fri, 30 Oct 2015 06:41:26 -0400 From: Vitaly Kuznetsov To: James Bottomley Cc: "andy.shevchenko\@gmail.com" , "ulf.hansson\@linaro.org" , "linux\@rasmusvillemoes.dk" , "andriy.shevchenko\@linux.intel.com" , "linux-kernel\@vger.kernel.org" , "akpm\@linux-foundation.org" , "keescook\@chromium.org" Subject: Re: [PATCH v3 2/4] lib/string_helpers.c: protect string_get_size() against blk_size=0 References: <1446136250-11507-1-git-send-email-vkuznets@redhat.com> <1446136250-11507-3-git-send-email-vkuznets@redhat.com> <1446159638.25009.5.camel@Odin.com> <1446176044.25009.17.camel@Odin.com> Date: Fri, 30 Oct 2015 11:41:21 +0100 In-Reply-To: <1446176044.25009.17.camel@Odin.com> (James Bottomley's message of "Fri, 30 Oct 2015 03:34:04 +0000") Message-ID: <87h9l8skoe.fsf@vitty.brq.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org James Bottomley writes: > On Fri, 2015-10-30 at 01:32 +0200, Andy Shevchenko wrote: >> On Fri, Oct 30, 2015 at 1:00 AM, James Bottomley wrote: >> > 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. >> >> For *block* size? It will crash the kernel. I've checked, it wasn't >> changed from the beginning (b9f28d863594). > > The standard signal for a drive error in capacity is zero size and zero > block size. We have to take that case as standard without emitting > scary warnings. Ok, but what if size != 0? Is WARN_ON() justified in this case? -- Vitaly