Received: by 2002:a4a:301c:0:0:0:0:0 with SMTP id q28-v6csp857679oof; Tue, 25 Sep 2018 05:42:38 -0700 (PDT) X-Google-Smtp-Source: ACcGV62mPqzRaN6sY0kCu2ZezpswFPwUe8KUPzhWKQYrlH+vu/e67uvaahXXEpfRD9Tofsj4Wtt8 X-Received: by 2002:a62:4ec9:: with SMTP id c192-v6mr935715pfb.221.1537879358627; Tue, 25 Sep 2018 05:42:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537879358; cv=none; d=google.com; s=arc-20160816; b=X14525WHU5XS+J3H7AW27qKUnK1hgioNRM1C6u4qP238HA+QDtpm50xHxMxBbcsgC+ /Be//EI+3B9w6T9ykY142tkKrFrD56/cKT1c2LFg0viXuhN54yVEdKC0RSdE5SwDDyQ6 vlVU+jh1j3jpc3jvnKhF24Ys8Elb12y+6SBBh8Q3ck42unhZg2lIqxSXMQkY6+nOn71N k7FZKjJwG4UBA1rC6Twv/K5ZyawCTATB4KzFAQ9Pl4NHf25Kdg7ydbVISdHm42FvJsWt AyA0uMKLSP7zDxSRhRI8asNAFblXHcUKcux1QgJvG4fWtUjFC+59fW65Q1TMAqpnOxQG lY/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=TXBHfeJF35NIAfif5+9+hdLxr2NWSgKP0pTdcLOmNr8=; b=PAo3k7Tzl8fKOsaCv9tiu440jSzZk0Mvi1gl4wOLBBtg+BpQEdMMsuFhzhTWGIWlnA d0w/5sf5HFa7gqWEq8P17OjJkJkiaWvL7VGbS7QUszUaww3X4aMKh16MiXv6d1s3nXhJ slwRvsECCvbt2QH+6sFF6l1wVnV1PhLgtdWZdM/nQm3zUAiSUu+PFzep/m2uKxMcXlKm 0pKjo1+jvzI3hBcqwxNmnX0VLkmbq+QzJ4i9uqCOWaRenAop/5bEP/1sdBUUBwDvkvNQ Ef6WjAg+fX5JmAGuTVyLwVXSFXmXH+hS6K0GV5jWesqlhsfpBLZizksJLWnC37g+17I5 MFsw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r73-v6si2225338pfk.83.2018.09.25.05.42.22; Tue, 25 Sep 2018 05:42:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729066AbeIYStG (ORCPT + 99 others); Tue, 25 Sep 2018 14:49:06 -0400 Received: from mx2.suse.de ([195.135.220.15]:35032 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728773AbeIYStG (ORCPT ); Tue, 25 Sep 2018 14:49:06 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 10AF9AEA3; Tue, 25 Sep 2018 12:41:42 +0000 (UTC) Subject: Re: [PATCH 2/2] panic fix for making cache device To: Dongbo Cao Cc: kent.overstreet@gmail.com, linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org References: <20180925060945.6731-1-cdbdyx@163.com> <20180925060945.6731-2-cdbdyx@163.com> From: Coly Li Message-ID: Date: Tue, 25 Sep 2018 20:41:36 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: <20180925060945.6731-2-cdbdyx@163.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/25/18 2:09 PM, Dongbo Cao wrote: > when the nbuckets of cache device is smaller than 1024, making cache device will trigger BUG_ON in kernel, add a condition to avoid this. > > Signed-off-by: Dongbo Cao This patch added to my for-next, with minor change to fix checkpatch.pl warning. Thanks. Coly Li > --- > drivers/md/bcache/super.c | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c > index 0c0f6d8f..47d122ed 100644 > --- a/drivers/md/bcache/super.c > +++ b/drivers/md/bcache/super.c > @@ -2036,7 +2036,12 @@ static int cache_alloc(struct cache *ca) > */ > btree_buckets = ca->sb.njournal_buckets ?: 8; > free = roundup_pow_of_two(ca->sb.nbuckets) >> 10; > - > + if (!free) { > + ret = -EPERM; > + err = "ca->sb.nbuckets is too small"; > + goto err_free; > + } > + > if (!init_fifo(&ca->free[RESERVE_BTREE], btree_buckets, > GFP_KERNEL)) { > err = "ca->free[RESERVE_BTREE] alloc failed"; > @@ -2102,6 +2107,7 @@ static int cache_alloc(struct cache *ca) > err_prio_alloc: > free_fifo(&ca->free[RESERVE_BTREE]); > err_btree_alloc: > +err_free: > module_put(THIS_MODULE); > if (err) > pr_notice("error %s: %s", ca->cache_dev_name, err); > @@ -2131,6 +2137,8 @@ static int register_cache(struct cache_sb *sb, struct page *sb_page, > blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL); > if (ret == -ENOMEM) > err = "cache_alloc(): -ENOMEM"; > + else if (ret == -EPERM) > + err = "cache_alloc(): cache device is too small"; > else > err = "cache_alloc(): unknown error"; > goto err;