Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2244457pxb; Thu, 11 Feb 2021 07:49:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJxi1mMJmt8rV0tBkOckNW+oQvJKV8f9hopjXeLLRflMzLFcluur9DOr1+baERGBnGdSGJsN X-Received: by 2002:a17:906:4e4b:: with SMTP id g11mr8901551ejw.3.1613058549055; Thu, 11 Feb 2021 07:49:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613058549; cv=none; d=google.com; s=arc-20160816; b=TmEDgz/ndShqRtJes2KnyZ/yZIi8qUuEX8INrPSls6W0RbbbNYzVZBGqzQhWexnJzu ZUbFpJgK363fpiXtMbT6XDaIHC3+836dCsTPjsKlwwIAQ8q8LEZHRreH9oMxVHbqDwoM 3F6DAFMpn8Oy5C8yZGmntDOx533g5WsFCfbn00HSuTcsQUQrnR4kRnUWMtqok1UjEwdU qxdbNKViI0AWbXNLS5HMBO30BgtBtRfyNmhPmp4oJ58GgjwkzOR1xKV8k2d1xE66R3Zy xnVr97fRl7MhRApmsiwTzTeDOKmIXWjlK0Ek0WvzjnbehpZiKxvSdJJXwQGbqBUSvwCr VCHQ== 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=ZL2MIAB2ue4YfEtlbheLQtQNjg8B47EuddRfrjh+KzRj25pUHDRDDJguDcuAkFQrvk UIzxoXCVs396OAPNzSe23v4Ns8rpNBrpw8axJRxZOtjVVlUonKKZnapNy9pqDOCX2byh OzHM+IR0tDhAka8wDTsxb8U0oNHjFyBMEE9hZ8pF0rVz6aHn98u4lJzQkm858LdVyOBl cwIq3GrMU6CjA03mF4mb9/aUY0dSznHXpkudGOqGcTyneiB5L+Q4tILA5ea3ap0P1bqj LmStiFhAy5kQO695qN6WcrRh55oGQU20aScUyugFvQNXK+2L4sbVbTlqy0At1Fsdx1Dv 5klQ== 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 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 w14si4078992ede.222.2021.02.11.07.48.44; Thu, 11 Feb 2021 07:49:09 -0800 (PST) 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=0jCLQtQX; 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 S229969AbhBKPpN (ORCPT + 99 others); Thu, 11 Feb 2021 10:45:13 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(-) 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; } -- 2.27.0