Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751654AbbEYRqF (ORCPT ); Mon, 25 May 2015 13:46:05 -0400 Received: from mezzanine.sirena.org.uk ([106.187.55.193]:55781 "EHLO mezzanine.sirena.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750994AbbEYRp7 (ORCPT ); Mon, 25 May 2015 13:45:59 -0400 Date: Mon, 25 May 2015 18:45:28 +0100 From: Mark Brown To: Tomeu Vizoso Cc: linux-arm-kernel@lists.infradead.org, =?iso-8859-1?Q?St=E9phane?= Marchesin , Thierry Reding , Dmitry Torokhov , Alexander Holler , Grant Likely , Rob Herring , Mark Rutland , Liam Girdwood , linux-kernel@vger.kernel.org Message-ID: <20150525174528.GG21577@sirena.org.uk> References: <1432565608-26036-1-git-send-email-tomeu.vizoso@collabora.com> <1432565608-26036-2-git-send-email-tomeu.vizoso@collabora.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="uK5R2a4OYMA55GL9" Content-Disposition: inline In-Reply-To: <1432565608-26036-2-git-send-email-tomeu.vizoso@collabora.com> X-Cookie: Positively no smoking. User-Agent: Mutt/1.5.23 (2014-03-12) X-SA-Exim-Connect-IP: 94.175.94.161 X-SA-Exim-Mail-From: broonie@sirena.org.uk Subject: Re: [PATCH 01/21] regulator: core: Reduce critical area in _regulator_get X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) X-SA-Exim-Scanned: Yes (on mezzanine.sirena.org.uk) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1777 Lines: 49 --uK5R2a4OYMA55GL9 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, May 25, 2015 at 04:53:05PM +0200, Tomeu Vizoso wrote: > ...by moving the locking to regulator_dev_lookup. This breaks the locking. > + mutex_lock(®ulator_list_mutex); > list_for_each_entry(r, ®ulator_list, list) > - if (strcmp(rdev_get_name(r), supply) == 0) > + if (strcmp(rdev_get_name(r), supply) == 0) { > + mutex_unlock(®ulator_list_mutex); > return r; > + } > + mutex_unlock(®ulator_list_mutex); This means that we hold the lock while we walk the list but then return a pointer to a regulator device that we don't have a reference to. This then means that something else can unregister the regulator we're holding a pointer to which means that it is unsafe to use that pointer. We need to ensure that any objects we look up via the list remain valid while we're working with them. --uK5R2a4OYMA55GL9 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJVY1+3AAoJECTWi3JdVIfQdKcH/jcb032kr9Ia/6/EPtPwPxM8 9TtiUVuH3SteKilq8nENSvt8hsnLNR4Xk4Q+whgKbJbvjp+cbpXcXl349fvMwnRU 2IUmQTZkEWOIjJDsX4XjvFklINwSfEyxsld1aqE32FTCigFDR0G8Np3IeO2/xLqt hGUsjwHHqkJsMNNgkvrN7jNwN2DEJ8rGDieCXh4JMJRiBim94wOr8l8XAaGcOm7v MvRyycoDRn+X3bLHFUxV/sSPCOoyacweTR9kGaAbhomDgMX8u5+jQddWXmVBmzwI ohnYMlAMmShdbdnEG2x/1vQ1fP3CTRsxIXAgwuu4AIDK3ymok4rljTBrontriok= =z02p -----END PGP SIGNATURE----- --uK5R2a4OYMA55GL9-- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/