Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp61308pxj; Thu, 20 May 2021 04:36:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGmwqQ+FOzeyVYMjbM8hBjrU9/p4PCUMICEUNOg5t1bYQhmOfDIY3rQ56Qq/U6S48a3eMW X-Received: by 2002:a17:906:b0cb:: with SMTP id bk11mr4347008ejb.310.1621510562085; Thu, 20 May 2021 04:36:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621510562; cv=none; d=google.com; s=arc-20160816; b=mSVBNuIkccmAcztFrPTkNiOkpkgkak1PqswCyLZ7O1s5rItWXWxumX7svJ9dS1XWlz qPaHK9OYxd2xHLKxP8TpK9tlt7LqQz/gYIdv20u0VAjUl8eEKfpbgxhSR0Cg8KclkFgD V/Qq8E8+QJExeK83xM5kQervTkJiv3t0SmGXdCzGRYbxZH53w05JcVq1mTmmmM+nUR39 LHVDCznby3ZDUwL+ObTF/vLf9ym5Y0kcdCO9apr5hDOkF4J7tzjuA/5Qd13Ak38CE1De 7kMtLTa4PMT28qzw8FWvFOcT86TrH3VXBWx+fhn1SNmpXPwFCxL2kLAtFz62jCVRJQ+1 XHPQ== 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=YB9XXkn/4kGPSF6O7HVl7w0B4wV8numeD+5zwr13umU=; b=PasZB+N4mCiETzKfPPID93/XZK+0vq1xlth8ypba7L7zPWLJFnNXetvTKj9Ww6LA9D z31YKMZ/QQVnB4/BeMqIDxp4HxlQLSabPzI5TIhHuzk1ubn0xwIAPX59ND7n+HahDfSM GFx2fayLm0KrBz4vdGRmt5ld7sC8JdccfaqLF8GkajpZBQvW4g6T/XQdF/JHxfXarulI JsgHn9qIT9GR9yblTUrTGWr/PcvWqBqEkO8ww7Xhx8xXYlj0AEy7V9x0xGi4sa3nVBN/ epehtmqJW7RNNfxByGkCF9SE8YZT86CuBSTG+XdbJgFIix4M5iVJPMM3LevFQ9vF6u8G FbJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=V2I3yRNw; 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 a15si208968edr.48.2021.05.20.04.35.38; Thu, 20 May 2021 04:36:02 -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=V2I3yRNw; 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 S241383AbhETLdr (ORCPT + 99 others); Thu, 20 May 2021 07:33:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:55136 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240014AbhETLNT (ORCPT ); Thu, 20 May 2021 07:13:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8751E60FEE; Thu, 20 May 2021 10:08:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621505287; bh=nGWRpsKjppsqCp8Uzxd5EPF1mpPji9rnT/6Vdsy2Z5s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V2I3yRNwDNHh1LyloAg9IWziwBgy+cjh4EvOUAkI0qMt6TAvR+VT3u8vnekdx6BJ7 rU+0YGIPUyMqxSfCuJkXUkdqtFTfYp7tXnFNknKIppwEq3q0aL30zxtKV9GcjSSmMl JoRNVL+A+cwrmvvChYnV3wO/PWWF6MPirdB0Uqms= 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.4 065/190] md: factor out a mddev_find_locked helper from mddev_find Date: Thu, 20 May 2021 11:22:09 +0200 Message-Id: <20210520092104.316576635@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092102.149300807@linuxfoundation.org> References: <20210520092102.149300807@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 @@ -515,6 +515,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, *new = NULL; @@ -526,13 +537,13 @@ static struct mddev *mddev_find(dev_t un 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); @@ -558,12 +569,7 @@ static struct mddev *mddev_find(dev_t un 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);