From patchwork Thu Feb 11 15:02:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 381015 Delivered-To: patch@linaro.org Received: by 2002:a02:b18a:0:0:0:0:0 with SMTP id t10csp2167454jah; Thu, 11 Feb 2021 07:20:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJwfBpzfYB5QVjP/sk8OpnKjcbId+9RhCfkiZ/T7Kx91zcfKQqSddBPLiHv4pb4Hd5B3tq5B X-Received: by 2002:a17:906:af58:: with SMTP id ly24mr9126049ejb.208.1613056849503; Thu, 11 Feb 2021 07:20:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613056849; cv=none; d=google.com; s=arc-20160816; b=sOPJo/vq9JfaryN1QyaGZj80UWlK864ac8B6o/vPh/txB4ROAbl+iMYiF7uE8QBzTD seHEj3KQXqv9ObXnrpc4SaRRVaDOjfuEZrUX3VEK7ysynB5x0SQYeSWspv28K38yPaMs Wff+CpeoXvpVycv1+55bRnfDn8a1LXcwrDraE58WoleCGmN1oVuAt9+dzRqT6cbq6cC4 4Fjxsp/k/UoH83J2O7AeYC6zS0LXlccL5w2PviEjO2p6iPaK6G6Ys225odrHTz7HNcnm bZlXLXneb+cFKGOHfuxPUGcYE6UkqI2jRKxas677f5BIKQ1GAD4IavlYqLuztIy9W+cV tc7A== 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=nj0yUajHZe7R9PgumbzDytc/XVQOxRBx1BWFZskhr4g=; b=HAfVCUwDZnR6rTypJSdyCeN8/TmIYfPBVJx9S/z/+7t0sRA5E35LNFzYlQ0edxQZa8 AjVtTWca6p0LeE6beVMFkBPRUcuNh0zGfeoVoVU9GUV6+iu+jutJOZxSXDPiI0vCJEVl 659H4bv27O18CsNAg6Hv0i91m6hdn5C073zVnh2jI0hpANUWMcIwg8hCvCpOJNsvUVac b5Px2TGPV2hVjz5hrLnqyynYJDcs4Qz/f+DNd7XMg/HEh9uucFC4fl8KXuXdIqwNI2T6 HTqVGKR/3xZ4zWtHE/l4fDOm78OVLMleUm7EkGZcCtg09jKWVGufBExP5a5814Z46JYX wtew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0jCLQtQX; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 l20si3774934ejn.375.2021.02.11.07.20.49; Thu, 11 Feb 2021 07:20:49 -0800 (PST) Received-SPF: pass (google.com: domain of stable-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=0jCLQtQX; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 S230318AbhBKPUY (ORCPT + 13 others); Thu, 11 Feb 2021 10:20:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:51400 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229946AbhBKPNT (ORCPT ); Thu, 11 Feb 2021 10:13:19 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5E16264EEE; Thu, 11 Feb 2021 15:04:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613055876; bh=l4jsbTIthBX8ZlPlTqTfRLysNM5GMsteOqAD2SmQ/Do=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0jCLQtQXzBO81BkRWNMbmK/zpSKxbZJTb3PbjgzSrHP0vLXIAU/N3xi1MmWn+Kitn LUKs2Oy8RngbhEru3qCwexZK0rhXSzjOgPbAnh89VMUZm/2xlShgbGLNMPM2LWLd6W hzDQNx5qxDncn9mWkZZ5E92CAv02E60umiEBjrK4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marek Szyprowski , Mark Brown , Sasha Levin Subject: [PATCH 5.10 43/54] regulator: Fix lockdep warning resolving supplies Date: Thu, 11 Feb 2021 16:02:27 +0100 Message-Id: <20210211150154.753986584@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210211150152.885701259@linuxfoundation.org> References: <20210211150152.885701259@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Mark Brown [ Upstream commit 14a71d509ac809dcf56d7e3ca376b15d17bd0ddd ] With commit eaa7995c529b54 (regulator: core: avoid regulator_resolve_supply() race condition) we started holding the rdev lock while resolving supplies, an operation that requires holding the regulator_list_mutex. This results in lockdep warnings since in other places we take the list mutex then the mutex on an individual rdev. Since the goal is to make sure that we don't call set_supply() twice rather than a concern about the cost of resolution pull the rdev lock and check for duplicate resolution down to immediately before we do the set_supply() and drop it again once the allocation is done. Fixes: eaa7995c529b54 (regulator: core: avoid regulator_resolve_supply() race condition) Reported-by: Marek Szyprowski Tested-by: Marek Szyprowski Signed-off-by: Mark Brown Link: https://lore.kernel.org/r/20210122132042.10306-1-broonie@kernel.org Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/regulator/core.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) -- 2.27.0 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 2c31f04ff950f..35098dbd32a3c 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1823,17 +1823,6 @@ static int regulator_resolve_supply(struct regulator_dev *rdev) if (rdev->supply) return 0; - /* - * Recheck rdev->supply with rdev->mutex lock held to avoid a race - * between rdev->supply null check and setting rdev->supply in - * set_supply() from concurrent tasks. - */ - regulator_lock(rdev); - - /* Supply just resolved by a concurrent task? */ - if (rdev->supply) - goto out; - r = regulator_dev_lookup(dev, rdev->supply_name); if (IS_ERR(r)) { ret = PTR_ERR(r); @@ -1885,12 +1874,29 @@ static int regulator_resolve_supply(struct regulator_dev *rdev) goto out; } + /* + * Recheck rdev->supply with rdev->mutex lock held to avoid a race + * between rdev->supply null check and setting rdev->supply in + * set_supply() from concurrent tasks. + */ + regulator_lock(rdev); + + /* Supply just resolved by a concurrent task? */ + if (rdev->supply) { + regulator_unlock(rdev); + put_device(&r->dev); + goto out; + } + ret = set_supply(rdev, r); if (ret < 0) { + regulator_unlock(rdev); put_device(&r->dev); goto out; } + regulator_unlock(rdev); + /* * In set_machine_constraints() we may have turned this regulator on * but we couldn't propagate to the supply if it hadn't been resolved @@ -1906,7 +1912,6 @@ static int regulator_resolve_supply(struct regulator_dev *rdev) } out: - regulator_unlock(rdev); return ret; }