Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756151AbbLHMfq (ORCPT ); Tue, 8 Dec 2015 07:35:46 -0500 Received: from mail-pa0-f67.google.com ([209.85.220.67]:34236 "EHLO mail-pa0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751531AbbLHMfp (ORCPT ); Tue, 8 Dec 2015 07:35:45 -0500 Date: Tue, 8 Dec 2015 20:35:43 +0800 From: Minfei Huang To: Minfei Huang Cc: axboe@fb.com, m@bjorling.me, akinobu.mita@gmail.com, rusty@rustcorp.com.au, keith.busch@intel.com, mcgrof@suse.com, krinkin.m.u@gmail.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] null_blk: Fix error path in module initialization Message-ID: <20151208121453.GA94282@dhcp-128-22.nay.redhat.com> References: <1448545693-22141-1-git-send-email-mhuang@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1448545693-22141-1-git-send-email-mhuang@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1984 Lines: 78 Ping. Any comment is appreciate. Thanks Minfei On 11/26/15 at 09:48P, Minfei Huang wrote: > From: Minfei Huang > > Module couldn't release resource properly during the initialization. To > fix this issue, we will clean up the proper resource before returning. > > Signed-off-by: Minfei Huang > --- > drivers/block/null_blk.c | 24 +++++++++++++++++------- > 1 file changed, 17 insertions(+), 7 deletions(-) > > diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c > index 5c8ba54..ec99568 100644 > --- a/drivers/block/null_blk.c > +++ b/drivers/block/null_blk.c > @@ -780,7 +780,9 @@ out: > > static int __init null_init(void) > { > + int ret = 0; > unsigned int i; > + struct nullb *nullb; > > if (bs > PAGE_SIZE) { > pr_warn("null_blk: invalid block size\n"); > @@ -835,22 +837,30 @@ static int __init null_init(void) > 0, 0, NULL); > if (!ppa_cache) { > pr_err("null_blk: unable to create ppa cache\n"); > - return -ENOMEM; > + ret = -ENOMEM; > + goto err_ppa; > } > } > > for (i = 0; i < nr_devices; i++) { > - if (null_add_dev()) { > - unregister_blkdev(null_major, "nullb"); > - goto err_ppa; > - } > + ret = null_add_dev(); > + if (ret) > + goto err_dev; > } > > pr_info("null: module loaded\n"); > return 0; > + > +err_dev: > + while (!list_empty(&nullb_list)) { > + nullb = list_entry(nullb_list.next, struct nullb, list); > + null_del_dev(nullb); > + } > + if (use_lightnvm) > + kmem_cache_destroy(ppa_cache); > err_ppa: > - kmem_cache_destroy(ppa_cache); > - return -EINVAL; > + unregister_blkdev(null_major, "nullb"); > + return ret; > } > > static void __exit null_exit(void) > -- > 1.8.3.1 > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/