Received: by 2002:a4a:301c:0:0:0:0:0 with SMTP id q28-v6csp427568oof; Mon, 24 Sep 2018 23:10:33 -0700 (PDT) X-Google-Smtp-Source: ACcGV621Mb1fG9ZmHWvFO2Mrympe3EB+MjvJQks+PyIWtfwkr/1AqyOA+iHoFdpuN1l5SjZ6LVqg X-Received: by 2002:a63:f252:: with SMTP id d18-v6mr1819738pgk.2.1537855833728; Mon, 24 Sep 2018 23:10:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537855833; cv=none; d=google.com; s=arc-20160816; b=JxxfP+woDCX+Datrlwju5PdTb02OVZi+wlZTZReRIjzmnIon709PMaKoLAGsQaMH9U SoGZUKavwssNWiAt1x20h6GV8e/0qQzR1fbyo82UFZQWWNKwHBjWVI8Xh8SiUYRRn+6t Qcu1rM+s9aHQuNrPyIu6yHKVBYhiHXsi4RzVdR7Jlh2BUOmQFKMdJaH/PBWFCSC4RaAT rr8rX0dSyk3R7WwsTW2uFkLmka59DUiPyaC0kuf/J/lZlfPGxpkoCJxCZgC2QoFLr0dJ bJyZxVOcVeUlNdU59cMaa8PzVhawl4+HXHKCs3UZw+4tGy6Dkuo21IQffdN+H1X4Pv99 wkAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=rkRH6fPSqexuLzk7EHomO2XoN1TdTkv91CxsYdxoc1g=; b=tk5ZCZjrS3o1XAOObN/nNVA5uZvk1hB9iFIlpJHfP4+zfZ+4M1DtPLO/X4l2fnTuyt pPxdAwzKV9jZUQzKdqAINuq3uQDN2G1BAMljYAL9nphPNQrotXU0fc1lGYbQhpgHKSzQ WQIG5bqiRHRvyhPGdILyKE1pyWtuDGPxz6hrukuebEEylTiQuXndmQcZg4qgRP8kPX1J C9aITg/Xj0y9Z5jD4aRAH8ZY35RFUsm+vou/FBknVeT2H8eemGmvHlRsrELhPjpi1XFw d62sNbb3/gOmZI3vBxmfQTrhFJmD+JAn56Ekli1CKV7UCcfhoEi4NJ5SXdKifncwf+Dv owEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=FpBcEE8F; 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 69-v6si1624837plc.388.2018.09.24.23.10.18; Mon, 24 Sep 2018 23:10:33 -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; dkim=pass header.i=@163.com header.s=s110527 header.b=FpBcEE8F; 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 S1727823AbeIYMQH (ORCPT + 99 others); Tue, 25 Sep 2018 08:16:07 -0400 Received: from m12-15.163.com ([220.181.12.15]:55090 "EHLO m12-15.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725843AbeIYMQH (ORCPT ); Tue, 25 Sep 2018 08:16:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=rkRH6fPSqexuLzk7EH omO2XoN1TdTkv91CxsYdxoc1g=; b=FpBcEE8Fh7/bhYt6KuMgHUhShrzbj7Vhmo TNhoFiQz2TAAX4ktuxefKhL578trnAzC/nWNrasbds9c1jTZRxBDqVenEJSoL0pR sGkuZcgArPnALpHvzFBrB+OYNWj7uURMG7f0N5hapD0q7JT+yF8O4sSt1N//I+5h 12qRckYb0= Received: from localhost.localdomain (unknown [117.136.0.174]) by smtp11 (Coremail) with SMTP id D8CowADHYdA20albK3grIQ--.53064S5; Tue, 25 Sep 2018 14:10:06 +0800 (CST) From: Dongbo Cao To: colyli@suse.de Cc: kent.overstreet@gmail.com, linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, Dongbo Cao Subject: [PATCH 2/2] panic fix for making cache device Date: Tue, 25 Sep 2018 14:09:45 +0800 Message-Id: <20180925060945.6731-2-cdbdyx@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180925060945.6731-1-cdbdyx@163.com> References: <20180925060945.6731-1-cdbdyx@163.com> X-CM-TRANSID: D8CowADHYdA20albK3grIQ--.53064S5 X-Coremail-Antispam: 1Uf129KBjvJXoW7Zr18Gw1xGw4fWr43GFy5CFg_yoW8Xr1kpF Z3C34fAF48Xr17AF1DXr4v9a4rA392vFZrG3srAw43u3WYgFyY9FWDtFyjgr1UXry8Ja1a yFy5Kr18WF1jkaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jI6wAUUUUU= X-Originating-IP: [117.136.0.174] X-CM-SenderInfo: xfgev5r06rljoofrz/1tbiRx7M3Fc7EoAjpwAAsz Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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; -- 2.17.1