Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752722AbbKYLhF (ORCPT ); Wed, 25 Nov 2015 06:37:05 -0500 Received: from mail-wm0-f50.google.com ([74.125.82.50]:34294 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752018AbbKYLhC (ORCPT ); Wed, 25 Nov 2015 06:37:02 -0500 Message-ID: <56559D5C.6090004@lightnvm.io> Date: Wed, 25 Nov 2015 12:37:00 +0100 From: =?UTF-8?B?TWF0aWFzIEJqw7hybGluZw==?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Wenwei Tao CC: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org Subject: Re: [PATCH] lightnvm: missing nvm_lock acquire References: <1448378697-2532-1-git-send-email-ww.tao0320@gmail.com> <5654AE2D.2080802@lightnvm.io> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1820 Lines: 62 On 11/25/2015 09:57 AM, Wenwei Tao wrote: > Hi Matias > I think list_for_each_entry_safe(pos, n, head, member) cannot avoid > race condition > the item point by ‘n’ can be deleted and freed in the same time we > operate on 'pos' > so lock is still necessary. > I've made the patch like this, ok? To avoid race conditions, traverse dev, media manager, and target lists and also register, unregister entries to/from them, should be always under the nvm_lock control. Signed-off-by: Wenwei Tao Signed-off-by: Matias Bjørling --- drivers/lightnvm/core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index ea6dba5..9f901f6 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -127,9 +127,11 @@ static struct nvm_dev *nvm_find_nvm_dev(const char *name) { struct nvm_dev *dev; + down_write(&nvm_lock); list_for_each_entry(dev, &nvm_devices, devices) if (!strcmp(name, dev->name)) return dev; + up_write(&nvm_lock); return NULL; } @@ -388,13 +390,14 @@ static int nvm_create_target(struct nvm_dev *dev, } } + down_write(&nvm_lock); tt = nvm_find_target_type(create->tgttype); if (!tt) { pr_err("nvm: target type %s not found\n", create->tgttype); + up_write(&nvm_lock); return -EINVAL; } - down_write(&nvm_lock); list_for_each_entry(t, &dev->online_targets, list) { if (!strcmp(create->tgtname, t->disk->disk_name)) { pr_err("nvm: target name already exists.\n"); -- 2.1.4 -- 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/