From patchwork Thu Feb 11 15:02:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 381016 Delivered-To: patch@linaro.org Received: by 2002:a02:b18a:0:0:0:0:0 with SMTP id t10csp2169672jah; Thu, 11 Feb 2021 07:23:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJwIfkT2S1eGGUwzSy5qdS+La7/d5QG7CK9eq7IJRouXZ7vB4N770ZUN2SLHA3HjAehEv4x5 X-Received: by 2002:a17:906:2299:: with SMTP id p25mr9063191eja.279.1613057026852; Thu, 11 Feb 2021 07:23:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613057026; cv=none; d=google.com; s=arc-20160816; b=jgN45LMHb5BK2Cp+j+qhHJkH0VnSM0AMm+V+SNMO2GLAMS1g55uCOIdZigBAlBS/B+ D74MmgyoAs2RbeJf0RtLnk8DmQePxbgCqnc9YARUUrEXLy5s4cdFVyK+pAsG7TVWRpgW kfAsKRgh+MAk7SAEBCU15YyPp7Z3PpD/zo2+fbz0/s535y+DdBJlo3FWPV582Pgl8ALb 0ot0Mbfg4Pox0SF24GME0uMOxODH62fFPE7c4E35KANKWIWKQF1w4GwdqSYYOsekSCOU MhyEA+35v545bW/gOorHS1WVFRIVWq4lUf9MQ2/v3w5d6sBFhrfrNO6JgxlNe2Kk5e4+ Zmvg== 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=lj2wJstLJy4RLyjS/SQLj0r158Frh1NCUf96IqMfEqg=; b=l6SNeV4Gb4O2Vo6R31gEXr7ayYAKpDLK2Y8J05vG22w5TDYq4rpaweXBpPAXNO2M3y ftBsnxc2ptWrpzOfyIfAbPTNWVGhZhImRZC4ZCoa8Ffco4DbT/3ReZt03YJX4PEbJqi7 nyuQlcudkOzbTmO/L/V6HKOULPZjxW6NPEfgDC+if1Y2eCo0WVi8us8GfP1qDuTPLbGC bvUro71JqmXypYjnC8pxy2+hmp5V9gvc3Q1VoAel3La6PfPvAs09xzHv8kG9AENaRHMs pDgFAkV202Sd19JsybJjL2lCbEW21GRB36vv2k0YCMXda9iL9Yo2A1+xO4nYG1xrgrSi 3W/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tThUqH4+; 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 u24si4086160edq.562.2021.02.11.07.23.46; Thu, 11 Feb 2021 07:23:46 -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=tThUqH4+; 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 S230187AbhBKPWR (ORCPT + 13 others); Thu, 11 Feb 2021 10:22:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:52618 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230046AbhBKPSV (ORCPT ); Thu, 11 Feb 2021 10:18:21 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id BAA5764F11; Thu, 11 Feb 2021 15:05:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613055956; bh=pa6Hgg3xEuFgkEo/ivc/91UtrOpegC71GIRRjIY8Efk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tThUqH4+n/lk2ysnSx/bd4ROyQVTFBRW2+msSKhTYK0pZAYW4Yk5uWhDHr9KFmlK1 S5D+Rxuhrf9wIEy9hrJk6lwI70bPG5QWXKTDM3+wV3QO2XHPd9p4Gp1/0rAYi4kVnE OF3xXxHU0dtbcfIklDvqcY5oK2GyEp8d+960fLqI= 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.4 19/24] regulator: Fix lockdep warning resolving supplies Date: Thu, 11 Feb 2021 16:02:42 +0100 Message-Id: <20210211150149.362433699@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210211150148.516371325@linuxfoundation.org> References: <20210211150148.516371325@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 5e0490e18b46a..5b9d570df85cc 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1782,17 +1782,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); @@ -1844,12 +1833,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 @@ -1865,7 +1871,6 @@ static int regulator_resolve_supply(struct regulator_dev *rdev) } out: - regulator_unlock(rdev); return ret; }