From patchwork Tue Nov 27 01:53:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hua Su X-Patchwork-Id: 10699567 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 07CA214E2 for ; Tue, 27 Nov 2018 01:55:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC3C72A34C for ; Tue, 27 Nov 2018 01:55:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E009A2A398; Tue, 27 Nov 2018 01:55:49 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 93DF92A34C for ; Tue, 27 Nov 2018 01:55:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727544AbeK0Mv7 (ORCPT ); Tue, 27 Nov 2018 07:51:59 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:35412 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727605AbeK0Mv7 (ORCPT ); Tue, 27 Nov 2018 07:51:59 -0500 Received: by mail-pl1-f194.google.com with SMTP id p8so4498885plo.2; Mon, 26 Nov 2018 17:55:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=1WTwvgoCZRsGXJrsy5qBbc33rFwaI9Gq0zhdjYK2sLE=; b=s++pL8e3E840PqO8FX2ewoyVHJKBMxi2UtL2Saf87F7wybYP44uXjv2K7MK/9YMZwP L2cQHTG8ajHCoIT1FeYO+T00x2cwqbguK48YZvnqhzOXzF2QknxnHfwCTsgNDFccYxOr xAO7xqmIkKIjiDmlMbseJlLDYnOjLT1pMJNveITmBvwVP7GF9bMorPckQ06imKcL0OJ6 KG/u6v0N/nSAwyGq8hcm1kBi6WULEXe79QjA6a+Tt0tjKuCfmSgnTKO5a+l3ue9b/M70 tHBV1k7qgvTq6RlK5lPZURIc+VwG3zCFtq0z+x94mKAH2reEXnvEgFIlgJKIOLh9pQ6U ukzw== 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:mime-version :content-transfer-encoding; bh=1WTwvgoCZRsGXJrsy5qBbc33rFwaI9Gq0zhdjYK2sLE=; b=tY4AoM3OAnPyhe4U3dkYmJnSLgr9e/Getls07es3MbKfUpT6pBOB1cqBXOHIKiITQD lWLqkaGOYHAML2OLlZOb8knbH6tBAhCtp9nCyUEXA8mpmnT9pMgtihRYvMmvb86DkJ0U vBGI1BnRyoMoY+iGoSpYdcxNxN+6h3I5aosnSTtLNmMG8tCRBr+5EtqVz+LuRggJNXbh osKHbcQulggUIzdejmy2zRehxQSvXFmm+at1CtbUFFkSnJC+dTvvSPRqB6Nl6kj2Tw/3 ZKje6JaXzz9FMilDGdbFIjUrd1Lx3bw3J7I/XugNdcFLLBISvx9ESUIThhicvnbICy1j +kiA== X-Gm-Message-State: AA+aEWYTJMpjH6SoDu5e99NZuLYbh2Z9mZ9NR5kjpeopuLOZqipBLjxv 025hMrz2wRSfVgZ6mYep2k4= X-Google-Smtp-Source: AFSGD/UqJktlt0i3CTFZk/tWBydoA7lPfOpEPGhXvTQbhtcWtEKB8XHu7vMWQ3Qvv6iUSN/cGAEhLA== X-Received: by 2002:a17:902:33c2:: with SMTP id b60mr30175676plc.211.1543283748013; Mon, 26 Nov 2018 17:55:48 -0800 (PST) Received: from localhost.localdomain ([119.40.32.42]) by smtp.gmail.com with ESMTPSA id a16-v6sm2157182pfh.107.2018.11.26.17.55.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Nov 2018 17:55:47 -0800 (PST) From: Hua Su To: mb@lightnvm.io Cc: javier@cnexlabs.com, axboe@kernel.dk, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, suhua.tanke@gmail.com Subject: [PATCH] lightnvm: pblk: adjust the position of the lock Date: Tue, 27 Nov 2018 09:53:09 +0800 Message-Id: <20181127015309.2374-1-suhua.tanke@gmail.com> X-Mailer: git-send-email 2.19.1 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 Add lock protection for list operations. Signed-off-by: Hua Su --- drivers/lightnvm/pblk-core.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/lightnvm/pblk-core.c b/drivers/lightnvm/pblk-core.c index 6944aac43b01..e490df217dac 100644 --- a/drivers/lightnvm/pblk-core.c +++ b/drivers/lightnvm/pblk-core.c @@ -1286,24 +1286,27 @@ int pblk_line_recov_alloc(struct pblk *pblk, struct pblk_line *line) list_del(&line->list); ret = pblk_line_prepare(pblk, line); - if (ret) { - list_add(&line->list, &l_mg->free_list); - spin_unlock(&l_mg->free_lock); - return ret; - } - spin_unlock(&l_mg->free_lock); + if (ret) + goto out; ret = pblk_line_alloc_bitmaps(pblk, line); if (ret) - return ret; + goto out; if (!pblk_line_init_bb(pblk, line, 0)) { list_add(&line->list, &l_mg->free_list); + spin_unlock(&l_mg->free_lock); return -EINTR; } + spin_unlock(&l_mg->free_lock); pblk_rl_free_lines_dec(&pblk->rl, line, true); return 0; + +out: + list_add(&line->list, &l_mg->free_list); + spin_unlock(&l_mg->free_lock); + return ret; } void pblk_line_recov_close(struct pblk *pblk, struct pblk_line *line)