From patchwork Tue Jul 30 21:05:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Perches X-Patchwork-Id: 2835946 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id AF969C0319 for ; Tue, 30 Jul 2013 21:06:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ADDF420340 for ; Tue, 30 Jul 2013 21:06:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4EB6E20326 for ; Tue, 30 Jul 2013 21:06:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756135Ab3G3VFt (ORCPT ); Tue, 30 Jul 2013 17:05:49 -0400 Received: from perches-mx.perches.com ([206.117.179.246]:53749 "EHLO labridge.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751777Ab3G3VFs (ORCPT ); Tue, 30 Jul 2013 17:05:48 -0400 Received: from [173.51.221.202] (account joe@perches.com HELO [192.168.1.152]) by labridge.com (CommuniGate Pro SMTP 5.0.14) with ESMTPA id 21199316; Tue, 30 Jul 2013 14:05:47 -0700 Message-ID: <1375218347.2075.133.camel@joe-AO722> Subject: Re: btrfs zero divide From: Joe Perches To: Josef Bacik Cc: Thorsten Glaser , Geert Uytterhoeven , Debian GNU/Linux m68k , linux-btrfs@vger.kernel.org, Linux Kernel Development Date: Tue, 30 Jul 2013 14:05:47 -0700 In-Reply-To: <20130730204001.GG24583@localhost.localdomain> References: <20130730171329.GF24583@localhost.localdomain> <20130730204001.GG24583@localhost.localdomain> X-Mailer: Evolution 3.6.4-0ubuntu1 Mime-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Tue, 2013-07-30 at 16:40 -0400, Josef Bacik wrote: > So stripe_len shouldn't be 0, if it is you have bigger problems :). Is this a > corrupt fs or something? If there was some sort of corruption that occured then > I suppose stripe_len could be 0 and we'd need to catch that somewhere higher up > the stack and error out. Is there a way you could check and see if that's the > case? Thanks, Maybe use a temporary check in do_div Something like this maybe. (uncompiled/untested) --- include/asm-generic/div64.h | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/include/asm-generic/div64.h b/include/asm-generic/div64.h index 8f4e319..cce75fe 100644 --- a/include/asm-generic/div64.h +++ b/include/asm-generic/div64.h @@ -19,16 +19,25 @@ #include #include +#include +#include #if BITS_PER_LONG == 64 -# define do_div(n,base) ({ \ +# define do_div(n, base) \ +({ \ uint32_t __base = (base); \ uint32_t __rem; \ - __rem = ((uint64_t)(n)) % __base; \ - (n) = ((uint64_t)(n)) / __base; \ + if (__base == 0) { \ + WARN(1, "Attempted division by 0\n"); \ + dump_stack(); \ + __rem = 0; \ + } else { \ + __rem = ((uint64_t)(n)) % __base; \ + (n) = ((uint64_t)(n)) / __base; \ + } \ __rem; \ - }) +}) #elif BITS_PER_LONG == 32 @@ -37,16 +46,22 @@ extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor); /* The unnecessary pointer compare is there * to check for type safety (n must be 64bit) */ -# define do_div(n,base) ({ \ - uint32_t __base = (base); \ - uint32_t __rem; \ - (void)(((typeof((n)) *)0) == ((uint64_t *)0)); \ - if (likely(((n) >> 32) == 0)) { \ - __rem = (uint32_t)(n) % __base; \ - (n) = (uint32_t)(n) / __base; \ - } else \ - __rem = __div64_32(&(n), __base); \ - __rem; \ +# define do_div(n, base) \ +({ \ + uint32_t __base = (base); \ + uint32_t __rem; \ + (void)(((typeof((n)) *)0) == ((uint64_t *)0)); \ + if (__base == 0) { \ + WARN(1, "Attempted division by 0\n"); \ + dump_stack(); \ + __rem = 0; \ + } else if (likely(((n) >> 32) == 0)) { \ + __rem = (uint32_t)(n) % __base; \ + (n) = (uint32_t)(n) / __base; \ + } else { \ + __rem = __div64_32(&(n), __base); \ + } \ + __rem; \ }) #else /* BITS_PER_LONG == ?? */