Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp316830pxb; Thu, 21 Jan 2021 07:49:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJzpoDDI3vhv/JEzq4wa+ESgDWN28C1mcddntr1AyNWwz0FE7McPHfJKWv3et13ajTQ4BX+1 X-Received: by 2002:a05:6402:14b:: with SMTP id s11mr11214705edu.214.1611244172941; Thu, 21 Jan 2021 07:49:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611244172; cv=none; d=google.com; s=arc-20160816; b=s3xVw73+VbAD7sr/fetdEuPht/OXvqwdoYZeAmNE9OWUcVRy/BOKdYa/K9afNL+ebB G/Pg9srlcBAXSWDZhm7KnocbSwe0t7X7KworbH3KuakJfjUTgHHZfpE4MZSy4VF8TvJL /OODYH1RJrmyR8JEXRIvNmD6xgCCkAL8nb5KzvdD0V2NFvqqqXRQmAEowcq8Y1BFdhXu b1lADjLWzIBSmuuhT2Qt0nq9aJFx9PESE6wQipJaONnnQ/CVzFY7tgTbw0/t4FEDb8sT MgdHCG1Lsj1GUnQe2TZDyRra6UhUa48ytFzQ21QByItXixdD/NO5H5sWpj516N5B8tdV 5H7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=mcV6TbKFreYa7QKIDfewy432Hq9BHsbgJ9XK1fszJ3Q=; b=Ca6rBbI+kDu9FA3yAk/J47aosSCpbo+mqNjxRRdQMIEY+/GjpdvdPXLdUizGeIHtCf /mCwiBtxTnjK3YIQGVpPA1i96MsORb98BQxUW1Lonrs3R6FtGJBBlAjgi8mdSNLOs1zh 7ZMsyZm6y/GXTC0XFUzAsikWbyAreAjmCKjvyhMlzXXZdWqPPs1GwmYIRD7MBagNE60n +X6yn4aiH5XjDIAea/1BjbFzuGvfC3dn4nPlaZALWxe2VtfXFM4DDkPwlajN+rrklLDf Oy4rxMKJc+V2CHi9TF4Gf+pzv12TNKWLXEcBDtiXipG3trwT+5WqOH3Kdo9/WYHwFqkx gZYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=paOfH3uV; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h18si1937929ejk.90.2021.01.21.07.49.07; Thu, 21 Jan 2021 07:49:32 -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=@kernel.org header.s=k20201202 header.b=paOfH3uV; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387467AbhAUPqq (ORCPT + 99 others); Thu, 21 Jan 2021 10:46:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:49252 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387493AbhAUPpi (ORCPT ); Thu, 21 Jan 2021 10:45:38 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 99D1E2073C; Thu, 21 Jan 2021 15:44:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611243897; bh=+5gRibZkC6bk1wv39tmFyPEKELorKhefP3ySjz4oV7Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=paOfH3uVrTWvohDqTqpIdqpX2ef5Ki07Df+QI0JomD1Z3Sd6xIxEgnbyPqqdPwJB2 +IsZnsl++3nCaiS9+JmHzVWBZsGBW5bywW/LxtPgNH8XH0vAT8Safno/b6NBN6E0Pu 3RFh3H11gbKk1X54ZMfmDYtW3lCbvtMx6HbWMA77zA8OhJmr5gBpJ3BCKLIyKOAPWr V4Vq+3HCiyYzwISCgV4voRb76fhGfBuNWNohRdmxqDyiBsTbs0JTXRWOcBhQEUO//d /rf7ynQ9XyTlPclKhATceuAqbZyWlfXTI5vFuZXKAjXpBDPP5IJTDu6xg/hfsg50R0 er2sWL3RYnLAA== Date: Thu, 21 Jan 2021 15:44:18 +0000 From: Mark Brown To: Marek Szyprowski Cc: David Collins , Liam Girdwood , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, 'Linux Samsung SOC' Subject: Re: [PATCH] regulator: core: avoid regulator_resolve_supply() race condition Message-ID: <20210121154418.GE4588@sirena.org.uk> References: <1610068562-4410-1-git-send-email-collinsd@codeaurora.org> <20210118204958.GS4455@sirena.org.uk> <5f37ae96-c5f9-6619-d88f-21c5e483ff8e@samsung.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="orO6xySwJI16pVnm" Content-Disposition: inline In-Reply-To: <5f37ae96-c5f9-6619-d88f-21c5e483ff8e@samsung.com> X-Cookie: Generic Fortune. User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --orO6xySwJI16pVnm Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jan 21, 2021 at 10:41:59AM +0100, Marek Szyprowski wrote: > On 18.01.2021 21:49, Mark Brown wrote: > > Does this help (completely untested): > Sadly nope. I get same warning: Try this instead: diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 3ae5ccd9277d..31503776dbd7 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; =20 - /* - * 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 =3D regulator_dev_lookup(dev, rdev->supply_name); if (IS_ERR(r)) { ret =3D PTR_ERR(r); @@ -1885,12 +1874,29 @@ static int regulator_resolve_supply(struct regulato= r_dev *rdev) goto out; } =20 + /* + * 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); + return ret; + } + ret =3D set_supply(rdev, r); if (ret < 0) { + regulator_unlock(rdev); put_device(&r->dev); - goto out; + return ret; } =20 + 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 @@ -1901,12 +1907,11 @@ static int regulator_resolve_supply(struct regulato= r_dev *rdev) if (ret < 0) { _regulator_put(rdev->supply); rdev->supply =3D NULL; - goto out; + goto out_rdev_lock; } } =20 out: - regulator_unlock(rdev); return ret; } =20 --orO6xySwJI16pVnm Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEreZoqmdXGLWf4p/qJNaLcl1Uh9AFAmAJoVEACgkQJNaLcl1U h9Cf8wf/XDuOH0gnqkdF8ahweAnC2dYaUGZyEUY+81aGMyOlfAOg28Xm6qM0Epf5 eoNso/xFUG9If6M7wjFbidSEW8R9GuGvw6MqNEtW56Fi/OyvXQ79zvNaOkDoHxcT n+Cc1p5XvjNpwo//JCrJklmdYT3qTB5Lk0hY05p3LTw+Q+soTwcUqYB5NieEhySA v1XdrRZnCdiYw/usO05C2pdERQmt9YDem9oj8yfu2PcKza2zE1g3Eu8EJQcfQe9I /3XeE2sLvLcjusTcH9DaiUOeOCFL4YWgnK5mB46dAuIE/fPqv48fUFMuyZ52PlN9 VQTkUxDM2/BrCf1GRByt4G5hRIhkvQ== =Jbpl -----END PGP SIGNATURE----- --orO6xySwJI16pVnm--