From patchwork Wed Dec 20 17:21:48 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: 10126065 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 ADC7E6057F for ; Wed, 20 Dec 2017 17:28:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96F41291A1 for ; Wed, 20 Dec 2017 17:28:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C12429280; Wed, 20 Dec 2017 17:28:31 +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 3D1DB291A1 for ; Wed, 20 Dec 2017 17:28:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755871AbdLTR2Z (ORCPT ); Wed, 20 Dec 2017 12:28:25 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:42257 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755944AbdLTRWX (ORCPT ); Wed, 20 Dec 2017 12:22:23 -0500 Received: by mail-wm0-f66.google.com with SMTP id b199so11380535wme.1 for ; Wed, 20 Dec 2017 09:22:22 -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=WEvghUbpJJdDBVOVkrGuJOvthquC9fWQ5dFcs1jvth2UCQnJndnbFosxFegIKXUjSE gKPbIWIDSV+3cgm/xtOVA104TLTQ29SVN5P/reKzK63Au2OWecxaGEUtDLa838yOe5Ak mr2o4Sm+gVuROLDyscgp+mJWloaH8a9Giy5tw= 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=O9g2XcpcU/OrMNSSL5SWoOzsMIKv7A8x+2GncYtshUp9Xe1KNgBwFoBlDR9JT22o5U ILRPlJXSYA3O57tEVR4eFHWTcJOk4BNoEAlMNLHQrsYvI+IGwzowLGUl1bR7+iLto99M MSA6FAH3tNlvO0NY9gQ0VNHy38XwUtN5xCMWw2lspD3nl3t45cn1MGRzQGZef/lvxFOg 5+w/ISzARQXjaPHAjuz7tnGJ5lEwJbaXPbdgkpmG3N9gToBPrv03oPSpmFw7v/5filmF xJ9171wOAi/YOPRk3A1aWf788QMID+kbbgKxJgdtZ/cUrQzLI74z3atRDVp8D+5VEAeQ cbBg== X-Gm-Message-State: AKGB3mISRmgdbj5a1ZpyFC5TH6s9TamNiz5WrIf4/YekVbtcMXDMepbW CDbD/5H1qgAQqKh/9savxnS4Cl1+ X-Google-Smtp-Source: ACJfBos2MB/mtwNfdq1S6dhFARPYdE3GWZqZCZJkblRORolKgZTNAZRTscfPQjeFcQ/FXAwkrrVvxA== X-Received: by 10.80.168.162 with SMTP id k31mr6670671edc.253.1513790541478; Wed, 20 Dec 2017 09:22:21 -0800 (PST) Received: from skyninja.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id 26sm15339120eds.67.2017.12.20.09.22.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Dec 2017 09:22:20 -0800 (PST) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Javier=20Gonz=C3=A1lez?= , =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [PATCH 08/25] lightnvm: refactor target type lookup Date: Wed, 20 Dec 2017 18:21:48 +0100 Message-Id: <20171220172205.26464-9-m@bjorling.me> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20171220172205.26464-1-m@bjorling.me> References: <20171220172205.26464-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);