Received: by 2002:a05:6520:4211:b029:f4:110d:56bc with SMTP id o17csp2110626lkv; Thu, 20 May 2021 03:39:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4n5WGtBDU3jnyjuuszhkpcNIp4RQDDg2LLCw2ZW+VRuu3ltrXV9CD/HmdNqsRdU4wc+Bk X-Received: by 2002:a05:6e02:b4b:: with SMTP id f11mr4830014ilu.253.1621507191218; Thu, 20 May 2021 03:39:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621507191; cv=none; d=google.com; s=arc-20160816; b=UMfmGoMd65R2748TdmdQZqCT7gOOTvz1IPt2f2agF4NmHe8O9aTZxWrYYceNsWXTjW NuMuS00nETerig9B8imvYr52wvQsjXpwW/CrOXE+ZsIE7zPGr00A5Kcu8N/yRI1sur1i ItB3SFHozORbuQrKFwzz0dDty22+YVB3mbPfB2nmLZ0wl+D/kyQfDf/2hW/OLMJXZ1Mf V7no2kY+Gh/HyDKID7Hn/Y/KiSRLQLaifc5+8RIZbICBUfMi+/eEmGeqisJBID1aSIrf w6Bvhb3DoRPBWNMwvH1ErXb8t6Y1L/LOjfnpZAgapIL2PFpds9sAj2ljyHA8PnuQz2mn BGNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PbsUXCHdEfV5AqU6JUVm45h3Q0TzIkqf9EOEX5eZnUE=; b=p729oJL2ZUQksoTFZN4h8YylZmTm42JACMBT47SNtR7nnbJMGJOvyT1SItCDDxfDnJ XyZ4pfr9lPHk3PnHYDA5YIa6ckNS9uW9QZs4wKQcdouvFAfun3U2qH/gq232muZRh/a8 BoswONPtB+rdEq2zGaZ+jGsbSoaO3gOx36y/AJ52t+xnnbxQET7jWZSVDh4/wkSigqc1 YX+asDFjhIksWLs+y9hHfxbbjBEBoRCh5NeIIY7A3jYe9jmcmkfv2YJseeaVw+tttX7V 8TcE09/pqT+m1Le32Me52dXt14G1TCyo6kgLkIGMWR+lESHjz8xkCzE4Qf2Ayyn+METn XqBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="T/nVsHBc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z6si2080245ilq.89.2021.05.20.03.39.23; Thu, 20 May 2021 03:39:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="T/nVsHBc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238269AbhETKjo (ORCPT + 99 others); Thu, 20 May 2021 06:39:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:55802 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236814AbhETKYd (ORCPT ); Thu, 20 May 2021 06:24:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C114561C18; Thu, 20 May 2021 09:49:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504171; bh=7VcG0lWkhYG2Zht8kzAcgvLD5mz/r4+3sgLPA3nHlW4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T/nVsHBcIkonHaBnQ61JjsXIY+lbpdb/isV48VVKd3M/REcjT24c3a1+FpdkL3UM9 PWJQb/m6me3wB9mhtGfjkfRm2uzmdfD+2EIjQIN+g3ILm/xC0H7AKKdCKul0UbTsfl +nyEZwymiTuwFIvNmUtKpthPUX/x35IAhsHSrNUc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Heming Zhao , Christoph Hellwig , Song Liu Subject: [PATCH 4.14 123/323] md: factor out a mddev_find_locked helper from mddev_find Date: Thu, 20 May 2021 11:20:15 +0200 Message-Id: <20210520092124.326124153@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christoph Hellwig commit 8b57251f9a91f5e5a599de7549915d2d226cc3af upstream. Factor out a self-contained helper to just lookup a mddev by the dev_t "unit". Cc: stable@vger.kernel.org Reviewed-by: Heming Zhao Signed-off-by: Christoph Hellwig Signed-off-by: Song Liu Signed-off-by: Greg Kroah-Hartman --- drivers/md/md.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -568,6 +568,17 @@ void mddev_init(struct mddev *mddev) } EXPORT_SYMBOL_GPL(mddev_init); +static struct mddev *mddev_find_locked(dev_t unit) +{ + struct mddev *mddev; + + list_for_each_entry(mddev, &all_mddevs, all_mddevs) + if (mddev->unit == unit) + return mddev; + + return NULL; +} + static struct mddev *mddev_find(dev_t unit) { struct mddev *mddev; @@ -595,13 +606,13 @@ static struct mddev *mddev_find_or_alloc spin_lock(&all_mddevs_lock); if (unit) { - list_for_each_entry(mddev, &all_mddevs, all_mddevs) - if (mddev->unit == unit) { - mddev_get(mddev); - spin_unlock(&all_mddevs_lock); - kfree(new); - return mddev; - } + mddev = mddev_find_locked(unit); + if (mddev) { + mddev_get(mddev); + spin_unlock(&all_mddevs_lock); + kfree(new); + return mddev; + } if (new) { list_add(&new->all_mddevs, &all_mddevs); @@ -627,12 +638,7 @@ static struct mddev *mddev_find_or_alloc return NULL; } - is_free = 1; - list_for_each_entry(mddev, &all_mddevs, all_mddevs) - if (mddev->unit == dev) { - is_free = 0; - break; - } + is_free = !mddev_find_locked(dev); } new->unit = dev; new->md_minor = MINOR(dev);