From patchwork Fri Jan 5 13:16:04 2018 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: 10146545 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 2BCF2604D3 for ; Fri, 5 Jan 2018 13:22:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1AADD26E97 for ; Fri, 5 Jan 2018 13:22:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F9AA27E01; Fri, 5 Jan 2018 13:22:07 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, 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 82D0027CAF for ; Fri, 5 Jan 2018 13:22:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751982AbeAENWF (ORCPT ); Fri, 5 Jan 2018 08:22:05 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:37960 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751487AbeAENQs (ORCPT ); Fri, 5 Jan 2018 08:16:48 -0500 Received: by mail-wm0-f68.google.com with SMTP id 64so2415603wme.3 for ; Fri, 05 Jan 2018 05:16:47 -0800 (PST) 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=k+OfqgAThYPOXBdFYBl0yLeFJQ3I/p/CH5Q4J0t9XVQ=; b=JrN0z3Fn4DjRnXUtlCIrFcEP7FTxxly8VPgBK3XxjTyLL+hdHHQ/wpZGerUnzWJaWo KGycAjyeMwobdIPiNtRuZ01WaE7hGk9uiQcbDEilLfS8crfdlKsb60t04BtfyZpmsWbY 6dwNS8V5xM8APL3uRM5quQUiY4x3UaXugF5c4= 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=k+OfqgAThYPOXBdFYBl0yLeFJQ3I/p/CH5Q4J0t9XVQ=; b=g24biHcoF8lDNt15yHWn9Tp3yRKkWEycOhlCyl55KS0+CM1wCj4uk18vo5hNY+ujJt X2zAmhtpgn8i+0pNsgH9yu9qaXtLsAeqItfbybPosgF9BecG8kU+CO5PSI1nES5aGGPH +M7XHG+Zv4wkpHPlEmZkyUkKyCzuqFx98/qgECYh8Q0Dh7Ho8bIxH0nBboyDkcSOPlyL zyi6OBj10K3DFdOWghebeUt4cjCE2KR8CM2pPzTwfA8Zf+T/Tqvel/hQI3Jcyd3888G+ 3bB8+3XfpNTVzw9IE0kqwL6H2yLkJbCNzSqxhuvTjHAakV8VhkNSJ9i1bVPlNek97YtV HUTw== X-Gm-Message-State: AKGB3mKCzfhuBPbt6A2a8xKqUCr5u/NY6UMPKb0kP2CM7oyWpt3/vZ9r IYBcTK4srGMD4utKIW0sjl7TSw== X-Google-Smtp-Source: ACJfBosnBlYkY2alEHfok73Lfp+OcXYVmKHslwz+32E7rppoOC3qKJIqoFqocOCI3h5vuYlyvCVb9A== X-Received: by 10.80.180.18 with SMTP id b18mr4103563edh.260.1515158207228; Fri, 05 Jan 2018 05:16:47 -0800 (PST) Received: from skyninja.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id e46sm4228940edb.93.2018.01.05.05.16.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Jan 2018 05:16:46 -0800 (PST) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: axboe@fb.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Javier=20Gonz=C3=A1lez?= , =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [GIT PULL 08/25] lightnvm: refactor target type lookup Date: Fri, 5 Jan 2018 14:16:04 +0100 Message-Id: <20180105131621.20808-9-m@bjorling.me> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180105131621.20808-1-m@bjorling.me> References: <20180105131621.20808-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: Javier González Refactor target type lookup to use/not use locks explicitly instead of using a hidden parameter to make the function locking. Signed-off-by: Javier González Signed-off-by: Matias Bjørling --- drivers/lightnvm/core.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 6d6d2c1..5c2d0f3 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -220,21 +220,25 @@ static const struct block_device_operations nvm_fops = { .owner = THIS_MODULE, }; -static struct nvm_tgt_type *nvm_find_target_type(const char *name, int lock) +static struct nvm_tgt_type *__nvm_find_target_type(const char *name) { - struct nvm_tgt_type *tmp, *tt = NULL; + struct nvm_tgt_type *tt; - if (lock) - down_write(&nvm_tgtt_lock); + list_for_each_entry(tt, &nvm_tgt_types, list) + if (!strcmp(name, tt->name)) + return tt; - list_for_each_entry(tmp, &nvm_tgt_types, list) - if (!strcmp(name, tmp->name)) { - tt = tmp; - break; - } + return NULL; +} + +static struct nvm_tgt_type *nvm_find_target_type(const char *name) +{ + struct nvm_tgt_type *tt; + + down_write(&nvm_tgtt_lock); + tt = __nvm_find_target_type(name); + up_write(&nvm_tgtt_lock); - if (lock) - up_write(&nvm_tgtt_lock); return tt; } @@ -249,7 +253,7 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create) void *targetdata; int ret; - tt = nvm_find_target_type(create->tgttype, 1); + tt = nvm_find_target_type(create->tgttype); if (!tt) { pr_err("nvm: target type %s not found\n", create->tgttype); return -EINVAL; @@ -523,7 +527,7 @@ int nvm_register_tgt_type(struct nvm_tgt_type *tt) int ret = 0; down_write(&nvm_tgtt_lock); - if (nvm_find_target_type(tt->name, 0)) + if (__nvm_find_target_type(tt->name)) ret = -EEXIST; else list_add(&tt->list, &nvm_tgt_types);