From patchwork Fri Oct 13 12:46:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Matias_Bj=C3=B8rling?= X-Patchwork-Id: 10004535 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5886060216 for ; Fri, 13 Oct 2017 12:53:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B84E29002 for ; Fri, 13 Oct 2017 12:53:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 407D82905C; Fri, 13 Oct 2017 12:53:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CEF8429002 for ; Fri, 13 Oct 2017 12:53:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758423AbdJMMxb (ORCPT ); Fri, 13 Oct 2017 08:53:31 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:45150 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932176AbdJMMru (ORCPT ); Fri, 13 Oct 2017 08:47:50 -0400 Received: by mail-wm0-f65.google.com with SMTP id q124so21262944wmb.0 for ; Fri, 13 Oct 2017 05:47:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bjorling.me; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2pa++iEMFyve26JxUQS5fQGtNyDTDYmkqp+iZvwIBeE=; b=EXT3Kg0v9ZKaCR0GT8DONRBsaMrX5BW0DMM1a8HfNzl598ICo/6wzmXTaLmJj4NedK fvzztP/gifwIpfnGCSLt8G2GJ0gTHbgJkP2Ve6QqxvJ8zaCd0tKsYCzhfWfiZE8V8lQv 41kHqIoIyJaUUnFinTyRlBKEYeskObEXlewrU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2pa++iEMFyve26JxUQS5fQGtNyDTDYmkqp+iZvwIBeE=; b=k7kU9JuZWGTaaLzCU4mHUPQyXqIZc/yP3jQCCma04BJNOzY80Lo9RG9joT8RAaM1np 5u7gBhH2H/7R3r/pt/QQ3zYD0D5LatPINyDLrEkJrQHMQquhkr46P6aHzXX6aSdDuby5 Ghz9OlTe1w29cKGnSzYe/PJEXU6+JK75jA1S5GAfP7oz8R4bYOFQUvb7awYsmpXxPAae RryV7vT7ZGD+Ky36WZgTRrqTmYVh4Y/6AVBK8xgqAk8G7staG9ymd2IgMynDZCL8VQ3w +NYNErnKmJ5y87yssmcM5x1xw0gsZ1jEbnAE/EkTrHMpcQryyGey1yL6M+3p2J03oHwn 53Ug== X-Gm-Message-State: AMCzsaUH5C+Wb1oeUp8a8EHO/0hnsqDtknv/0ELs1z4in9u1KnIvQuiA FvG3BXrW6Lt6sV/xDpyVuqNmLpZX X-Google-Smtp-Source: AOwi7QD5N7RXllCke5SIPCIdQVjxdoquQoJFTDDmLugi98tXRulDCfkQrd25a4W/j/sq6xcq7moceg== X-Received: by 10.80.139.65 with SMTP id l59mr2058195edl.187.1507898868893; Fri, 13 Oct 2017 05:47:48 -0700 (PDT) Received: from skyninja.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id p91sm735012edp.69.2017.10.13.05.47.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Oct 2017 05:47:48 -0700 (PDT) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: axboe@fb.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Rakesh Pandit , =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [GIT PULL 44/58] lightnvm: pblk: fix releases of kmem cache in error path Date: Fri, 13 Oct 2017 14:46:33 +0200 Message-Id: <20171013124647.32668-45-m@bjorling.me> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20171013124647.32668-1-m@bjorling.me> References: <20171013124647.32668-1-m@bjorling.me> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Rakesh Pandit If pblk_core_init fails lets destroy all global caches. Signed-off-by: Rakesh Pandit Signed-off-by: Matias Bjørling --- drivers/lightnvm/pblk-init.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c index 56ece7d..2e59973 100644 --- a/drivers/lightnvm/pblk-init.c +++ b/drivers/lightnvm/pblk-init.c @@ -220,6 +220,14 @@ static int pblk_init_global_caches(struct pblk *pblk) return 0; } +static void pblk_free_global_caches(struct pblk *pblk) +{ + kmem_cache_destroy(pblk_ws_cache); + kmem_cache_destroy(pblk_rec_cache); + kmem_cache_destroy(pblk_g_rq_cache); + kmem_cache_destroy(pblk_w_rq_cache); +} + static int pblk_core_init(struct pblk *pblk) { struct nvm_tgt_dev *dev = pblk->dev; @@ -235,7 +243,7 @@ static int pblk_core_init(struct pblk *pblk) pblk->page_bio_pool = mempool_create_page_pool(nvm_max_phys_sects(dev), 0); if (!pblk->page_bio_pool) - return -ENOMEM; + goto free_global_caches; pblk->gen_ws_pool = mempool_create_slab_pool(PBLK_GEN_WS_POOL_SIZE, pblk_ws_cache); @@ -303,6 +311,8 @@ static int pblk_core_init(struct pblk *pblk) mempool_destroy(pblk->gen_ws_pool); free_page_bio_pool: mempool_destroy(pblk->page_bio_pool); +free_global_caches: + pblk_free_global_caches(pblk); return -ENOMEM; } @@ -324,10 +334,7 @@ static void pblk_core_free(struct pblk *pblk) mempool_destroy(pblk->e_rq_pool); mempool_destroy(pblk->w_rq_pool); - kmem_cache_destroy(pblk_ws_cache); - kmem_cache_destroy(pblk_rec_cache); - kmem_cache_destroy(pblk_g_rq_cache); - kmem_cache_destroy(pblk_w_rq_cache); + pblk_free_global_caches(pblk); } static void pblk_luns_free(struct pblk *pblk)