Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp544715pxj; Thu, 20 May 2021 15:50:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaBXrIg7YADfSpY1zG3TuAuvYsdmH3M5gT4wiFjw6nrsNqQHNfFSH6fkNgtwKjyefkADVD X-Received: by 2002:a5e:aa10:: with SMTP id s16mr8221143ioe.147.1621551044538; Thu, 20 May 2021 15:50:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621551044; cv=none; d=google.com; s=arc-20160816; b=IEGkKrrc943HO8qCqnI/NHVe49LSJK0Y5H1yZnG/AQJQYYDjJ1OxkhybcZQo+Qm108 eoiWgg5+Y0N7EsCaMNfg2G9xjtnpdOez6NAMM2Uz3y8E9Lwr5RzbQD6dZB8QHaQcywLu d2XoOf3hyoE20drqYcZHU4ABEScyunG2PhhR1sOcNCyjji4JVcO7ybSWG9gURqyLvTPn Bb3evE4xuhT0ZqJ9PsAwfgwgDBjysqvh5wB+DudQk1VJ/JYSNheccGHiU7HS8DQBsL0A SvaDp/fALbvpKweSC4Y/ah+YM8vShWGNpiLiE8hNH/BvpH7ZtbbZkSb+NyhTB4H7+kdH OJog== 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=/ICZW4U+U7Y2ed44o4WnWW2/zt9lFq+XgpYK+6OWWaQ=; b=wJ9OStg+XveXb2d5IEnGHF215jf7yFU8Zn+AEI0B9b0O8cdQAXANI5G3zbnRkGplA+ AOt072S2QLEGSt4360yOs/mQ9LaWiBxqWhfFM4sm+v/tEuMpqyeyWbnIcTQcoLzMgzt5 rWcG/VQJ/FCKP6XrOQ4HwSmYfpSbJ7x4mgpHQWLbGd7/jG8KHNSwROT5S0OX2Tcf9SZ7 Yw9Q6AcxvtGcmmWgFHE9kYmI2OoZEuG9q8O6yBxeVTdeXYWqTleuFFzxa0VJR4G0zLeV Bb+LX/cWvA1Oxpq/JxviVmCI/34bD5yQWlQPusSpW148CVFck/IKoPmoKVfzi1XYx1zx 1nPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mhJH+RvF; 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 d9si3510562ils.122.2021.05.20.15.50.31; Thu, 20 May 2021 15:50:44 -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=mhJH+RvF; 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 S240479AbhETLKT (ORCPT + 99 others); Thu, 20 May 2021 07:10:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:49004 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238954AbhETKum (ORCPT ); Thu, 20 May 2021 06:50:42 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 983F761CD0; Thu, 20 May 2021 09:59:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504787; bh=2Vl2YMPx0ocYVCCfLjIexlfpR1+ziBADLp+bZwq6A94=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mhJH+RvFaMRPZG6yyhrz3Q94wdpTtdW1nEwthQndzhinj5LTeVVAeJ0JUj32tHAc3 Y5TBepcalgPZF5sX86NOtJR/0yIKpSyYHs/yVz/8avcQoHELgOrQc7lARm2hWcqaI5 tZdWqyWwojdCurSlb/G3muP04QtJWAUOLRW3i390= 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.9 081/240] md: factor out a mddev_find_locked helper from mddev_find Date: Thu, 20 May 2021 11:21:13 +0200 Message-Id: <20210520092111.403218007@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092108.587553970@linuxfoundation.org> References: <20210520092108.587553970@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 @@ -508,6 +508,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; @@ -519,13 +530,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); @@ -551,12 +562,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);